From 23da739650bca0d195fdf622d81426b2c2f9f657 Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Sat, 29 May 2021 03:27:33 -0700 Subject: [PATCH] Update fltk (#169) - Fixes #163 - Reimplements window resize - Still has problems on macOS; Resizing with the drag handle blocks the main loop. See: - https://github.com/glfw/glfw/issues/1251 - https://github.com/rust-windowing/winit/issues/219 --- examples/minimal-fltk/Cargo.toml | 2 +- examples/minimal-fltk/src/main.rs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/minimal-fltk/Cargo.toml b/examples/minimal-fltk/Cargo.toml index 4897ae4..b0d60d9 100644 --- a/examples/minimal-fltk/Cargo.toml +++ b/examples/minimal-fltk/Cargo.toml @@ -10,7 +10,7 @@ optimize = ["log/release_max_level_warn"] default = ["optimize"] [dependencies] -fltk = { version = "1.0", features = ["no-images", "no-pango"] } +fltk = { version = "1.0.14", features = ["no-images", "no-pango"] } env_logger = "0.8" log = "0.4" pixels = { path = "../.." } diff --git a/examples/minimal-fltk/src/main.rs b/examples/minimal-fltk/src/main.rs index 783bc7b..31f1859 100644 --- a/examples/minimal-fltk/src/main.rs +++ b/examples/minimal-fltk/src/main.rs @@ -2,7 +2,7 @@ #![forbid(unsafe_code)] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] -use fltk::{app, prelude::*, window::Window}; +use fltk::{app, enums::Event, prelude::*, window::Window}; use log::error; use pixels::{Error, Pixels, SurfaceTexture}; use std::{thread, time::Duration}; @@ -26,19 +26,30 @@ fn main() -> Result<(), Error> { let mut win = Window::default() .with_size(WIDTH as i32, HEIGHT as i32) .with_label("Hello Pixels"); + win.make_resizable(true); win.end(); win.show(); let mut pixels = { - let surface_texture = SurfaceTexture::new(WIDTH, HEIGHT, &win); + let pixel_width = win.pixel_w() as u32; + let pixel_height = win.pixel_h() as u32; + let surface_texture = SurfaceTexture::new(pixel_width, pixel_height, &win); Pixels::new(WIDTH, HEIGHT, surface_texture)? }; let mut world = World::new(); while app.wait() { + // Handle window events + if app::event() == Event::Resize { + let pixel_width = win.pixel_w() as u32; + let pixel_height = win.pixel_h() as u32; + pixels.resize_surface(pixel_width, pixel_height); + } + // Update internal state world.update(); + // Draw the current frame world.draw(pixels.get_frame()); if pixels @@ -49,6 +60,7 @@ fn main() -> Result<(), Error> { app.quit(); } win.redraw(); + // Calls to redraw in the event loop require an explicit sleep thread::sleep(Duration::from_millis(SLEEP)); }