Skip to content

Commit 83cfa80

Browse files
committed
Remove references to layout rect
1 parent 8207370 commit 83cfa80

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

masonry/src/core/contexts.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,8 @@ impl LayoutCtx<'_> {
594594
self.get_child_state(child).baseline_offset
595595
}
596596

597-
/// Get the given child's layout rect.
598-
///
599-
/// ## Panics
600-
///
601-
/// This method will panic if [`LayoutCtx::run_layout`] and [`LayoutCtx::place_child`]
602-
/// have not been called yet for the child.
597+
// TODO - Remove (used in Flex)
598+
#[doc(hidden)]
603599
#[track_caller]
604600
pub fn child_layout_rect(&self, child: &WidgetPod<impl Widget + ?Sized>) -> Rect {
605601
self.assert_layout_done(child, "child_layout_rect");
@@ -629,7 +625,7 @@ impl LayoutCtx<'_> {
629625
#[track_caller]
630626
pub fn child_size(&self, child: &WidgetPod<impl Widget + ?Sized>) -> Size {
631627
self.assert_layout_done(child, "child_size");
632-
self.get_child_state(child).layout_rect().size()
628+
self.get_child_state(child).size
633629
}
634630

635631
/// Skips running the layout pass and calling [`LayoutCtx::place_child`] on the child.
@@ -730,16 +726,6 @@ impl_context_method!(
730726
self.widget_state.size
731727
}
732728

733-
/// The layout rect of the widget in window coordinates.
734-
///
735-
/// This is the layout [size](Self::size) and [window_origin](Self::window_origin) combined.
736-
///
737-
/// See [layout rect documentation](crate::doc::doc_06_masonry_concepts#layout-rect)
738-
/// for details.
739-
pub fn global_layout_rect(&self) -> Rect {
740-
Rect::from_origin_size(self.widget_state.window_origin(), self.widget_state.size)
741-
}
742-
743729
// TODO - Remove
744730
#[allow(dead_code, reason = "Only used in tests")]
745731
pub(crate) fn local_layout_rect(&self) -> Rect {

masonry/src/core/widget_state.rs

+2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ impl WidgetState {
294294
///
295295
/// By default, returns the same as [`Self::bounding_rect`].
296296
pub(crate) fn get_ime_area(&self) -> Rect {
297+
// Note: this returns sensible values for a widget that is translated and/or rescaled.
298+
// Other transformations like rotation may produce weird IME areas.
297299
self.window_transform
298300
.transform_rect_bbox(self.ime_area.unwrap_or_else(|| self.size.to_rect()))
299301
}

masonry/src/doc/06_masonry_concepts.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,24 @@ A widget is considered "interactive" if it can still get text and/or pointer eve
100100
Stashed and disabled widget are non-interactive.
101101

102102

103-
## Layout rect
103+
## Bounding rect
104104

105-
A widget's layout rect includes its self-declared size, and the position attributed by its parent (local position) / parents (global position).
105+
A widget's bounding rect is a window-space axis-aligned rectangle inside of which pointer events might affect either the widget or its descendants.
106106

107-
Pointer events cannot target a widget if they are outside its layout rect, though they can target its children (see **Bounding rect** section).
107+
In general, the bounding rect is a union or a widget's layout rect and the bounding rects of all its descendants.
108108

109-
A layout rect doesn't necessarily have a formal definition; it's generally where the widget will be drawn, though a widget can be drawn outside its layout rect; it's usually a widget's own space and containers will try to avoid having its children's layout rects overlap.
109+
The bounding rects of the widget tree form a kind of "bounding volume hierarchy": when looking to find which widget a pointer is on, Masonry will automatically exclude any widget if the pointer is outside its bounding rect.
110110

111+
<!-- TODO - Include illustration. -->
111112

112-
## Bounding rect
113+
<!-- TODO - Add section about clip paths and pointer detection. -->
113114

114-
A widget's bounding rect is a rectangle inside of which pointer events might affect either the widget or its descendants.
115115

116-
In general, the bounding rect is a union or a widget's layout rect and the bounding rects of all its descendants.
116+
## Layout rect
117117

118-
The bounding rects of the widget tree form a kind of "bounding volume hierarchy": when looking to find which widget a pointer is on, Masonry will automatically exclude any widget if the pointer is outside its bounding rect.
118+
Previous versions of Masonry had a concept of a widget's "layout rect", composed of its self-declared size and the position attributed by its parent.
119119

120-
<!-- TODO - Include illustration. -->
120+
However, given that widgets can have arbitrary transforms, the concept of an axis-aligned layout rect doesn't really make sense anymore.
121121

122122

123123
## Safety rails

masonry/src/testing/harness.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ impl TestHarness {
472472
#[track_caller]
473473
pub fn mouse_move_to(&mut self, id: WidgetId) {
474474
let widget = self.get_widget(id);
475-
let widget_center = widget.ctx().global_layout_rect().center();
475+
let local_widget_center = (widget.ctx().size() / 2.0).to_vec2().to_point();
476+
let widget_center = widget.ctx().widget_state.window_transform * local_widget_center;
476477

477478
if !widget.ctx().accepts_pointer_interaction() {
478479
panic!("Widget {id} doesn't accept pointer events");

0 commit comments

Comments
 (0)