Skip to content

Instantly share code, notes, and snippets.

@MoAlyousef
Created April 22, 2021 17:06
Show Gist options
  • Save MoAlyousef/e5731fc662c1f6f25f53923360b406c2 to your computer and use it in GitHub Desktop.
Save MoAlyousef/e5731fc662c1f6f25f53923360b406c2 to your computer and use it in GitHub Desktop.
Override FLTK's resizing defaults
#![allow(unused_variables)]
use fltk::{
app::App,
button::Button,
enums::Event,
group::Group,
prelude::{GroupExt, WidgetBase, WidgetExt, WindowExt},
window::Window,
};
fn main() {
let app = App::default();
let mut win = Window::default().with_size(400, 300);
// but1 is automatically resized by FLTK
let but1 = Button::new(80, 200, 80, 40, "but1");
// We'll override but2's resizing in the win event handler
let mut but2 = Button::new(180, 200, 80, 40, "but2");
// We put but3 in a group to disable its resizing
let mut grp = Group::new(280, 200, 80, 40, "");
let but3 = Button::new(280, 200, 80, 40, "but3");
grp.end();
// This makes but3 unresizable
grp.make_resizable(false);
win.end();
win.make_resizable(true);
win.show();
// This limits the window's size range to a minimun of (400, 300) and max (800, 600)
// To remove the upper limit, pass zeroes: `win.size_range(400, 300, 0, 0);`
win.size_range(400, 300, 800, 600);
win.handle(move |w, ev| match ev {
Event::Resize => {
but2.resize(but2.x(), but2.y(), w.w() / 5 - 20, w.h() / 5 - 20);
true
}
_ => false,
});
app.run().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment