1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright 2018 the Xilem Authors and the Druid Authors
// SPDX-License-Identifier: Apache-2.0
// After you edit the crate's doc comment, run this command, then check README.md for any missing links
// cargo rdme --workspace-project=masonry
//! Masonry is a foundational framework for building GUI libraries in Rust.
//!
//! The developers of Masonry are developing [Xilem][], a reactive UI library built on top of Masonry.
//! Masonry's API is geared towards creating GUI libraries; if you are creating an application, we recommend also considering Xilem.
//!
//! Masonry gives you a platform-independent manager, which owns and maintains a widget tree.
//! 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.
//!
//! It *is* opinionated about its internals: things like text focus, pointer interactions and accessibility events are often handled in a centralized way.
//!
//! Masonry is built on top of:
//!
//! - [Imaging][imaging] (by default [Vello][vello] and [wgpu][wgpu] for 2D graphics.
//! - [Parley][parley] for the text stack.
//! - [AccessKit][accesskit] for plugging into accessibility APIs.
//!
//! Masonry can be used with any windowing library which allows the window content to be rendered using `wgpu`.
//! There are currently two backends for using Masonry to create operating system windows:
//!
//! - [Masonry Winit][masonry_winit] for most platforms.
//! - `masonry_android_view` for Android. This can currently be found in the [Android View repository](https://github.com/rust-mobile/android-view),
//! and is not yet generally usable.
//!
//! <!-- TODO: Document that Masonry is a set of baseline widgets and properties built on Masonry core, which can also be used completely independently -->
//!
//! # Example
//!
//! The to-do-list example looks like this, using Masonry Winit as the backend:
//!
//! ```rust
//! use masonry::core::{ErasedAction, NewWidget, PropertySet, Widget, WidgetId, WidgetTag};
//! use masonry::dpi::LogicalSize;
//! use masonry::layout::Length;
//! use masonry::peniko::color::AlphaColor;
//! use masonry::properties::Padding;
//! use masonry::theme::default_property_set;
//! use masonry::widgets::{Button, ButtonPress, Flex, Label, Portal, TextAction, TextArea, TextInput};
//! use masonry_winit::app::{AppDriver, DriverCtx, NewWindow, WindowId};
//! use masonry_winit::winit::window::Window;
//!
//! const TEXT_INPUT_TAG: WidgetTag<TextInput> = WidgetTag::named("text-input");
//! const LIST_TAG: WidgetTag<Flex> = WidgetTag::named("list");
//! const WIDGET_SPACING: Length = Length::const_px(5.0);
//!
//! struct Driver {
//! next_task: String,
//! window_id: WindowId,
//! }
//!
//! impl AppDriver for Driver {
//! fn on_action(
//! &mut self,
//! window_id: WindowId,
//! ctx: &mut DriverCtx<'_>,
//! _widget_id: WidgetId,
//! action: ErasedAction,
//! ) {
//! debug_assert_eq!(window_id, self.window_id, "unknown window");
//!
//! if action.is::<ButtonPress>() {
//! let render_root = ctx.render_root(window_id);
//!
//! render_root.edit_widget_with_tag(TEXT_INPUT_TAG, |mut text_input| {
//! let mut text_area = TextInput::text_mut(&mut text_input);
//! TextArea::reset_text(&mut text_area, "");
//! });
//! render_root.edit_widget_with_tag(LIST_TAG, |mut list| {
//! let child = Label::new(self.next_task.clone()).prepare();
//! Flex::add_fixed(&mut list, child);
//! });
//! } else if action.is::<TextAction>() {
//! let action = action.downcast::<TextAction>().unwrap();
//! match *action {
//! TextAction::Changed(new_text) => {
//! self.next_task = new_text.clone();
//! }
//! TextAction::Entered(_) => {}
//! TextAction::Cancelled => {}
//! }
//! }
//! }
//! }
//!
//! /// Return initial to-do-list without items.
//! pub fn make_widget_tree() -> NewWidget<impl Widget> {
//! let text_input = NewWidget::new(
//! TextInput::new("").with_placeholder("ex: 'Do the dishes', 'File my taxes', ..."),
//! )
//! .with_tag(TEXT_INPUT_TAG);
//! let button = NewWidget::new(Button::with_text("Add task"));
//!
//! let list = Flex::column()
//! .with_fixed(
//! NewWidget::new(Flex::row().with(text_input, 1.0).with_fixed(button))
//! .with_props(PropertySet::new().with(Padding::all(WIDGET_SPACING))),
//! )
//! .with_fixed_spacer(WIDGET_SPACING);
//!
//! NewWidget::new(Portal::new(NewWidget::new(list).with_tag(LIST_TAG)))
//! }
//!
//! fn main() {
//! 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);
//! let driver = Driver {
//! next_task: String::new(),
//! window_id: WindowId::next(),
//! };
//! # make_widget_tree();
//! # return;
//!
//! masonry_winit::app::run(
//! vec![
//! NewWindow::new_with_id(
//! driver.window_id,
//! window_attributes,
//! make_widget_tree().erased(),
//! )
//! .with_base_color(AlphaColor::from_rgb8(2, 6, 23)),
//! ],
//! driver,
//! default_property_set(),
//! )
//! .unwrap();
//! }
//! ```
//!
//! Running this will open a window that looks like this:
//!
//! ![Screenshot of the to-do-list example][to-do-screenshot]
//!
//! # Feature flags
//!
//! The following crate [feature flags](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features) are available:
//!
//! - `default`: Enables the default features of [Masonry Core][masonry_core], [Masonry Testing][masonry_testing]
//! (if enabled via the `testing` feature).
//! - `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.
//! - `testing`: Re-exports the test harness from [Masonry Testing][masonry_testing].
//!
//! # Debugging features
//!
//! Masonry apps currently ship with several debugging features built in:
//!
//! - A rudimentary widget inspector - toggled by the F11 key.
//! - A debug mode painting widget layout rectangles - toggled by the F12 key.
//! - Optional automatic registration of a [tracing] subscriber, which outputs to the console and to a file in the dev profile.
//!
//! If you want to use your own subscriber, simply set it before starting masonry - in this case masonry will not set a subscriber.
//!
//! [masonry_winit]: https://crates.io/crates/masonry_winit
//! [Xilem]: https://github.com/linebender/xilem/tree/main/xilem
//! [masonry_testing]: https://docs.rs/masonry_testing/latest/masonry_testing/
//! [tracing_tracy]: https://crates.io/crates/tracing-tracy
//! [vello]: https://crates.io/crates/vello
//! [wgpu]: https://crates.io/crates/wgpu
// Screenshot generated in the unit test for the `to_do_list` example.
//!
// LINEBENDER LINT SET - lib.rs - v5
// See https://linebender.org/wiki/canonical-lints/
// These lints shouldn't apply to examples.
// Targeting e.g. 32-bit means structs containing usize can give false positives for 64-bit.
// END LINEBENDER LINT SET
// TODO - re-add #[doc(hidden)]
pub use accesskit;
pub use imaging;
pub use palette;
pub use ;
pub use masonry_testing as testing;
pub use ;