fltk-rs
Rust bindings for the FLTK Graphical User Interface library.
The FLTK crate is a crossplatform lightweight gui library which can be statically linked to produce small ( < 1mb for a hello world application after stripping), self-contained (no dependencies) and fast gui applications.
Usage
Just add the following to your project's Cargo.toml file:
[]
= "^0.2.5"
An example hello world application:
use ;
Another example showing the basic callback functionality:
use ;
Please check the examples directory for more examples. You will notice that all widgets are instantiated with a new() method, taking the x and y coordinates, as well as the width and height of the widget. Most widgets, except the TextDisplay and TextEditor, also take a label which can be left blank if needed. Another way to initialize a widget is using the builder pattern: (The following buttons are equivalent)
let but1 = new;
let but2 = default
.with_pos
.with_size
.with_label;
An example of a counter showing use of the builder pattern:
Events
Events can be handled using the set_callback method (as above) or free function, it will handle the default trigger of each widget(like clicks for buttons). For custom event handling, the set_custom_handler() method can be used:
some_widget.set_custom_handler;
Theming
FLTK offers 4 application themes (called schemes):
- Base
- Gtk
- Gleam
- Plastic
These can be set using the App::set_scheme() function. Themes of individual widgets can be optionally modified using the provided methods in the WidgetTrait, such as set_color(), set_label_font(), set_frame_type() etc:
some_button.set_color; // You can use one of the provided colors in the fltk enums
some_button.set_color; // Or you can specify a color by rgb or hex/u32 value
some_button.set_color;
some_button.set_frame;
some_button.set_font;
Dependencies
CMake and a C++ compiler need to be installed and in your PATH for a crossplatform build.
- Windows: None.
- MacOs: None.
- Linux: X11 development headers need to be installed for development. For Debian-based distribution, that means running:
$ sudo apt-get install libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev
Building
To build, just run:
$ git clone https://github.com/MoAlyousef/fltk-rs
$ cd fltk-rs
$ cargo build
Examples
To run the examples:
$ cargo run --example editor
$ cargo run --example calculator
$ cargo run --example gallery
$ cargo run --example button
$ cargo run --example terminal
$ cargo run --example counter
$ cargo run --example hello
$ cargo run --example hello_button
$ cargo run --example paint
Setting the scheme to Gtk.
Check the full code for the custom theming.
Setting the scheme to Gtk
Currently implemented widgets
Most common widgets are implemented:
- Images (BMP, JPEG, GIF, PNG, SVG)
- Button
- RadioButton
- ToggleButton
- RoundButton
- CheckButton
- LightButton
- RepeatButton
- Native FileDialog
- HelpDialog
- Frame (Fl_Box)
- Window
- DoubleWindow
- MenuWindow
- Group
- Pack
- Tabs
- Scroll
- Tile
- TextDisplay
- TextEditor
- SimpleTerminal
- Input
- IntInput
- FloatInput
- MultilineInput
- SecretInput
- FileInput
- Output
- MultilineOutput
- MenuBar
- MenuItem
- Choice (dropdown list)
- Slider
- NiceSlider
- ValueSlider
- Dial
- LineDial
- Counter
- Scrollbar
- Roller
- Adjuster
- ValueInput
- Browser
- SelectBrowser
- HoldBrowser
- MultiBrowser
- FileBrowser
- Spinner
- Clock
- Chart
- Progress (progress bar)
- Wizard
- ColorChooser
- Drawing primitives
Todo
- Complete widget set
- Better documentation
- Better testing
Contributions
Contributions are very welcome!