Skip to content

Commit

Permalink
fix(core): 🐛 wrong clamp in WrapRender layout
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Dec 26, 2024
1 parent 7330c0e commit 5e7af7e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
7 changes: 6 additions & 1 deletion core/src/builtin_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,10 @@ impl<'a> FatObj<Widget<'a>> {
scrollable,
layout_box,
class,
cursor,
constrained_box,
tooltips,
margin,
cursor,
mix_builtin,
request_focus,
transform,
Expand Down Expand Up @@ -1107,3 +1107,8 @@ where

fn with_child(self, child: C) -> Self::Target { self.map(|host| host.with_child(child)) }
}

impl Declare for FatObj<()> {
type Builder = Self;
fn declarer() -> Self::Builder { FatObj::default() }
}
18 changes: 12 additions & 6 deletions core/src/builtin_widgets/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ impl WrapRender for HAlignWidget {
clamp.min.width = clamp.max.width;
}

let child_size = host.perform_layout(clamp, ctx);
let x = align.align_value(child_size.width, clamp.max.width);
let host_size = host.perform_layout(clamp, ctx);
let x = align.align_value(host_size.width, clamp.max.width);
let pos = ctx.box_pos().unwrap_or_default();
ctx.update_position(ctx.widget_id(), Point::new(x, pos.y));
clamp.clamp(child_size)

// The size should not be clamped; it should simply follow its host. If the host
// ignores the constraint, the align widget should do the same.
host_size
}
}

Expand All @@ -101,11 +104,14 @@ impl WrapRender for VAlignWidget {
if align == Align::Stretch {
clamp.min.height = clamp.max.height;
}
let child_size = host.perform_layout(clamp, ctx);
let y = align.align_value(child_size.height, clamp.max.height);
let host_size = host.perform_layout(clamp, ctx);
let y = align.align_value(host_size.height, clamp.max.height);
let pos = ctx.box_pos().unwrap_or_default();
ctx.update_position(ctx.widget_id(), Point::new(pos.x, y));
clamp.clamp(child_size)

// The size should not be clamped; it should simply follow its host. If the host
// ignores the constraint, the align widget should do the same.
host_size
}
}

Expand Down
10 changes: 4 additions & 6 deletions core/src/builtin_widgets/margin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ pub(crate) fn space_around_layout(
// widget is already set during layout.
// ctx.force_child_relayout(child);

let thickness = edges.thickness();
let zero = Size::zero();
let min = (clamp.min - thickness).max(zero);
let max = (clamp.max - thickness).max(zero);
let thickness = edges.thickness().min(clamp.max);
let min = (clamp.min - thickness).max(ZERO_SIZE);
let max = clamp.max - thickness;

// Shrink the clamp of child.
let child_clamp = BoxClamp { min, max };
Expand All @@ -144,8 +143,7 @@ pub(crate) fn space_around_layout(
let pos = pos + Vector::new(edges.left, edges.top);
ctx.update_position(child, pos);

// Expand the size, so the child have padding.
clamp.clamp(size + thickness)
size + thickness
}

#[cfg(test)]
Expand Down

0 comments on commit 5e7af7e

Please sign in to comment.