Skip to content

Commit

Permalink
Add comments and handle paint_insets with the bounding_rect
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp-M committed Jan 11, 2025
1 parent deca314 commit 7b99baa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion masonry/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl ComposeCtx<'_> {
self.widget_state.needs_compose
}

/// Set a translation for the child widget.
/// Set the scroll translation for the child widget.
///
/// The translation is applied on top of the position from [`LayoutCtx::place_child`].
pub fn set_child_scroll_translation<W: Widget>(
Expand Down Expand Up @@ -949,6 +949,7 @@ impl_context_method!(MutateCtx<'_>, EventCtx<'_>, UpdateCtx<'_>, {
self.request_layout();
}

/// Indicate that the transform of this widget has changed.
pub fn transform_changed(&mut self) {
trace!("transform_changed");
self.widget_state.transform_changed = true;
Expand Down Expand Up @@ -986,6 +987,9 @@ impl_context_method!(MutateCtx<'_>, EventCtx<'_>, UpdateCtx<'_>, {
self.widget_state.is_explicitly_disabled = disabled;
}

/// Set the transform for this widget.
///
/// It behaves similarly as CSS transforms
pub fn set_transform(&mut self, transform: Affine) {
self.widget_state.transform = transform;
self.transform_changed();
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/passes/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn compose_widget(
state.item.window_transform =
parent_window_transform * state.item.transform.then_translate(local_translation);

let local_rect = state.item.size.to_rect();
let local_rect = state.item.size.to_rect() + state.item.paint_insets;
state.item.bounding_rect = state.item.window_transform.transform_rect_bbox(local_rect);

let mut ctx = ComposeCtx {
Expand Down
1 change: 1 addition & 0 deletions masonry/src/passes/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn paint_widget(
},
);

// draw the global axis aligned bounding rect of the widget
if debug_paint {
const BORDER_WIDTH: f64 = 1.0;
let color = get_debug_color(id.to_raw());
Expand Down
3 changes: 3 additions & 0 deletions masonry/src/widget/widget_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl<W: Widget> WidgetMut<'_, W> {
}
}

/// Set the local transform of this widget.
///
/// It behaves similarly as CSS transforms.
pub fn set_transform(&mut self, transform: Affine) {
self.ctx.set_transform(transform);
}
Expand Down
9 changes: 6 additions & 3 deletions masonry/src/widget/widget_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) struct WidgetState {
/// The size of the widget; this is the value returned by the widget's layout
/// method.
pub(crate) size: Size,
/// The origin of the widget in the parent's coordinate space; together with
/// The origin of the widget in the `window_transform` coordinate space; together with
/// `size` these constitute the widget's layout rect.
pub(crate) origin: Point,
/// The insets applied to the layout rect to generate the paint rect.
Expand All @@ -68,7 +68,7 @@ pub(crate) struct WidgetState {
// TODO - Document
// The computed paint rect, in local coordinates.
pub(crate) local_paint_rect: Rect,
/// An axis aligned bounding rect (AABB in 2D), containing itself and all its descendents in window coordinates.
/// An axis aligned bounding rect (AABB in 2D), containing itself and all its descendents in window coordinates. Includes `paint_insets`.
pub(crate) bounding_rect: Rect,
/// The offset of the baseline relative to the bottom of the widget.
///
Expand Down Expand Up @@ -98,8 +98,11 @@ pub(crate) struct WidgetState {

/// This is being computed out of all ancestor transforms and `translation`
pub(crate) window_transform: Affine,
/// Local transform of this widget in the parent coordinate space.
pub(crate) transform: Affine,
/// translation applied by scrolling, this is applied after applying `transform` to this widget.
pub(crate) scroll_translation: Vec2,
/// The `transform` or `scroll_translation` has changed.
pub(crate) transform_changed: bool,

// --- PASSES ---
Expand Down Expand Up @@ -274,7 +277,7 @@ impl WidgetState {
Rect::from_origin_size(self.origin, self.size)
}

/// The axis aligned bounding rect of this widget in window coordinates.
/// The axis aligned bounding rect of this widget in window coordinates. Includes `paint_insets`.
pub fn bounding_rect(&self) -> Rect {
self.bounding_rect
}
Expand Down

0 comments on commit 7b99baa

Please sign in to comment.