Skip to content

Commit

Permalink
Update fltk (#169)
Browse files Browse the repository at this point in the history
- Fixes #163
- Reimplements window resize
  - Still has problems on macOS; Resizing with the drag handle blocks the main loop. See:
    - glfw/glfw#1251
    - rust-windowing/winit#219
  • Loading branch information
parasyte committed May 29, 2021
1 parent b76ae1f commit 23da739
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/minimal-fltk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../.." }
16 changes: 14 additions & 2 deletions examples/minimal-fltk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand All @@ -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));
}
Expand Down

0 comments on commit 23da739

Please sign in to comment.