Skip to main content

Crate noesis_bevy

Crate noesis_bevy 

Source
Expand description

Bevy plugin for the Noesis GUI SDK.

Noesis parses your XAML and owns the live controls, layout, styles and animations. This crate drives it through the noesis_runtime FFI crate, renders it on Bevy’s wgpu device, and composites each UI onto a camera. Building requires a licensed Noesis Native SDK at NOESIS_SDK_DIR.

§Getting started

Add NoesisPlugin, register XAML in the XamlRegistry (or load .xaml files through the asset server), and put a NoesisView on a camera:

use std::sync::Arc;
use bevy::prelude::*;
use noesis_bevy::{NoesisPlugin, NoesisView, XamlRegistry};

const MENU: &str = r#"<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <TextBlock Text="Hello, Noesis!" Foreground="White"
             HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>"#;

fn setup(mut commands: Commands, mut xaml: ResMut<XamlRegistry>) {
    xaml.insert("menu.xaml", Arc::new(MENU.as_bytes().to_vec()));
    commands.spawn((
        Camera2d,
        NoesisView {
            xaml_uri: "menu.xaml".to_string(),
            size: UVec2::new(1920, 1080),
            ..default()
        },
    ));
}

App::new()
    .add_plugins((DefaultPlugins, NoesisPlugin::default()))
    .add_systems(Startup, setup)
    .run();

§Bridges

Controls are not entities. You reach them through bridge components on the NoesisView entity that name elements by x:Name: NoesisText, NoesisDp (any dependency property), NoesisVm and NoesisViewModel (view models), NoesisCommands, NoesisItems, NoesisVisibility, NoesisLayout and more. Their systems run in NoesisSet::Apply in PostUpdate, and read-backs arrive as messages carrying the view entity.

Most bridge maps are write-through: removing an entry stops further writes but leaves the element at its last value. The order of bridges within NoesisSet::Apply is unspecified.

For entity-shaped UI, UiPanel mounts a XAML fragment bound to an entity’s components, and UiList turns entities into list rows.

§Input

Mouse, keyboard, touch and window focus are forwarded to the primary view automatically (see input). Read NoesisPointerOverUi to keep UI clicks out of the game world.

§Threading

Noesis is thread-affine. All Noesis calls run on the main thread in the main world, in NoesisSet in PostUpdate; the render world only receives each view’s painted texture to composite.

Re-exports§

pub use animation::AnimationSpec;
pub use animation::NoesisAnimation;
pub use animation::NoesisAnimationPlugin;
pub use bake::NoesisLabelBaker;
pub use bake::NoesisLabelBakerPlugin;
pub use binding::NoesisBinding;
pub use binding::NoesisBindingPlugin;
pub use binding::SourceSpec;
pub use brushes::BrushReadback;
pub use brushes::BrushSpec;
pub use brushes::BrushTarget;
pub use brushes::GradientStop;
pub use brushes::NoesisBrushChanged;
pub use brushes::NoesisBrushes;
pub use brushes::NoesisBrushesPlugin;
pub use classes::NoesisClassPlugin;
pub use classes::NoesisClassRegistry;
pub use clip::NoesisClip;
pub use clip::NoesisClipPlugin;
pub use commands::CommandForwarder;
pub use commands::CommandsDef;
pub use commands::NoesisCommandInvoked;
pub use commands::NoesisCommands;
pub use commands::NoesisCommandsPlugin;
pub use commands::SharedCommandQueue;
pub use diagnostics::NoesisDiagnostics;
pub use diagnostics::NoesisDiagnosticsPlugin;
pub use dp::DpKind;
pub use dp::DpValue;
pub use dp::DpWatch;
pub use dp::NoesisDp;
pub use dp::NoesisDpChanged;
pub use dp::NoesisDpPlugin;
pub use events::ClickWatchEntry;
pub use events::KeyDownWatchEntry;
pub use events::NoesisClickWatch;
pub use events::NoesisClicked;
pub use events::NoesisEventsPlugin;
pub use events::NoesisKeyDown;
pub use events::NoesisKeyDownWatch;
pub use events::SharedClickQueue;
pub use events::SharedKeyDownQueue;
pub use events::UiClicked;
pub use events::UiKeyDown;
pub use focus::NoesisFocus;
pub use focus::NoesisFocusPlugin;
pub use focus_input::FocusMove;
pub use focus_input::FocusPredict;
pub use focus_input::KeyBindingSpec;
pub use focus_input::NoesisFocusBindingFired;
pub use focus_input::NoesisFocusControl;
pub use focus_input::NoesisFocusControlPlugin;
pub use focus_input::NoesisFocusPredicted;
pub use font::BevyFontProvider;
pub use font::FontAsset;
pub use font::FontAssetLoader;
pub use font::FontAssetPlugin;
pub use font::FontRegistry;
pub use geometry::NoesisGeometry;
pub use geometry::NoesisGeometryPlugin;
pub use headless::NoesisHeadlessPlugin;
pub use image::BevyTextureProvider;
pub use image::ImageAsset;
pub use image::ImageAssetLoader;
pub use image::ImageAssetPlugin;
pub use image::ImageRegistry;
pub use imaging::ImageBitmap;
pub use imaging::ImageReadback;
pub use imaging::NoesisImageChanged;
pub use imaging::NoesisImaging;
pub use imaging::NoesisImagingPlugin;
pub use inlines::InlineSpec;
pub use inlines::InlinesReadback;
pub use inlines::NoesisInlines;
pub use inlines::NoesisInlinesChanged;
pub use inlines::NoesisInlinesPlugin;
pub use input::NoesisInputEvent;
pub use input::NoesisInputPlugin;
pub use input::NoesisInputQueue;
pub use input::NoesisPointerOverUi;
pub use input::TargetedInput;
pub use integration::NoesisCursorRequested;
pub use integration::NoesisIntegrationPlugin;
pub use integration::NoesisOpenUrl;
pub use integration::NoesisPlayAudio;
pub use items::CollectionViewOp;
pub use items::ItemValue;
pub use items::ItemsBinding;
pub use items::NoesisItems;
pub use items::NoesisItemsCurrent;
pub use items::NoesisItemsPlugin;
pub use items::ObjectRow;
pub use items::ObjectSource;
pub use layout::Margin;
pub use layout::NoesisLayout;
pub use layout::NoesisLayoutPlugin;
pub use list::ListRows;
pub use list::ListSort;
pub use list::ListedIn;
pub use list::NoesisListAppExt;
pub use list::NoesisListOps;
pub use list::NoesisListPlugin;
pub use list::NoesisListSelection;
pub use list::NoesisListSet;
pub use list::NoesisRowSelected;
pub use list::Selected;
pub use list::UiList;
pub use markup::NoesisMarkupExtensionPlugin;
pub use markup::NoesisMarkupExtensionRegistry;
pub use panel::NoesisPanelAppExt;
pub use panel::NoesisPanelPlugin;
pub use panel::NoesisPanelSet;
pub use panel::NoesisPanelText;
pub use panel::NoesisPanelTextChanged;
pub use panel::SealPanel;
pub use panel::UiPanel;
pub use plain_vm::NoesisViewModel;
pub use plain_vm::NoesisViewModelAppExt;
pub use render::NoesisCamera;
pub use render::NoesisIntermediate;
pub use render::NoesisRenderPlugin;
pub use render::NoesisSet;
pub use render::NoesisView;
pub use resources::NoesisResources;
pub use resources::NoesisResourcesInstalled;
pub use resources::NoesisResourcesPlugin;
pub use resources::ResourceEntry;
pub use routed_events::EventWatchEntry;
pub use routed_events::NoesisEventWatch;
pub use routed_events::NoesisRoutedEvent;
pub use routed_events::NoesisRoutedEventsPlugin;
pub use routed_events::RoutedEventSnapshot;
pub use routed_events::SharedRoutedEventQueue;
pub use routed_events::UiRoutedEvent;
pub use shapes::NoesisShapes;
pub use shapes::NoesisShapesPlugin;
pub use shapes::ShapeKind;
pub use shapes::ShapeSpec;
pub use styles::DataTriggerSpec;
pub use styles::MultiTriggerSpec;
pub use styles::NoesisStyles;
pub use styles::NoesisStylesPlugin;
pub use styles::PropertyTrigger;
pub use styles::StyleSpec;
pub use svg::NoesisSvg;
pub use svg::NoesisSvgChanged;
pub use svg::NoesisSvgPlugin;
pub use text::NoesisText;
pub use text::NoesisTextChanged;
pub use text::NoesisTextPlugin;
pub use theme::NoesisDefaultThemePlugin;
pub use transforms::NoesisTransform;
pub use transforms::NoesisTransformChanged;
pub use transforms::NoesisTransformPlugin;
pub use transforms::TransformSpec;
pub use transforms3d::Matrix3DSpec;
pub use transforms3d::NoesisMatrixTransform3DChanged;
pub use transforms3d::NoesisTransform3D;
pub use transforms3d::NoesisTransform3DChanged;
pub use transforms3d::NoesisTransform3DPlugin;
pub use transforms3d::Transform3DSpec;
pub use typography::FontStyling;
pub use typography::NoesisTypography;
pub use typography::NoesisTypographyChanged;
pub use typography::NoesisTypographyPlugin;
pub use typography::TypographyField;
pub use typography::TypographyValue;
pub use typography::TypographyWatch;
pub use ui::NoesisUi;
pub use viewmodel::NoesisViewModelChanged;
pub use viewmodel::NoesisViewModelPlugin;
pub use viewmodel::NoesisVm;
pub use viewmodel::SharedVmChangedQueue;
pub use viewmodel::ViewModelChangeForwarder;
pub use viewmodel::ViewModelDef;
pub use viewmodel::VmValue;
pub use visibility::NoesisVisibility;
pub use visibility::NoesisVisibilityPlugin;
pub use visual_state::NoesisVisualState;
pub use visual_state::NoesisVisualStatePlugin;
pub use visual_state::StateRequest;
pub use window_compat::NoesisWindowCompatPlugin;
pub use window_compat::WINDOW_CLASS;
pub use xaml::BevyXamlProvider;
pub use xaml::XamlAsset;
pub use xaml::XamlAssetLoader;
pub use xaml::XamlAssetPlugin;
pub use xaml::XamlRegistry;

Modules§

animation
Code-built property animations: start a DoubleAnimation on a named element’s scalar property from Rust, without a XAML <Storyboard>.
bake
Render XAML once into a static texture you can map onto your own geometry.
binding
Code-built bindings with Rust converters: bind a named element’s dependency property to a source through a ValueConverter or MultiValueConverter written in Rust.
brushes
Code-built brushes: paint a named element’s Background, Foreground, Fill or Stroke with a solid color or linear gradient built in Rust.
classes
Register Rust-backed XAML classes (<myns:Foo>) from Bevy systems.
clip
Polygon clips: clip a named element to a polygon set from Rust.
commands
Rust-owned ICommands: let XAML Command="{Binding Name}" controls invoke Rust code.
diagnostics
Engine-wide diagnostics: Noesis allocator counters, bridge bookkeeping and timing in the NoesisDiagnostics resource, plus Noesis error reports routed into Bevy’s log.
dp
Read and write any dependency property on a named element, by name.
events
Button clicks and key presses from named elements, delivered as Bevy messages and as observer events.
focus
Give a named element keyboard focus from Rust, e.g. focus a console’s input box when it opens.
focus_input
Focus navigation and key bindings for a view: directional moves, focus engagement, key chords, and focus prediction.
font
Font assets and the Noesis font provider.
geometry
Draws Rust-supplied polylines into named XAML Path elements.
headless
Headless harness for tests and CI.
image
Image assets and the Noesis texture provider, which back <Image Source> and <ImageBrush ImageSource>.
imaging
Feeds a named <Image> pixels from Rust, with no image file.
inlines
Builds a named TextBlock’s rich inline content (Run, Bold, Italic, Underline, Span, Hyperlink, LineBreak, decorated spans, embedded UI) from Rust, and reads the live structure back.
input
Forwards Bevy mouse, keyboard, touch and window input to Noesis.
integration
Noesis host callbacks (cursor, open URL, play audio) as Bevy messages.
items
Fills XAML list controls (ComboBox, ListBox, ItemsControl) from Bevy.
layout
Sets Margin on named XAML elements, for positioning floating panels (context menus, popups, tooltips) at gameplay coordinates.
list
List controls whose rows are Bevy entities.
markup
Custom XAML markup extensions ({myns:Foo arg}) backed by Rust handlers.
panel
Panels: XAML fragments mounted into a view, with ECS components as their DataContext.
plain_vm
Bind a plain Rust struct, as a Bevy component, to a view’s XAML {Binding field_name}, two-way.
reconcile
How the data-driven bridges split work between parallel ECS systems and the serial Noesis section.
render
Drives each NoesisView’s UI and composites it onto its camera.
resources
Application resources built in Rust: brushes, scalar values, and <ResourceDictionary> XAML fragments that XAML {StaticResource Key} references resolve without a theme file on disk.
routed_events
Surfaces any Noesis RoutedEvent (mouse, key, focus, drag, manipulation, lifecycle) raised on named elements as Bevy messages and observer events.
shapes
Builds Noesis vector shapes (Rectangle, Ellipse, Line) in Rust and places each one inside a named container element of a NoesisView.
styles
Restyles named elements of a NoesisView with a Style built in Rust.
svg
Parses SVG path data in Rust and sizes a named element of a NoesisView to the outline’s bounds.
text
Writes and watches the Text of named elements (TextBox, TextBlock) in a NoesisView.
theme
Loads the control theme that ships with the Noesis SDK.
transforms
Sets the RenderTransform of named elements: post-layout scale, skew, rotation, and translation for UI motion (a button that pops on hover, a panel that slides in, a spinner).
transforms3d
Sets the Transform3D of named elements: rotation, scale, and translation in 3D with perspective, for effects such as a card flip. For flat 2D motion, use the RenderTransform bridge in crate::transforms.
typography
Sets and watches the font properties (size, family, weight, style, stretch) of named text elements in a NoesisView.
ui
NoesisUi, a system parameter for apps with exactly one NoesisView.
viewmodel
Rust-owned view model bound as a view’s DataContext.
visibility
Show or hide named XAML elements on a NoesisView.
visual_state
Move named templated controls between visual states from code.
window_compat
Stand-in for the Window root element, so <Window>-rooted XAML loads.
xaml
XAML assets and the provider Noesis loads them through.

Structs§

ConvertArg
A value or parameter passed to a ValueConverter: a borrowed, boxed Noesis::BaseComponent*, valid only during the call. It is null when the source value is null or no parameter was given. The typed accessors return None when the boxed type doesn’t match.
ModifierKeys
A set of modifier keys (Alt, Control, Shift, Windows). Combine with |, Self::with or FromIterator, and test with Self::contains.
NoesisLicense
Noesis license credentials. See NoesisPlugin::license.
NoesisPlugin
Initializes Noesis and adds the standard plugin set: asset loaders, input, host integration, all bridges, and the render pipeline. Noesis shuts down when the App is dropped.
PlainValueRef
A value the UI wrote to a view-model property, passed to a PlainSetHandler. The typed accessors return None if the value is null or of another type.

Enums§

BindingMode
How a Binding moves values between source and target.
Converted
The result of a ValueConverter, boxed for Noesis when returned.
CursorType
Built-in cursor kind Noesis asks the host to display, carried by NoesisCursorRequested::cursor. Built-in cursor types (Noesis::CursorType in NsGui/Cursor.h), passed to the set_cursor_callback closure. Discriminants match the C++ enum.
FocusNavigationDirection
Direction for FrameworkElement::move_focus and FrameworkElement::predict_focus. Next, Previous, First and Last follow tab order and are not supported by predict_focus; Left, Right, Up and Down are directional.
FontStretch
Font width, from most condensed to most expanded.
FontStyle
Font slant.
FontWeight
Font weight. The discriminant is the OpenType usWeightClass value (Normal = 400, Bold = 700).
Key
A keyboard or gamepad key, for View::key_down / View::key_up and the key-state queries on FrameworkElement. A subset of Noesis::Key; keys outside it can’t be sent.
MouseButton
A mouse button, for View::mouse_button_down and friends (Noesis::MouseButton).
PlainType
The type of a view-model property, as bindings see it.
PlainValue
A value to store in a view-model property with PlainInstance::set.
RoutedEvent
A routed event for subscribe_event. Handlers get the EventArgs accessors that match the event’s argument type. For other events, use subscribe_event_by_name.
TextDecorations
Text decorations for InlineSpec::decorated. The line decoration an Inline draws on its text.

Traits§

MultiValueConverter
Combines the values of a MultiBinding’s children into one target value. Closures of the same signature implement it.
ValueConverter
The logic behind a Converter. Returning None from either method reports UnsetValue.

Functions§

get_culture
The default culture’s BCP-47 name; "en-US" until set_culture is called.
open_url
Asks Noesis to open url, which calls the registered open-URL callback synchronously. Does nothing if no callback is registered.
play_audio
Asks Noesis to play the sound at uri at volume, which calls the registered play-audio callback synchronously. Does nothing if no callback is registered.
set_culture
Sets the default culture by BCP-47 name (e.g. "en-US", "fr-FR"), read back by get_culture. Only the name changes; the number format keeps Noesis’s defaults.

Derive Macros§

NoesisViewModel
Derive macro for NoesisViewModel: binds a plain struct’s fields by name. Implements noesis_bevy::plain_vm::NoesisViewModel for a named struct or a single-field newtype, exposing its fields to XAML bindings by name.