A small collection of modular UI features made with the fltk-rs library.
Handling state in rust can be tricky. These examples with a simple counter demonstrate different approaches to managing and mutating state in your app.
Use the state crate to mutate and reference a global hashmap of widget values.
Use comp_state to mutate and reference local counter values in a react-like fashion. Requires running with cargo +nightly run
Fuzzy search a table of random strings, powered by Sublime Fuzzy.
Select a portion of an image from one frame and draw it in another frame.
A hardware accelerated pan/zoom canvas using Speedy2d as the render engine.
Simple demonstration of using app::belowmouse()
to differentiate between nested widgets with Dnd Events
Demonstrates creating a group that has a solid background color over which child widgets are drawn.
Simple app demonstrating demonstrating handling channeled events (which have the advantage of carrying data) as well as custom events, all the while keeping fn main() clean.
using app::handle_main
can result in more ergonomic code, allowing any widget to handle the event, keeping main
more organized. However, custom event values are hard coded. enum_ordanlize lets us define our custom event values relative to the number of total enum values. Thus we can insert or remove custom events without worrying about disjoint values.
#[derive(Debug, PartialEq, Eq, Ordinalize)]
#[repr(i32)]
enum CustomEvents{
AddOne = 41,
AddTwo,
AddThree,
}
//..
win.handle(move |_, ev|
if ev.bits() == CustomEvents::AddOne.ordinal(){
*counter.borrow_mut() += 1;
true
} else if ev.bits() == CustomEvents::AddTwo.ordinal(){
*counter.borrow_mut() += 2;
true
} else if ev.bits() == CustomEvents::AddThree.ordinal(){
*counter.borrow_mut() += 3;
true
} else {
false
});
- For detailed windows installation seeksthe fltk-rs wiki
- Make sure your project directory path isn't too long, see https://stackoverflow.com/questions/49603759/msb6003-the-specified-task-executable-cl-exe-could-not-be-run
children()
forScroll
counts the vertical and horizontal sliders, so subtract 3 from that number to get the actual count