Skip to content

Commit 995d59f

Browse files
committed
Rework pixel snapping, take two.
1 parent db21584 commit 995d59f

71 files changed

Lines changed: 1795 additions & 703 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

masonry/ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ The current passes are:
166166
- **on_xxx_event:** Handles UX-related events, e.g. clicks, text entered, IME updates and accessibility input. Widgets can declare these events as "handled" which has a bunch of semantic implications.
167167
- **anim:** Do updates related to an animation frame.
168168
- **update:** Handles internal changes to some widgets, e.g. when the widget is marked as "disabled" or Masonry detects that a widget is hovered by a pointer.
169-
- **layout:** Container widgets measure their children with `LayoutCtx::compute_size` and then lay them out with `LayoutCtx::run_layout`, finally giving them a position with `LayoutCtx::place_child`.
169+
- **layout:** Container widgets measure their children with `LayoutCtx::compute_size` and then lay them out with `LayoutCtx::layout_child`, choosing an origin and size for each child.
170170
- **compose:** Computes the global transform/origin for every widget.
171171
- **paint** Paint every widget.
172172
- **accessibility:** Compute every widget's node in the accessibility tree.

masonry/examples/layers.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ impl Widget for OverlayBox {
133133

134134
fn layout(&mut self, ctx: &mut LayoutCtx<'_>, _props: &PropertiesRef<'_>, size: Size) {
135135
let child_size = ctx.compute_size(&mut self.child, SizeDef::fit(size), size.into());
136-
ctx.run_layout(&mut self.child, child_size);
137-
ctx.place_child(&mut self.child, Point::ORIGIN);
136+
ctx.layout_child(&mut self.child, Point::ORIGIN, child_size);
138137
}
139138

140139
fn paint(
-18 Bytes
Loading
-19 Bytes
Loading
-1 Bytes
Loading
9 Bytes
Loading
53 Bytes
Loading
2 Bytes
Loading

masonry/src/doc/implementing_container_widget.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ Like with a leaf widget, the `measure` method must compute and return the length
7272
Before that, it must call [`MeasureCtx::compute_length`] for each of its own children.
7373
For a vertical stack, we want to sum these on the vertical axis and take the largest on the horizontal axis.
7474

75-
Then later in `layout`, it must call [`LayoutCtx::run_layout`] then [`LayoutCtx::place_child`] for each of its own children:
75+
Then later in `layout`, it must call [`LayoutCtx::layout_child`] for each of its own children:
7676

77-
- `LayoutCtx::run_layout` recursively calls `Widget::layout` on the child.
78-
It takes a [`Size`] argument, which is the chosen size of the child.
79-
- `LayoutCtx::place_child` sets the child's position relative to the container.
77+
- `LayoutCtx::layout_child` recursively calls `Widget::layout` on the child.
78+
It takes both a [`Point`] and [`Size`] argument, which are the chosen origin and size of the child.
79+
The child's origin is in relation to the container.
8080

8181
The `layout` method *must* iterate over all its children.
8282
Not doing so is a logical bug.
@@ -144,8 +144,7 @@ impl Widget for VerticalStack {
144144
let mut y_offset = 0.0;
145145
for child in &mut self.children {
146146
let child_size = ctx.compute_size(child, auto_size, context_size);
147-
ctx.run_layout(child, child_size);
148-
ctx.place_child(child, Point::new(0.0, y_offset));
147+
ctx.layout_child(child, Point::new(0.0, y_offset), child_size);
149148
150149
y_offset += child_size.height + self.gap;
151150
}
@@ -163,7 +162,8 @@ There are a few things to note here:
163162

164163
### `compose`
165164

166-
The `compose` method is called during the compose pass, after layout.
165+
The `compose` method may be called during the compose pass, after layout.
166+
Masonry guarantees that `compose` is called after that widget's `layout` method runs, or when the widget explicitly requests compose.
167167

168168
The compose pass runs top-down and assigns transforms to children. Transform-only layout changes (e.g. scrolling) should request compose instead of requesting layout.
169169

@@ -321,11 +321,11 @@ So for instance, if `VerticalStack::children_ids()` returns a list of three chil
321321
Pass methods in container widgets should only implement the logic that is specific to the container itself.
322322
For instance, a container widget with a background color should implement `paint` to draw the background.
323323

324+
[`Point`]: crate::kurbo::Point
324325
[`Size`]: crate::kurbo::Size
325326
[`Widget`]: crate::core::Widget
326327
[`WidgetPod`]: crate::core::WidgetPod
327328
[`WidgetMut`]: crate::core::WidgetMut
328329
[`MeasureCtx::compute_length`]: crate::core::MeasureCtx::compute_length
329-
[`LayoutCtx::place_child`]: crate::core::LayoutCtx::place_child
330-
[`LayoutCtx::run_layout`]: crate::core::LayoutCtx::run_layout
330+
[`LayoutCtx::layout_child`]: crate::core::LayoutCtx::layout_child
331331
[`RegisterCtx::register_child`]: crate::core::RegisterCtx::register_child

masonry/src/doc/vertical_stack.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ impl Widget for VerticalStack {
140140
let mut y_offset = 0.0;
141141
for child in &mut self.children {
142142
let child_size = ctx.compute_size(child, auto_size, context_size);
143-
ctx.run_layout(child, child_size);
144-
ctx.place_child(child, Point::new(0.0, y_offset));
143+
ctx.layout_child(child, Point::new(0.0, y_offset), child_size);
145144

146145
y_offset += child_size.height + self.gap;
147146
}

0 commit comments

Comments
 (0)