Expand description
A framework that aims to provide the foundation for Rust GUI libraries.
Masonry gives you a platform to create windows (using Glazier as a backend) each with a tree of widgets. It also gives you tools to inspect that widget tree at runtime, write unit tests on it, and generally have an easier time debugging and maintaining your app.
The framework is not opinionated about what your user-facing abstraction will be: you can implement immediate-mode GUI, the Elm architecture, functional reactive GUI, etc, on top of Masonry.
This project was originally was originally a fork of Druid that emerged from discussions I had with Raph Levien and Colin Rofls about what it would look like to turn Druid into a foundational library.
§Example
(TODO: FIX THIS EXAMPLE) The todo-list example looks like this:
use masonry::widget::{prelude::*, TextBox};
use masonry::widget::{Button, Flex, Label, Portal, WidgetMut};
use masonry::Action;
use masonry::{AppDelegate, AppLauncher, DelegateCtx, WindowDescription, WindowId};
const VERTICAL_WIDGET_SPACING: f64 = 20.0;
struct Delegate {
next_task: String,
}
impl AppDelegate for Delegate {
fn on_action(
&mut self,
ctx: &mut DelegateCtx,
_window_id: WindowId,
_widget_id: WidgetId,
action: Action,
) {
match action {
Action::ButtonPressed => {
let mut root: WidgetMut<Portal<Flex>> = ctx.get_root();
let mut flex = root.child_mut();
flex.add_child(Label::new(self.next_task.clone()));
}
Action::TextChanged(new_text) => {
self.next_task = new_text.clone();
}
_ => {}
}
}
}
fn main() {
// The main button with some space below, all inside a scrollable area.
let root_widget = Portal::new(
Flex::column()
.with_child(
Flex::row()
.with_child(TextBox::new(""))
.with_child(Button::new("Add task")),
)
.with_spacer(VERTICAL_WIDGET_SPACING),
);
let main_window = WindowDescription::new(root_widget)
.title("To-do list")
.window_size((400.0, 400.0));
AppLauncher::with_window(main_window)
.with_delegate(Delegate {
next_task: String::new(),
})
.log_to_console()
.launch()
.expect("Failed to launch application");
}
Re-exports§
pub use widget::BackgroundBrush;
pub use widget::WidgetPod;
pub use widget::WidgetState;
pub use text_helpers::ArcStr;
pub use kurbo;
pub use parley;
pub use vello;
Modules§
- Helper tools for writing unit tests.
- Support for text display and rendering
- Helper functions for working with text in Masonry.
- Theme keys and initial values.
- Common widgets.
Macros§
- Assert a snapshot of a rendered frame of your app.
Structs§
- A 2D affine transform.
- Constraints for layout.
- 32-bit RGBA color.
- A context provided to event handling methods of widgets.
- Definition of a gradient that transitions between two or more colors.
- Insets from the edges of a rectangle.
- A context provided to layout handling methods of widgets.
- A context provided to the
lifecycle
method on widgets. - A context passed to paint methods of widgets.
- A 2D point.
- A rectangle.
- A 2D size.
- A 2D vector.
- A context provided inside of
WidgetMut
. - A unique identifier for a single
Widget
.
Enums§
- Events from UI elements.
- An enum for specifying whether an event was handled.
- Internal lifecycle events used by Masonry inside
WidgetPod
. - Application life cycle events.
- Event indicating status changes within the widget hierarchy.
- Alignment of a layout.
Traits§
- Trait extending Any, implemented for all types that implement Any.
- The trait implemented by all widgets.