Expand description
§fltk-builder
A crate to enable building an FLTK UI in Rust with a builder pattern using fltk-rs.
This includes:
- Builder pattern friendly versions for setter functions, starting with a
with_prefix - A global map to store any widget based on an ID, which can be assigned using the
with_idfunction and retrieved by thefltk_builder::get_widget_by_idfunction
§Usage
Just add the following to your project’s Cargo.toml file:
[dependencies]
fltk = "1"
fltk-builder = "^0.1"If you’re not interested in the ID map functionality you can it off by disabling the default features:
[dependencies]
fltk = "1"
fltk-builder = { version = "^0.1", default-features = false }An example application based on the hello_button example from fltk-rs:
use fltk::{app, button::Button, frame::Frame, prelude::*, window::Window};
use fltk_builder::prelude::*;
fn main() {
let mut app = fltk_builder::FltkBuilder::new(app::App::default()).window(
Window::default()
.with_size(400, 300)
.widget(
Frame::default()
.with_size(200, 100)
.center_of_parent()
.with_id("frame"),
)
.widget(Button::new(160, 210, 80, 40, "Click me").with_callback({
// Retrieve the frame once and not every click for better performance
let mut frame: Frame = fltk_builder::get_widget_by_id("frame").unwrap();
move |_| frame.set_label("Hello World")
})),
);
app.show();
app.app()
.run()
.unwrap();
}You don’t need to use the FLTKBuilder struct if you don’t want to. You can still create the app and window normally and just use the builder pattern functions.
use fltk::{app, button::Button, frame::Frame, prelude::*, window::Window};
use fltk_builder::prelude::*;
fn main() {
let app = app::App::default();
let mut wind = Window::default()
.with_size(400, 300)
.widget(
Frame::default()
.with_size(200, 100)
.center_of_parent()
.with_id("frame"),
)
.widget(Button::new(160, 210, 80, 40, "Click me").with_callback({
// Retrieve the frame once and not every click for better performance
let mut frame: Frame = fltk_builder::get_widget_by_id("frame").unwrap();
move |_| frame.set_label("Hello World")
}));
wind.end();
wind.show();
app.run()
.unwrap();
}Modules§
- extensions
- Holds several extension traits to enable a builder pattern
- prelude
- Reexports of all fltk_builder traits
Structs§
- Fltk
Builder - Starting point for the UI
Enums§
- IdMap
Error - Represents all possible outcomes when using the
get_widget_by_idfunction
Functions§
- get_
widget_ by_ id - Retrieves a widget by its ID