Skip to content

Commit e5a5ed0

Browse files
committed
Rework pixel snapping, take two.
1 parent d68357e commit e5a5ed0

64 files changed

Lines changed: 1220 additions & 567 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
35 Bytes
Loading

masonry/src/doc/implementing_container_widget.md

Lines changed: 7 additions & 8 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
}
@@ -322,11 +321,11 @@ So for instance, if `VerticalStack::children_ids()` returns a list of three chil
322321
Pass methods in container widgets should only implement the logic that is specific to the container itself.
323322
For instance, a container widget with a background color should implement `paint` to draw the background.
324323

324+
[`Point`]: crate::kurbo::Point
325325
[`Size`]: crate::kurbo::Size
326326
[`Widget`]: crate::core::Widget
327327
[`WidgetPod`]: crate::core::WidgetPod
328328
[`WidgetMut`]: crate::core::WidgetMut
329329
[`MeasureCtx::compute_length`]: crate::core::MeasureCtx::compute_length
330-
[`LayoutCtx::place_child`]: crate::core::LayoutCtx::place_child
331-
[`LayoutCtx::run_layout`]: crate::core::LayoutCtx::run_layout
330+
[`LayoutCtx::layout_child`]: crate::core::LayoutCtx::layout_child
332331
[`RegisterCtx::register_child`]: crate::core::RegisterCtx::register_child

0 commit comments

Comments
 (0)