2024-05-06 14:50:12 +08:00
< div align = "center" >
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
# Masonry
2024-04-22 17:41:35 +08:00
2024-07-22 20:44:41 +08:00
**A foundational framework for Rust GUI libraries.**
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
[![Latest published version. ](https://img.shields.io/crates/v/masonry.svg )](https://crates.io/crates/masonry)
[![Documentation build status. ](https://img.shields.io/docsrs/masonry.svg )](https://docs.rs/masonry)
[![Apache 2.0 license. ](https://img.shields.io/badge/license-Apache--2.0-blue.svg )](#license)
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
[![Linebender Zulip chat. ](https://img.shields.io/badge/Linebender-%23masonry-blue?logo=Zulip )](https://xi.zulipchat.com/#narrow/stream/317477-masonry)
[![GitHub Actions CI status. ](https://img.shields.io/github/actions/workflow/status/linebender/xilem/ci.yml?logo=github&label=CI )](https://github.com/linebender/xilem/actions)
[![Dependency staleness status. ](https://deps.rs/crate/masonry/latest/status.svg )](https://deps.rs/crate/masonry)
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
< / div >
2024-04-22 17:41:35 +08:00
2024-10-02 20:50:51 +08:00
[tracing_tracy]: https://crates.io/crates/tracing-tracy
2024-07-22 20:44:41 +08:00
<!-- cargo - rdme start -->
Masonry gives you a platform to create windows (using [winit] 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.
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
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.
2024-07-22 20:44:41 +08:00
2024-05-06 14:50:12 +08:00
See [Xilem] as an example of reactive UI built on top of Masonry.
2024-04-22 17:41:35 +08:00
2024-06-03 22:21:41 +08:00
Masonry was originally a fork of [Druid] that emerged from discussions within the Linebender community about what it would look like to turn Druid into a foundational library.
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
Masonry can currently be considered to be in an alpha state.
Lots of things need improvements, e.g. text input is janky and snapshot testing is not consistent across platforms.
2024-04-22 17:41:35 +08:00
2024-06-03 22:21:41 +08:00
## Example
The to-do-list example looks like this:
```rust
use masonry::dpi::LogicalSize;
use masonry::widget::{Button, Flex, Label, Portal, RootWidget, Textbox, WidgetMut};
2024-10-21 20:18:30 +08:00
use masonry::{Action, AppDriver, DriverCtx, WidgetId};
2024-06-03 22:21:41 +08:00
use winit::window::Window;
struct Driver {
next_task: String,
}
impl AppDriver for Driver {
fn on_action(& mut self, ctx: & mut DriverCtx< '_>, _widget_id: WidgetId, action: Action) {
match action {
2024-06-15 00:40:26 +08:00
Action::ButtonPressed(_) => {
2024-06-03 22:21:41 +08:00
let mut root: WidgetMut< RootWidget < Portal < Flex > >> = ctx.get_root();
2024-10-22 21:36:48 +08:00
let mut portal = RootWidget::child_mut(& mut root);
let mut flex = Portal::child_mut(& mut portal);
Flex::add_child(& mut flex, Label::new(self.next_task.clone()));
2024-06-03 22:21:41 +08:00
}
Action::TextChanged(new_text) => {
self.next_task = new_text.clone();
}
_ => {}
}
}
}
fn main() {
2024-10-22 21:49:43 +08:00
const VERTICAL_WIDGET_SPACING: f64 = 20.0;
2024-06-03 22:21:41 +08:00
let main_widget = Portal::new(
Flex::column()
.with_child(
Flex::row()
.with_flex_child(Textbox::new(""), 1.0)
.with_child(Button::new("Add task")),
)
.with_spacer(VERTICAL_WIDGET_SPACING),
);
let window_size = LogicalSize::new(400.0, 400.0);
let window_attributes = Window::default_attributes()
.with_title("To-do list")
.with_resizable(true)
.with_min_inner_size(window_size);
masonry::event_loop_runner::run(
masonry::event_loop_runner::EventLoop::with_user_event(),
window_attributes,
RootWidget::new(main_widget),
Driver {
next_task: String::new(),
},
)
.unwrap();
}
```
2024-10-22 21:49:43 +08:00
For more information, see [the documentation module ](https://docs.rs/masonry/latest/masonry/doc/ ).
### Crate feature flags
2024-10-02 20:50:51 +08:00
The following feature flags are available:
- `tracy` : Enables creating output for the [Tracy ](https://github.com/wolfpld/tracy ) profiler using [`tracing-tracy`][tracing_tracy].
This can be used by installing Tracy and connecting to a Masonry with this feature enabled.
2024-07-22 20:44:41 +08:00
[winit]: https://crates.io/crates/winit
[Druid]: https://crates.io/crates/druid
[Xilem]: https://crates.io/crates/xilem
<!-- cargo - rdme end -->
2024-06-28 21:02:54 +08:00
## Minimum supported Rust Version (MSRV)
2024-07-18 15:38:28 +08:00
This version of Masonry has been verified to compile with **Rust 1.79** and later.
2024-06-28 21:02:54 +08:00
Future versions of Masonry might increase the Rust version requirement.
It will not be treated as a breaking change and as such can even happen with small patch releases.
< details >
< summary > Click here if compiling fails.< / summary >
As time has passed, some of Masonry's dependencies could have released versions with a higher Rust requirement.
If you encounter a compilation issue due to a dependency and don't want to upgrade your Rust toolchain, then you could downgrade the dependency.
```sh
# Use the problematic dependency's name and version
cargo update -p package_name --precise 0.1.1
```
< / details >
2024-05-06 14:50:12 +08:00
## Community
2024-04-22 17:41:35 +08:00
2024-07-31 20:49:54 +08:00
Discussion of Masonry development happens in the [Linebender Zulip ](https://xi.zulipchat.com/ ), specifically the [#masonry channel ](https://xi.zulipchat.com/#narrow/stream/317477-masonry ).
2024-05-06 14:50:12 +08:00
All public content can be read without logging in.
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
Contributions are welcome by pull request. The [Rust code of conduct] applies.
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache 2.0 license, shall be licensed as noted in the [License ](#license ) section, without any additional terms or conditions.
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
## License
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
Licensed under the Apache License, Version 2.0 ([LICENSE](LICENSE) or < http: / / www . apache . org / licenses / LICENSE-2 . 0 > )
2024-04-22 17:41:35 +08:00
2024-05-06 14:50:12 +08:00
[Rust code of conduct]: https://www.rust-lang.org/policies/code-of-conduct