-
-
Save pa-0/0db1333d19807ddb01992848da763926 to your computer and use it in GitHub Desktop.
Override FLTK's resizing defaults
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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