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
This commit is contained in:
parent
b76ae1f7bc
commit
23da739650
|
@ -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 = "../.." }
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue