Crate ambient_ui

source ·
Expand description

A UI library for Ambient. Built on top of ambient_element.

Ambient’s UI system is heavily inspired by React (with hooks), and follows many of the same patterns. Take a look at the React documentation to learn how hooks work in general.

Getting started

Here’s a minimal, complete example of a counter app:

use ambient_api::prelude::*;

#[element_component]
fn App(hooks: &mut Hooks) -> Element {
    let (count, set_count) = use_state(hooks,0);
    FlowColumn::el([
        Text::el(format!("We've counted to {count} now")),
        Button::new("Increase", move |_| set_count(count + 1)).el(),
    ])
}

#[main]
pub fn main() {
    App.el().spawn_interactive();
}

See all UI examples here.

Modules

  • Implements a button UI element, as well as variants thereof.
  • Defines the ClickArea element.
  • Defines the default theme for the UI.
  • Implements a dropdown element.
  • Provides an Editor trait for values that can be edited in the UI, and implementations for common types.
  • Implements all of the Elements used for layouting.
  • A prelude for users of the crate. Imports all the most commonly used types and functions.
  • Defines several UI prompts, such as Alert, Prompt, and EditorPrompt.
  • Defines several kinds of window-sized screens.
  • Defines a scroll area.
  • Defines elements that can be used to select an item from a list.
  • Implements basic tabs.
  • Defines a text element.
  • Defines a throbber.
  • Implements a window with a title bar and a child element. Can be moved around.

Structs

  • Show an image loaded from a url
  • A simple UI line. Use components like line_from, line_to, line_width, background_color, border_color, border_radius and border_thickness to control its appearance.
  • A simple UI rect. Use components like width, height, background_color, border_color, border_radius and border_thickness to control its appearance.
  • A base element for all UI elements. It contains all the components needed for a UI element to work.
  • This only exists so that we can implement From<String> for Text, and then use it in for instance Button.

Traits

  • A trait that provides helper methods for UI elements.

Functions

  • Update the current focus to new_focus (if it’s different from the current focus)
  • A hook that returns the current focus state for this element and a callback to set the focus state.
  • A hook that returns the current focus state for this element, given a specific instance_id, and a callback to set the focus state.
  • Helper wrapper around use_runtime_message that listens to WindowKeyboardInput messages and parses them for you.
  • A hook that returns the current window logical resolution (i.e. taking DPI scaling into account)
  • A hook that returns the current window physical resolution (i.e. not taking DPI scaling into account)
  • Converts the given element into a rect.

Type Aliases