/FLTK-RS-Examples

Collection of small demo applications which emphasize using fltk-rs in combination with other rust crates.

Primary LanguageRustMIT LicenseMIT

FLTK-RS Examples

fltk-rs version license

A small collection of modular UI features made with the fltk-rs library.

Table of Contents


State

State Crate

Handling state in rust can be tricky. These examples with a simple counter demonstrate different approaches to managing and mutating state in your app.

State

Use the state crate to mutate and reference a global hashmap of widget values.

comp_state

Use comp_state to mutate and reference local counter values in a react-like fashion. Requires running with cargo +nightly run

Custom Widget Examples

Fuzzy Search Table

Fuzzy search a table of random strings, powered by Sublime Fuzzy.

Fuzzy Search

Image Selection

Select a portion of an image from one frame and draw it in another frame.

Image Select

Speedy2d Pan/Zoom Canvas

A hardware accelerated pan/zoom canvas using Speedy2d as the render engine.

Speedy2d Canvas

Misc Demos

Nested Drag targets

Simple demonstration of using app::belowmouse() to differentiate between nested widgets with Dnd Events

Nested Drag Targets

Background Fill for Group

Demonstrates creating a group that has a solid background color over which child widgets are drawn.

Background Fill Group

Event Handling

Crossbeam Channels

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.

Crossbeam Channels

Ordinal Custom Events

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
});

Misc