• English
  • Run examples

    Try a layout in the browser, or run a complete program with display setup, input and cleanup. The examples below cover both.

    Try layouts in the browser

    Try changing a layout on this page and running it. Examples and supported edits run in your browser and accept input immediately; see the supported syntax. For state connected to controls, start with the switch example.

    Arrange a row

    Make room for contentDistribute remaining space with grow in an action row.
    row.rs
    use rs_lvgl_ui::prelude::*;
    
    fn view(theme: &Theme) -> View<()> {
        let actions = row([
            button("Back").font(theme.body_font).text_color(theme.text),
            label("Step 2 of 3")
                .font(theme.body_font)
                .text_color(theme.text)
                .grow(1),
            button("Continue").style(Style::accent(theme)),
        ])
        .style(Style::surface(theme))
        .width(percent(100))
        .gap(12);
    
        column([
            label("Make room")
                .font(theme.title_font)
                .text_color(theme.text),
            label("The middle label grows into the available space."),
            actions,
        ])
        .style(Style::screen(theme))
        .font(theme.body_font)
        .text_color(theme.text)
        .padding(24)
        .gap(20)
    }
    struct Example;
    
    impl rs_lvgl_ui::App for Example {
        type Action = ();
    
        fn update(&mut self, _: ()) {}
    
        fn view(&self, theme: &rs_lvgl_ui::Theme) -> rs_lvgl_ui::View<()> {
            view(theme)
        }
    }
    
    fn app() -> impl rs_lvgl_ui::App {
        Example
    }
    
    Make room for content

    Loading the interactive example…

    Try changing the row's spacing or replacing row with column. The child collection still defines the order; the container changes the layout direction.

    Place cells in a grid

    Place views in a gridTracks set sizes; grid_cell sets position and span.
    grid.rs
    use rs_lvgl_ui::prelude::*;
    
    fn view(theme: &Theme) -> View<()> {
        let tiles = grid(
            [GridTrack::Fr(1), GridTrack::Fr(1)],
            [GridTrack::Px(72), GridTrack::Px(72)],
            [
                button("Top left").grid_cell(0, 0, 1, 1),
                button("Top right").grid_cell(1, 0, 1, 1),
                button("Two columns").grid_cell(0, 1, 2, 1),
            ],
        )
        .style(Style::surface(theme))
        .width(percent(100))
        .gap(12);
    
        column([
            label("A place for everything")
                .font(theme.title_font)
                .text_color(theme.text),
            tiles,
        ])
        .style(Style::screen(theme))
        .font(theme.body_font)
        .text_color(theme.text)
        .padding(24)
        .gap(20)
    }
    struct Example;
    
    impl rs_lvgl_ui::App for Example {
        type Action = ();
    
        fn update(&mut self, _: ()) {}
    
        fn view(&self, theme: &rs_lvgl_ui::Theme) -> rs_lvgl_ui::View<()> {
            view(theme)
        }
    }
    
    fn app() -> impl rs_lvgl_ui::App {
        Example
    }
    
    Place views in a grid

    Loading the interactive example…

    Change a child's .grid_cell(...) to move it to another cell. Changing the collection order alone does not override an explicit cell assignment. The Arrange widgets explains composition and stable keys; the playground contains the full preset collection.

    Run a complete application

    The workspace ships its runnable examples in the rs_lvgl_ui package. Ten focused examples each demonstrate one behavior; their source files are in the repository-level examples/ directory, and rs_lvgl_ui/Cargo.toml attaches each file to an example target with explicit required features. The larger galleries live in rs_lvgl_ui/examples/.

    Prepare the desktop environment

    Install Rust, a C compiler and libclang as described in Getting started, then install SDL2 for the window, mouse and keyboard:

    brew install sdl2 pkg-config

    If the linker cannot find SDL2, set its library directory:

    export LIBRARY_PATH="$(pkg-config --variable=libdir sdl2)"
    sudo apt-get update
    sudo apt-get install g++ pkg-config libsdl2-dev

    The component studio includes Lottie, which also needs a C++14 compiler. Xcode Command Line Tools on macOS and g++ above provide it.

    Get and run the examples

    These commands run examples from the repository. To add the library to your own project, use the crates.io installation in Getting started.

    git clone https://github.com/umbrella22/rs_lvgl.git
    cd rs_lvgl
    cargo run -p rs_lvgl_ui --example button_click --features simulator

    A button counter window opens; clicking the button increments the count. Run subsequent commands from the repository root, choosing an example name and its required features:

    cargo run -p rs_lvgl_ui --example <name> --features <features>

    --features adds capabilities to the crate's default set. The table lists the full required-features value declared for each target; the commands below work with defaults enabled. If --no-default-features is passed to test a reduced build, every required feature must be provided explicitly.

    Open the component preview for interactive WebAssembly controls and animations. The desktop and browser editions share the same Rust views.

    The targets below add display setup, an event loop and teardown. Use these when learning state changes and native input.

    Focused examples

    ExampleRequired featuresBehavior
    appsimulator, widget-switchA notifications switch and a save counter backed by application state
    button_clicksimulatorA button sends a message and increments a rendered count
    barsimulator, widget-barA progress bar and label share one value; buttons advance or reset it
    arcsimulator, widget-arcAn interactive dial; dragging or the Increase button changes the output value
    scalesimulator, widget-scale, widget-sliderA numbered scale above a slider; Center sets the shared value to 50
    animationsimulatorA native X animation on a dot, with Pause and Resume messages
    demosimulator, widget-barA watch face with day, step count and progress bar
    sdlsimulatorSDL mouse events drive increment and decrement actions
    sdl_demosimulator, components, widget-slider, widget-switch, widget-barA Panel composes a volume slider, switch, bar and restore action
    rust_timersimulator, rust_timer, widget-barA Rust monotonic clock drives LVGL's tick and an elapsed-time display

    For example:

    cargo run -p rs_lvgl_ui --example sdl_demo --features simulator,components,widget-slider,widget-switch,widget-bar
    cargo run -p rs_lvgl_ui --example rust_timer --features simulator,rust_timer,widget-bar

    Each focused example opens a 640 x 480 SDL window titled rs_lvgl / <name>. The shared frame shows a small repository label, the example title, a one-line description and a surface card containing the interactive content. The theme is light by default. Close the window to exit; the program prints a frame and node count during teardown.

    Three environment variables adjust a run:

    • EXAMPLE_DARK=1 selects the dark theme.
    • EXAMPLE_FRAMES=100 stops after the given number of frames instead of waiting for the window to close.
    • EXAMPLE_CAPTURE_DIR=target/captures writes initial and final PPM snapshots.
    EXAMPLE_DARK=1 EXAMPLE_FRAMES=100 EXAMPLE_CAPTURE_DIR=target/captures cargo run -p rs_lvgl_ui --example app --features simulator,widget-switch

    Shared host

    The ten focused examples share examples/support/mod.rs. Its run function creates the SDL window and mouse, initializes LVGL, mounts the App, and runs the common timer_handler, drain and Ui::tick sequence. Each example keeps its state, component action enum and view in one file. Tests beside each example render the same view on a memory display and dispatch native pointer events, so interaction assertions do not depend on a window server.

    button_click.rs is the smallest complete state/message/view cycle; sdl_demo.rs shows the same host with a composite component.

    Galleries

    These targets cover the wider component and widget surface. The commands below use the aggregating features where one exists.

    TargetRequired featuresWhat it runs
    studioshowcaseThe full 1280 x 860 component studio with eleven categories, themes, modal dialog and toasts
    capabilitiessimulator, components, input-gridnav, widget-canvas, widget-qrcode, widget-barcode, widget-gif, widget-lottie, widget-ime-pinyin, widget-textarea, font-cjk-16Native screen transitions and the optional capability pages
    widgets_demosimulator, widget-arc, widget-chart, widget-checkbox, widget-dropdown, widget-image, widget-keyboard, widget-scale, widget-slider, widget-switch, widget-tabview, widget-textareaA multi-tab widget tour with analytics, shop and keyboard states
    componentssimulator, components, widget-switchPanels, lists, navigation, dialogs and toasts
    gallerysimulator, widget-slider, widget-switchThe general component gallery
    inputsimulator, input-keypadKeypad input and focus behavior in a native window
    settingswidget-slider, widget-switchA headless memory-display settings screen that prints reconcile counters
    cargo run -p rs_lvgl_ui --example studio --features showcase
    cargo run -p rs_lvgl_ui --example capabilities --features capability-gallery
    cargo run -p rs_lvgl_ui --example widgets_demo --features simulator
    cargo run -p rs_lvgl_ui --example components --features simulator
    cargo run -p rs_lvgl_ui --example gallery --features simulator
    cargo run -p rs_lvgl_ui --example input --features simulator,input-keypad
    cargo run -p rs_lvgl_ui --example settings

    studio opens a window titled rs_lvgl / Component Studio. Select a category in the sidebar, drag a slider or toggle a switch. Tab and Shift-Tab move focus; Enter activates a control. Reset restores the example state while retaining the category and theme. Exit studio closes the window. showcase includes the widgets, fonts and media extensions used by the studio.

    capability-gallery is the aggregate feature set for capabilities: it contains every feature that target requires. settings does not open a window; it registers a 320 x 240 memory display, mounts the screen, drains four messages and prints created, deleted and moved node counts before unmounting.

    The component studio overview

    The component studio guide documents its eleven categories and native checks. The focused example sources and their shared host are listed in examples/README.md.

    Run and capture the studio automatically

    To visit every category in a bounded run:

    STUDIO_FRAMES=460 STUDIO_AUTORUN=1 cargo run -p rs_lvgl_ui --example studio --features showcase

    Set STUDIO_CAPTURE_DIR=target/studio-captures to write PPM snapshots. The studio uses synthetic data and local resources; it needs no network service or application filesystem.

    Check the native runs

    python3 scripts/check-ui-examples.py --artifacts target/ui-audit

    On headless Linux, run it under a virtual display:

    xvfb-run -a python3 scripts/check-ui-examples.py --artifacts target/ui-audit

    The runner builds the examples with showcase,font-cjk-14,rust_timer, runs their native tests serially, and executes twenty bounded native scenarios across the focused examples and galleries. Logs and snapshots are written under target/ui-audit.

    These checks exercise actual views on memory displays and separate SDL smoke runs. SDL smoke proves that a native window can open and close; it does not emulate operating-system input or certify a physical board.