All Projects → MoAlyousef → Fltk Rs

MoAlyousef / Fltk Rs

Licence: mit
Rust bindings for the FLTK GUI library.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Fltk Rs

Iced
A cross-platform GUI library for Rust, inspired by Elm
Stars: ✭ 12,176 (+4952.28%)
Mutual labels:  graphics, gui, widgets
Libs Gui
The GNUstep gui library is a library of graphical user interface classes written completely in the Objective-C language; the classes are based upon Apple's Cocoa framework (which came from the OpenStep specification). *** Larger patches require copyright assignment to FSF. please file bugs here. ***
Stars: ✭ 148 (-38.59%)
Mutual labels:  graphics, gui, widgets
Nuklear Rust
The bindings to the Nuklear 2D immediate GUI library.
Stars: ✭ 308 (+27.8%)
Mutual labels:  graphics, bindings, gui
Fruity
Rusty bindings for Apple libraries
Stars: ✭ 72 (-70.12%)
Mutual labels:  graphics, bindings
Gi
Native Go (golang) Graphical Interface system (2D and 3D), built on GoKi tree framework
Stars: ✭ 864 (+258.51%)
Mutual labels:  graphics, gui
Bogue
GUI library for ocaml based on SDL2
Stars: ✭ 48 (-80.08%)
Mutual labels:  gui, widgets
Horus ui
HorusUI Immediate Mode Graphical User Interface
Stars: ✭ 106 (-56.02%)
Mutual labels:  gui, widgets
Nuklear Nim
Nim bindings for https://github.com/vurtun/nuklear/
Stars: ✭ 109 (-54.77%)
Mutual labels:  bindings, gui
Ocamlverse.github.io
Documentation of everything relevant in the OCaml world
Stars: ✭ 117 (-51.45%)
Mutual labels:  graphics, gui
Awesome Python Applications
💿 Free software that works great, and also happens to be open-source Python.
Stars: ✭ 13,275 (+5408.3%)
Mutual labels:  graphics, gui
Gtk Fortran
A GTK / Fortran binding
Stars: ✭ 171 (-29.05%)
Mutual labels:  graphics, gui
Vim Quickui
The missing UI extensions for Vim 8.2 (and NeoVim 0.4) !! 😎
Stars: ✭ 714 (+196.27%)
Mutual labels:  gui, widgets
Clui
Command Line User Interface (Console UI inspired by TurboVision)
Stars: ✭ 561 (+132.78%)
Mutual labels:  gui, widgets
Ttkwidgets
A collection of widgets for Tkinter's ttk extensions by various authors
Stars: ✭ 57 (-76.35%)
Mutual labels:  gui, widgets
Dearpygui
Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
Stars: ✭ 6,631 (+2651.45%)
Mutual labels:  graphics, gui
Core2d
A multi-platform data driven 2D diagram editor.
Stars: ✭ 475 (+97.1%)
Mutual labels:  graphics, gui
Orbtk
The Rust UI-Toolkit.
Stars: ✭ 3,460 (+1335.68%)
Mutual labels:  gui, widgets
Qml Creative Controls
QML controls for creative applications and creative coding
Stars: ✭ 199 (-17.43%)
Mutual labels:  gui, widgets
Litegui.js
Javascript Library to create webapps with a desktop look-alike interface. All the widgets are created from Javascript instead of using HTML.
Stars: ✭ 131 (-45.64%)
Mutual labels:  gui, widgets
Qt5.cr
Qt5 bindings for Crystal, based on Bindgen
Stars: ✭ 182 (-24.48%)
Mutual labels:  bindings, gui

fltk-rs

Documentation Crates.io License Build

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, self-contained and fast gui applications.

Tutorials:

  • Video
  • Written
  • Erco's FLTK cheat page, which is an excellent FLTK C++ reference.

Why choose FLTK?

  • Lightweight. Small binary, around 1mb after stripping. Small memory footprint.
  • Speed. Fast to install, fast to build, fast at startup and fast at runtime.
  • Single executable. No DLLs to deploy.
  • Supports old architectures.
  • FLTK's permissive license which allows static linking for closed-source applications.
  • Themability (4 supported themes: Base, GTK, Plastic and Gleam).
  • Provides around 80 customizable widgets.
  • Has inbuilt image support.

Here is a list of software using FLTK. For software using fltk-rs, check here.

  • Link to the official FLTK repository.
  • Link to the official documentation.

Usage

Just add the following to your project's Cargo.toml file:

[dependencies]
fltk = "^0.15"

To use the latest changes in the repo:

[dependencies]
fltk = { version = "^0.15", git = "https://github.com/MoAlyousef/fltk-rs" }

The library is automatically built and statically linked to your binary.

For faster builds you can enable ninja builds for the C++ source using the "use-ninja" feature.

An example hello world application:

use fltk::{app, window::*};

fn main() {
    let app = app::App::default();
    let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
    wind.end();
    wind.show();
    app.run().unwrap();
}

Another example showing the basic callback functionality:

use fltk::{app, button::*, frame::*, window::*};

fn main() {
    let app = app::App::default();
    let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
    let mut frame = Frame::new(0, 0, 400, 200, "");
    let mut but = Button::new(160, 210, 80, 40, "Click me!");
    wind.end();
    wind.show();
    but.set_callback(move || frame.set_label("Hello World!"));
    app.run().unwrap();
}

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, the width and height of the widget, as well as 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 = Button::new(10, 10, 80, 40, "Button 1");

let but2 = Button::default()
    .with_pos(10, 10)
    .with_size(80, 40)
    .with_label("Button 2");

An example of a counter showing use of the builder pattern:

fn main() {
    let app = app::App::default();
    let mut wind = Window::default()
        .with_size(160, 200)
        .center_screen()
        .with_label("Counter");
    let mut frame = Frame::default()
        .with_size(100, 40)
        .center_of(&wind)
        .with_label("0");
    let mut but_inc = Button::default()
        .size_of(&frame)
        .above_of(&frame, 0)
        .with_label("+");
    let mut but_dec = Button::default()
        .size_of(&frame)
        .below_of(&frame, 0)
        .with_label("-");
    wind.make_resizable(true);
    wind.end();
    wind.show();
    /* Event handling */
}

Alternatively, you can use packs to layout your widgets:

    let mut wind = Window::default().with_size(160, 200).with_label("Counter");
    // Vertical is default. You can choose horizontal using pack.set_type(PackType::Horizontal);
    let mut pack = Pack::default().with_size(120, 140).center_of(&wind);
    pack.set_spacing(10);
    let mut but_inc = Button::default().with_size(0, 40).with_label("+");
    let mut frame = Frame::default().with_size(0, 40).with_label("0");
    let mut but_dec = Button::default().with_size(0, 40).with_label("-");
    pack.end();

Events

Event handling must be done after the drawing is done and the main window shown. And must be done in the main thread

Events can be handled using the set_callback method (as above) or the available fltk::app::set_callback() free function, which will handle the default trigger of each widget(like clicks for buttons):

    /* previous hello world code */
    but.set_callback(move || frame.set_label("Hello World!"));
    app.run().unwrap();

Another way is to use message passing:

    /* previous counter code */
    let (s, r) = app::channel::<Message>();

    but_inc.emit(s, Message::Increment);
    but_dec.emit(s, Message::Decrement);
    
    while app.wait() {
        let label: i32 = frame.label().parse().unwrap();
        match r.recv() {
            Some(Message::Increment) => frame.set_label(&(label + 1).to_string()),
            Some(Message::Decrement) => frame.set_label(&(label - 1).to_string()),
            None => (),
        }
    }

For the remainder of the code, check the full example here.

For custom event handling, the handle() method can be used:

    some_widget.handle(move |ev: Event| {
        match ev {
            /* handle ev */
        }
    });

Handled or ignored events using the handle method should return true, unhandled events should return false. More examples are available in the fltk/examples directory.

Theming

FLTK offers 4 application themes (called schemes):

  • Base
  • Gtk
  • Gleam
  • Plastic

These can be set using the App::with_scheme() method.

let app = app::App::default().with_scheme(app::Scheme::Gleam);

Themes of individual widgets can be optionally modified using the provided methods in the WidgetExt trait, such as set_color(), set_label_font(), set_frame() etc:

    some_button.set_color(Color::Light1); // You can use one of the provided colors in the fltk enums
    some_button.set_color(Color::from_rgb(255, 0, 0)); // Or you can specify a color by rgb or hex/u32 value
    some_button.set_color(Color::from_u32(0xffebee));
    some_button.set_frame(FrameType::RoundUpBox);
    some_button.set_font(Font::TimesItalic);

Features

The following are the features offered by the crate:

  • use-ninja: If you have ninja build installed, it builds faster than make or VS
  • system-libpng: Uses the system libpng
  • system-libjpeg: Uses the system libjpeg
  • system-zlib: Uses the system zlib
  • fltk-bundled: Support for bundled versions of cfltk and fltk on selected platforms (requires curl and tar)
  • no-pango: Build without pango support on Linux/BSD.
  • enable-glwindow: Support for drawing using OpenGL functions.

Dependencies

Rust (version > 1.38), CMake (version > 3.0), Git and a C++11 compiler need to be installed and in your PATH for a crossplatform build from source. This crate also offers a bundled form of fltk on selected platforms, this can be enabled using the fltk-bundled feature flag (which requires curl and tar to download and unpack the bundled libraries). If you have ninja-build installed, you can enable it using the "use-ninja" feature. This should accelerate build times significantly.

  • Windows: No dependencies.
  • MacOS: No dependencies.
  • Linux: X11 and OpenGL development headers need to be installed for development. The libraries themselves are available on linux distros with a graphical user interface.

For Debian-based GUI distributions, that means running:

$ sudo apt-get install libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpango1.0-dev libpng-dev libgl1-mesa-dev libglu1-mesa-dev

For RHEL-based GUI distributions, that means running:

$ sudo yum groupinstall "X Software Development" && yum install pango-devel libXinerama-devel libpng-devel

For Arch-based GUI distributions, that means running:

$ sudo pacman -S libx11 libxext libxft libxinerama libxcursor libxrender libxfixes libpng pango cairo libgl mesa --needed

For Alpine linux:

$ apk add pango-dev fontconfig-dev libxinerama-dev libxfixes-dev libxcursor-dev libpng-dev mesa-gl

For NixOS (Linux distribution) this nix-shell environment can be used:

$ nix-shell --packages rustc cmake git gcc xorg.libXext xorg.libXft xorg.libXinerama xorg.libXcursor xorg.libXrender xorg.libXfixes libpng libcerf pango cairo libGL mesa pkg-config
  • Android (experimental): Android Studio, Android Sdk, Android Ndk.

FAQ

please check the FAQ page for frequently asked questions, encountered issues, guides on deployment, and contribution.

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 calculator2
$ cargo run --example terminal
$ cargo run --example counter
$ cargo run --example hello
$ cargo run --example hello_button
$ cargo run --example fb
$ cargo run --example pong
$ cargo run --example custom_widgets
...

alt_test

With custom theming:

alt_test

alt_test

alt_test

Setting the scheme to Gtk:

alt_test

alt_test

Counter

Check the full code for the custom theming.

Setting the scheme to Gtk:

alt_test

alt_test

alt_test

alt_test

alt_test

alt_test

Different frame types which can be used with many different widgets such as Frame, Button widgets, In/Output widgets...etc.

More interesting examples can be found in the fltk-rs-demos repo. Also a nice implementation of the 7guis tasks can be found here.

Currently implemented types:

Image types:

  • SharedImage
  • BmpImage
  • JpegImage
  • GifImage
  • PngImage
  • SvgImage
  • Pixmap
  • RgbImage
  • XpmImage
  • XbmImage
  • PnmImage
  • TiledImage

Widgets:

  • Buttons
    • Button
    • RadioButton
    • ToggleButton
    • RoundButton
    • CheckButton
    • LightButton
    • RepeatButton
    • RadioLightButton
    • RadioRoundButton
  • Dialogs
    • Native FileDialog
    • FileChooser
    • HelpDialog
    • Message dialog
    • Alert dialog
    • Password dialog
    • Choice dialog
    • Input dialog
    • ColorChooser dialog
  • Frame (Fl_Box)
  • Windows
    • Window
    • SingleWindow (single buffered)
    • DoubleWindow (double buffered)
    • MenuWindow
    • OverlayWindow
    • GlWindow (requires the "enable-glwindow" flag)
    • GlutWindow (requires the "enable-glwindow" flag)
  • Groups
    • Group
    • Pack (Horizontal and Vertical)
    • Tabs
    • Scroll
    • Tile
    • Wizard
    • ColorChooser
    • VGrid
    • HGrid
  • Text display widgets
    • TextDisplay
    • TextEditor
    • SimpleTerminal
  • Input widgets
    • Input
    • IntInput
    • FloatInput
    • MultilineInput
    • SecretInput
    • FileInput
  • Output widgets
    • Output
    • MultilineOutput
  • Menu widgets
    • MenuBar
    • MenuItem
    • Choice (dropdown list)
    • SysMenuBar (MacOS menu bar which appears at the top of the screen)
  • Valuator widgets
    • Slider
    • NiceSlider
    • ValueSlider
    • Dial
    • LineDial
    • Counter
    • Scrollbar
    • Roller
    • Adjuster
    • ValueInput
    • ValueOutput
    • FillSlider
    • FillDial
    • HorSlider (Horizontal slider)
    • HorFillSlider
    • HorNiceSlider
    • HorValueSlider
  • Browsing widgets
    • Browser
    • SelectBrowser
    • HoldBrowser
    • MultiBrowser
    • FileBrowser
    • CheckBrowser
  • Miscelaneous widgets
    • Spinner
    • Clock (Round and Square)
    • Chart (several chart types are available)
    • Progress (progress bar)
    • Tooltip
    • InputChoice
    • HelpView
  • Table widgets
    • Table
    • TableRow
  • Trees
    • Tree
    • TreeItem

Drawing primitives

(In the draw module)

Surface types:

  • Printer.
  • ImageSurface.
  • SvgFileSurface.

Tutorials

More videos in the playlist here. Some of the demo projects can be found here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].