You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apply many small tweaks I found while going over the documentation.
Rename some variables.
Add asserts to `BoxConstraints::constrain_aspect_ratio`.
Flesh out the WidgetState documentation.
Introduce the concept of "zombie flags".
Copy file name to clipboardexpand all lines: masonry/src/doc/01_creating_app.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -118,8 +118,8 @@ When handling `ButtonPressed`:
118
118
-`ctx.render_root()` returns a reference to the `RenderRoot`, which owns the widget tree and all the associated visual state.
119
119
-`RenderRoot::edit_root_widget()` takes a closure; that closure takes a `WidgetMut<Box<dyn Widget>>` which we call `root`. Once the closure returns, `RenderRoot` runs some passes to update the app's internal states.
120
120
-`root.downcast::<...>()` returns a `WidgetMut<RootWidget<...>>`.
121
-
-`RootWidget::child_mut()` returns a `WidgetMut<Portal<...>>` for the `Portal`.
122
-
-`Portal::child_mut()` returns a `WidgetMut<Flex>` for the `Flex`.
121
+
-`RootWidget::child_mut()` returns a `WidgetMut<Portal<...>>`.
122
+
-`Portal::child_mut()` returns a `WidgetMut<Flex>`.
123
123
124
124
A [`WidgetMut`] is a smart reference type which lets us modify the widget tree.
125
125
It's set up to automatically propagate update flags and update internal state when dropped.
Copy file name to clipboardexpand all lines: masonry/src/doc/03_implementing_container_widget.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -254,11 +254,11 @@ Doesn't `VerticalStack::paint` need to call `paint` on its children, for instanc
254
254
255
255
It doesn't.
256
256
257
-
In Masonry, most passes are automatically propagated to children, without container widgets having to implement code iterating over their children.
257
+
In Masonry, most passes are automatically propagated to children, and so container widgets do not need to *and cannot* call the pass methods on their children.
258
258
259
259
So for instance, if `VerticalStack::children_ids()` returns a list of three children, the paint pass will automatically call `paint` on all three children after `VerticalStack::paint()`.
260
260
261
-
So various methods in container widgets should only implement the logic that is specific to the container itself.
261
+
Pass methods in container widgets should only implement the logic that is specific to the container itself.
262
262
For instance, a container widget with a background color should implement `paint` to draw the background.
Copy file name to clipboardexpand all lines: masonry/src/doc/05_pass_system.md
+16-12
Original file line number
Diff line number
Diff line change
@@ -12,15 +12,15 @@
12
12
13
13
</div>
14
14
15
-
Masonry has a set of **passes**, which are computations run over a subset of the widget tree during every frame.
15
+
Masonry's internal architecture is based on a set of **passes**, which are computations run over a subset of the widget tree during every frame.
16
16
17
17
Passes can be split into roughly three categories:
18
18
19
-
-**Event passes:** triggered by user interaction.
20
-
-**Rewrite passes:** run after every event pass, may run multiple times until all invalidation flags are cleared.
21
-
-**Render passes:** run just before rendering a new frame.
19
+
-**Event passes** are triggered by user interaction.
20
+
-**Rewrite passes** run after every event pass, may run multiple times until all invalidation flags are cleared.
21
+
-**Render passes** run just before rendering a new frame.
22
22
23
-
Note: unless otherwise specified, all passes run over widgets in depth-first preorder.
23
+
Note that unless otherwise specified, all passes run over widgets in depth-first preorder, where child order is determined by their position in the `children_ids()` array.
24
24
25
25
26
26
## Event passes
@@ -68,7 +68,7 @@ To address these invalidations, Masonry runs a set of **rewrite passes** over th
68
68
The layout and compose passes have methods with matching names in the Widget trait.
69
69
The update_xxx passes call the widgets' update method.
70
70
71
-
By default, each of these passes completes immediately, unless pass-dependent invalidation flags are set.
71
+
By default, each of these passes completes without doing any work, unless pass-dependent invalidation flags are set.
72
72
Each pass can generally request work for later passes; for instance, the mutate pass can invalidate the layout of a widget, in which case the layout pass will run on that widget and its children and parents.
73
73
74
74
Passes may also request work for *previous* passes, in which case all rewrite passes are run again in sequence.
@@ -106,6 +106,13 @@ It is called when new widgets are added to the tree, or existing widgets are rem
106
106
107
107
It will call the `register_children()` widget method on container widgets whose children changed, then the `update()` method with the `WidgetAdded` event on new widgets.
The layout pass runs bidirectionally, passing constraints from the top down and getting back sizes and other layout info from the bottom up.
@@ -126,8 +133,6 @@ Because the compose pass is more limited than layout, it's easier to recompute i
126
133
127
134
For instance, if a widget in a list changes size, its siblings and parents must be re-laid out to account for the change; whereas changing a given widget's transform only affects its children.
128
135
129
-
Masonry automatically calls the `compose` methods of all widgets in the tree, in depth-first preorder, where child order is determined by their position in the `children_ids()` array.
130
-
131
136
132
137
## Render passes
133
138
@@ -144,17 +149,16 @@ These nodes together form the accessibility tree.
144
149
Methods for these passes should be written under the assumption that they can be skipped or called multiple times for arbitrary reasons.
145
150
Therefore, their ability to affect the widget tree is limited.
146
151
147
-
Masonry automatically calls these methods for all widgets in the tree in depth-first preorder.
148
152
149
153
## External mutation
150
154
151
155
Code with mutable access to the `RenderRoot`, like the Xilem app runner, can get mutable access to the root widget and all its children through the `edit_root_widget()` method, which takes a callback and passes it a `WidgetMut` to the root widget.
152
156
153
-
This is in effect a MUTATE pass which only processes one callback.
157
+
This is in effect a "mutate" pass which only processes one callback.
154
158
155
159
External mutation is how Xilem applies any changes to the widget tree produced by its reactive step.
156
160
157
-
Calling the `edit_root_widget()`method, or any similar direct-mutation method, triggers the entire set of rewrite passes.
161
+
`RenderRoot::edit_root_widget()` triggers the entire set of rewrite passes before returning.
158
162
159
163
160
164
## Pass context types
@@ -164,7 +168,7 @@ Some notes about pass context types:
164
168
- Render passes should be pure and can be skipped occasionally, therefore their context types ([`PaintCtx`] and [`AccessCtx`]) can't set invalidation flags or send signals.
165
169
- The `layout` and `compose` passes lay out all widgets, which are transiently invalid during the passes, therefore [`LayoutCtx`]and [`ComposeCtx`] cannot access the size and position of the `self` widget.
166
170
They can access the layout of children if they have already been laid out.
167
-
- For the same reason, `LayoutCtx`and `ComposeCtx` cannot create a `WidgetRef` reference to a child.
171
+
- For the same reason, [`LayoutCtx`]and [`ComposeCtx`] cannot create a `WidgetRef` reference to a child.
168
172
-[`MutateCtx`], [`EventCtx`] and [`UpdateCtx`] can let you add and remove children.
169
173
-[`RegisterCtx`] can't do anything except register children.
170
174
-[`QueryCtx`] provides read-only information about the widget.
Copy file name to clipboardexpand all lines: masonry/src/event.rs
+39-28
Original file line number
Diff line number
Diff line change
@@ -181,7 +181,6 @@ impl From<PointerButton> for PointerButtons {
181
181
// TODO - How can RenderRoot express "I started a drag-and-drop op"?
182
182
// TODO - Touchpad, Touch, AxisMotion
183
183
// TODO - How to handle CursorEntered?
184
-
// Note to self: Events like "pointerenter", "pointerleave" are handled differently at the Widget level. But that's weird because WidgetPod can distribute them. Need to think about this again.
185
184
#[derive(Debug,Clone)]
186
185
pubenumPointerEvent{
187
186
PointerDown(PointerButton,PointerState),
@@ -313,21 +312,7 @@ pub enum Update {
313
312
}
314
313
315
314
implPointerEvent{
316
-
pubfnnew_pointer_leave() -> Self{
317
-
// TODO - The fact we're creating so many dummy values might be
318
-
// a sign we should refactor that struct
319
-
let pointer_state = PointerState{
320
-
physical_position:Default::default(),
321
-
position:Default::default(),
322
-
buttons:Default::default(),
323
-
mods:Default::default(),
324
-
count:0,
325
-
focus:false,
326
-
force:None,
327
-
};
328
-
Self::PointerLeave(pointer_state)
329
-
}
330
-
315
+
/// Returns the [`PointerState`] of the event.
331
316
pubfnpointer_state(&self) -> &PointerState{
332
317
matchself{
333
318
Self::PointerDown(_, state)
@@ -343,13 +328,17 @@ impl PointerEvent {
343
328
}
344
329
}
345
330
331
+
/// Returns the position of the pointer event, except for [`PointerEvent::PointerLeave`] and [`PointerEvent::HoverFileCancel`].
0 commit comments