Skip to main content

Crate rosin

Crate rosin 

Source
Expand description

Rosin is a GUI library.

  • The css module documentation lists which CSS features are supported.
  • The layout module documentation explains how to use the layout system.
  • The localization module documentation explains how to use the localization features.
  • The reactive module documentation explains how to use reactive variables.
  • The prelude module exports all of the relevant types for building an application with Rosin.
  • The widgets module contains reusable widgets.

§The Basics

At a high level, starting an application simply requires constructing an AppLauncher and calling run. In order to construct an AppLauncher, you provide a WindowDesc that describes the properties of the first window, as well as optional configuration parameters.

In Rosin, a UI is described declaratively as a pure function of state. So, to create a WindowDesc you provide a function that will be called to construct the UI tree for that window using a simple builder-style API.

The Var type is used to track changes to application state, automatically updating the screen when needed. Anything visible and dynamic should be stored in a Var.

In order to provide a stable identity for nodes between rebuilds, the id macro can be used to generate a unique ID based on the call location.

The EventCtx struct is the primary interface for reacting to user input.

The WindowHandle struct is the primary interface for interacting with the platform.

Example:

use rosin::{prelude::*, widgets::*};

// All application state is stored in a single type
struct State {
    style: Stylesheet,
    count: Var<i32>,
}

impl Default for State {
    fn default() -> Self {
        Self {
            style: stylesheet!("examples/styles/counter.css"),
            count: Var::new(0),
        }
    }
}

fn main_view(state: &State, ui: &mut Ui<State, WindowHandle>) {
    // create the root node
    ui.node()
        // assign a stylesheet
        .style_sheet(&state.style)
        // add a CSS class
        .classes("root")
        // add children
        .children(|ui| {
            // build a label widget with an additional CSS class
            label(ui, id!(), *state.count).classes("number");
            // build a button widget that increases the count when activated
            button(ui, id!(), "Count", |s, _| {
                *s.count.write() += 1;
            });
        });
}

fn main() {
    // init the logger so errors can be displayed
    env_logger::init();

    // describe a simple window
    let window = WindowDesc::new(callback!(main_view))
        .title("Counter Example")
        .size(400, 300)
        .min_size(250, 150);

    // launch the app with an empty translation map
    AppLauncher::new(window)
        .run(State::default(), TranslationMap::default())
        .expect("Failed to launch");
}

Re-exports§

pub use rosin_core::accesskit;
pub use rosin_core::keyboard_types;
pub use rosin_core::kurbo;
pub use rosin_core::log;
pub use rosin_core::parking_lot;
pub use rosin_core::parley;
pub use rosin_core::peniko;
pub use rosin_core::unic_langid;
pub use rosin_core::vello;
pub use rosin_core::wgpu;

Modules§

app
Types for configuring and launching an application instance.
callbacks
Handles for functions that Rosin calls to display the UI.
css
Types related to styling the UI tree.
data
Types for UI parameters and text.
desc
Types related to the behavior of an application window.
dialog
Types for configuring the behavior of a file dialog.
events
Types related to event handling and dispatch.
gpu
Types for configuring and interacting with wgpu.
handle
Types related to interacting with the platform window handle.
ime
Types for interacting with the platform’s text input APIs.
layout
Layout Guide
localization
Localization primitives built on top of Project Fluent.
menu
Platform agnostic native menu descriptions.
nodeid
A stable and unique node identifier.
pointer
Pointer input types used by the event system.
prelude
The public API
reactive
Provides values that allow Rosin to track data dependencies automatically.
text
Exposes functions to access global shared parley contexts.
tree
Exposes the builder used to construct a UI tree.
widgets
Reusable widgets.

Macros§

callback
A macro that takes a function item and makes it useable as either a ViewFn or a WgpuFn.
id
The preferred method for creating a NodeId.
stylesheet
Loads a CSS Stylesheet from a path relative to the crate root.
ui_format
Constructs a UIString with a custom format string.