#cross-platform-ui #user-interface #ui #gtk #native-bindings #ui-toolkit

sys ui-sys

Native bindings to the minimalist, cross-platform, widget set libui

3 releases

Uses old Rust 2015

0.1.3 May 30, 2018
0.1.1 Jan 30, 2018
0.1.0 Jan 30, 2018

#848 in GUI

Download history 48/week @ 2024-07-20 45/week @ 2024-07-27 41/week @ 2024-08-03 62/week @ 2024-08-10 35/week @ 2024-08-17 42/week @ 2024-08-24 26/week @ 2024-08-31 20/week @ 2024-09-07 17/week @ 2024-09-14 34/week @ 2024-09-21 71/week @ 2024-09-28 6/week @ 2024-10-05 16/week @ 2024-10-12 15/week @ 2024-10-19 17/week @ 2024-10-26 27/week @ 2024-11-02

75 downloads per month
Used in 3 crates (via iui)

MIT license

1MB
35K SLoC

C 14K SLoC // 0.1% comments C++ 10K SLoC // 0.1% comments Objective-C 9K SLoC // 0.1% comments Rust 1.5K SLoC // 0.0% comments Go 137 SLoC // 0.0% comments Swift 68 SLoC // 0.0% comments GNU Style Assembly 45 SLoC Shell 18 SLoC // 0.1% comments Batch 8 SLoC

Improved User Interface

A cross-platform UI toolkit for Rust based on libui

libui-rs travis build status libui-rs appveyor build status badge actively developed badge

iui: iui crates.io version badge docs.rs for iui ui-sys: ui-sys crates.io version badge docs.rs for ui-sys

iui is a simple, small, easy to distribute GUI library, a Rusty user interface library that binds to platform native APIs. These are work-in-progress bindings to the minimalistic native UI library [libui][libui] via the ui-sys bindings crate.

Add iui to your project with:

iui = "0.3"

Organization

  • iui is the safe Rust wrapper, to be used by most users.
  • ui is the old version of the safe wrapper. Don't use this.
  • ui-sys is the raw unsafe bindings to the libui C code. Requires cmake so it can build libui.
  • libui is included as a submodule.

Based on work by @pcwalton. Licensed MIT.

Example

Three example GUI applications running on Linux

extern crate iui;
use iui::prelude::*;
use iui::controls::{Label, Button, VerticalBox, Group};

fn main() {
    // Initialize the UI library
    let ui = UI::init().expect("Couldn't initialize UI library");
    // Create a window into which controls can be placed
    let mut win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);

    // Create a vertical layout to hold the controls
    let mut vbox = VerticalBox::new(&ui);
    vbox.set_padded(&ui, true);

    let mut group_vbox = VerticalBox::new(&ui);
    let mut group = Group::new(&ui, "Group");

    // Create two buttons to place in the window
    let mut button = Button::new(&ui, "Button");
    button.on_clicked(&ui, {
        let ui = ui.clone();
        move |btn| {
            btn.set_text(&ui, "Clicked!");
        }
    });

    let mut quit_button = Button::new(&ui, "Quit");
    quit_button.on_clicked(&ui, {
        let ui = ui.clone();
        move |_| {
            ui.quit();
        }
    });

    // Create a new label. Note that labels don't auto-wrap!
    let mut label_text = String::new();
    label_text.push_str("There is a ton of text in this label.\n");
    label_text.push_str("Pretty much every unicode character is supported.\n");
    label_text.push_str("πŸŽ‰ η”¨ζˆ·η•Œι’ μ‚¬μš©μž μΈν„°νŽ˜μ΄μŠ€");
    let label = Label::new(&ui, &label_text);

    vbox.append(&ui, label, LayoutStrategy::Stretchy);
    group_vbox.append(&ui, button, LayoutStrategy::Compact);
    group_vbox.append(&ui, quit_button, LayoutStrategy::Compact);
    group.set_child(&ui, group_vbox);
    vbox.append(&ui, group, LayoutStrategy::Compact);

    // Actually put the button in the window
    win.set_child(&ui, vbox);
    // Show the window
    win.show(&ui);
    // Run the application
    ui.main();
}

Building ui-sys

ui-sys includes libui as a sub-module and allows it to be built on-the-fly with the default features fetch and build. Withfetch disabled, it will simply build the existing sources without updating them, and with build disabled it will build nothing, assuming either a system or local (in ./lib/) version of libui is available.

Note that most of the time, building libui on the fly is what you want. It does however require a copy of cmake, essential build tools, et cetera.

Dependencies