3 releases

0.1.2 Feb 5, 2023
0.1.1 Feb 5, 2023
0.1.0 Nov 30, 2022

#80 in GUI


15K SLoC


Masonry is 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.


cargo add masonry


On Linux, Masonry requires gtk+3; see GTK installation page. (On ubuntu-based distro, running sudo apt-get install libgtk-3-dev from the terminal will do the job.)


On OpenBSD, Masonry requires gtk+3; install from packages:

pkg_add gtk+3


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,
        _env: &Env,
    ) {
        match action {
            Action::ButtonPressed => {
                let mut root: WidgetMut<Portal<Flex>> = ctx.get_root();
                let mut flex = root.child_mut();
            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(
                    .with_child(Button::new("Add task")),

    let main_window = WindowDescription::new(root_widget)
        .title("To-do list")
        .window_size((400.0, 400.0));

        .with_delegate(Delegate {
            next_task: String::new(),
        .expect("Failed to launch application");

As you can see, compared to crates like Druid or Iced, Masonry takes a fairly low-level approach to GUI: there is no complex reconciliation logic or dataflow going on behind the scenes; if you want to add a widget to the flex container, you call flex.add_child(your_widget).

This simplicity makes Masonry somewhat painful if you want to use it to actually build GUI applications. The hope is that, by being low-level and straightforward, developers can easily build GUI frameworks on top of it.

(Well, in theory. The first stress-test will be porting Panoramix, a React-style GUI in Rust, to Masonry.)

Unit tests

Masonry is designed to make unit tests easy to write, as if the test function were a mouse-and-keyboard user. Tests look like this:

fn some_test_with_a_button() {
    let [button_id] = widget_ids();
    let widget = Button::new("Hello").with_id(button_id);

    let mut harness = TestHarness::create(widget);

    // Make a snapshot test of the visual contents of the window
    assert_render_snapshot!(harness, "hello");

    harness.edit_root_widget(|mut button, _| {
        let mut button = button.downcast::<Button>().unwrap();

    // Make new snapshot test now that the window has changed
    assert_render_snapshot!(harness, "world");

    // References to widget automatically implement Debug, and
    // will print their part of the widget hierarchy.
    println!("Window contents: {:?}", harness.root_widget());

    // You can also use insta to snapshot-test the widget hierarchy

    // Clicking on a button will produce a "ButtonPressed" action.
        Some((Action::ButtonPressed, button_id))


Issues and PRs are welcome. See help-wanted issues if you don't know where to begin.


The immediate next steps are:

  • Remove Env type and Data trait (#8)

  • Re-add Dialog feature (#25)

  • Switch to using Vello and Glazier (#24)

  • Refactor TextLayout (#23)

  • Rework Widget trait (#26)

  • Port Panoramix to Masonry

  • Port Xilem to Masonry

See ROADMAP.md and the issues page for more.


~596K SLoC