Skip to content

Fix screen resizing after initial launch #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions raven-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub struct Stage<'a> {
vm: Uxn<'a>,
dev: Varvara,

/// Double the UI size
/// Enlarge or shrink the screen size
scale: f32,

/// Current size as set by ROM
size: (u16, u16),

/// Time (in seconds) at which we should draw the next frame
next_frame: f64,

/// Forces a window resize when set
needs_resize: bool,

#[cfg(not(target_arch = "wasm32"))]
console_rx: std::sync::mpsc::Receiver<u8>,

Expand Down Expand Up @@ -68,8 +68,8 @@ impl<'a> Stage<'a> {
dev,

scale,
size,
next_frame: 0.0,
needs_resize: true,

#[cfg(not(target_arch = "wasm32"))]
console_rx: varvara::console_worker(),
Expand All @@ -92,7 +92,7 @@ impl<'a> Stage<'a> {
let data = self.vm.reset(data);
self.dev.reset(data);
self.vm.run(&mut self.dev, 0x100);
self.needs_resize = true;
self.size = (0, 0);
let out = self.dev.output(&self.vm);
out.check()?;
Ok(())
Expand Down Expand Up @@ -228,15 +228,15 @@ impl eframe::App for Stage<'_> {
// Handle audio callback
self.dev.audio(&mut self.vm);

let prev_size = self.dev.screen_size();
let out = self.dev.output(&self.vm);

// Update our GUI based on current state
if out.hide_mouse {
ctx.set_cursor_icon(egui::CursorIcon::None);
}
if std::mem::take(&mut self.needs_resize) || prev_size != out.size {
if self.size != out.size {
info!("resizing window to {:?}", out.size);
self.size = out.size;
let size = egui::Vec2::new(out.size.0 as f32, out.size.1 as f32)
* self.scale;
ctx.send_viewport_cmd(egui::ViewportCommand::InnerSize(size));
Expand Down
1 change: 1 addition & 0 deletions raven-gui/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn run() -> Result<()> {
dev.send_args(&mut vm, &args.args).check()?;

let (width, height) = dev.output(&vm).size;
info!("creating window with size {:?}", (width, height));
let options = eframe::NativeOptions {
window_builder: Some(Box::new(move |v| {
v.with_inner_size(egui::Vec2::new(width as f32, height as f32))
Expand Down
5 changes: 0 additions & 5 deletions raven-varvara/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ impl Varvara {
self.already_warned.fill(false);
}

/// Returns the current screen size
pub fn screen_size(&self) -> (u16, u16) {
self.screen.size()
}

/// Checks whether the SHIFT key is currently down
fn warn_missing(&mut self, t: u8) {
if !self.already_warned[usize::from(t >> 4)] {
Expand Down