Skip to content

Commit

Permalink
fix(core): 🐛 padding does not work after being implemented as a WrapR…
Browse files Browse the repository at this point in the history
…ender
  • Loading branch information
M-Adoo authored and rchangelog[bot] committed Dec 19, 2024
1 parent 8239522 commit d1a44db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

- **core**: Added `Measure` to enable support for percentage values for position, and `Anchor` now supports percentage values. (#672 @M-Adoo)
- **core**: Add APIs `AppCtx::once_next_frame`, `Window::once_next_frame`, `Window::once_frame_finished` and `Window::once_before_layout`. (#672 @M-Adoo)
- **painter**: Typography now supports baselines (middle and alphabetic). (#pr @M-Adoo)
- **painter**: Typography now supports baselines (middle and alphabetic). (#674 @M-Adoo)

### Fixed

- **core**: Fix set opacity zero no work to it's children. (#671 @wjian23)
- **core**: Fix TextStyle cause providers mismatched (#671 @wjian23)
- **core**: Running an animation that is already in progress does not trigger a smooth transition. (#672 @M-Adoo)
- **core**: The framework incorrectly clamps the layout result of the render widget. (#672 @M-Adoo)
- **painter**: Fixed text line height does not work correctly. (#pr @M-Adoo)
- **painter**: Fixed issue with text not being drawn at the middle baseline by default. (#pr @M-Adoo)
- **painter**: Fixed text line height does not work correctly. (#674 @M-Adoo)
- **painter**: Fixed issue with text not being drawn at the middle baseline by default. (#674 @M-Adoo)

## [0.4.0-alpha.19] - 2024-12-18

Expand Down
44 changes: 24 additions & 20 deletions core/src/builtin_widgets/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,20 @@ impl WrapRender for Padding {
fn perform_layout(&self, clamp: BoxClamp, host: &dyn Render, ctx: &mut LayoutCtx) -> Size {
let thickness = self.padding.thickness();
let zero = Size::zero();
// Reset children position before layout
let (ctx, children) = ctx.split_children();
for c in children {
ctx.update_position(c, Point::zero());
}

// Shrink the clamp for child.
let min = (clamp.min - thickness).max(zero);
let max = (clamp.max - thickness).max(zero);
// Shrink the clamp of child.
let child_clamp = BoxClamp { min, max };
let mut size = host.perform_layout(child_clamp, ctx);
let size = host.perform_layout(child_clamp, ctx);

size = clamp.clamp(size + thickness);

let (ctx, children) = ctx.split_children();
// Update the children's positions to ensure they are correctly positioned after
// expansion with padding.
for c in children {
if let Some(pos) = ctx.widget_box_pos(c) {
let pos = pos + Vector::new(self.padding.left, self.padding.top);
ctx.update_position(c, pos);
}
}
clamp.clamp(size + thickness)
}

size
fn paint(&self, host: &dyn Render, ctx: &mut PaintingCtx) {
let EdgeInsets { left, top, .. } = self.padding;
ctx.painter().translate(left, top);
host.paint(ctx);
}
}

Expand All @@ -56,7 +45,7 @@ mod tests {
use ribir_dev_helper::*;

use super::*;
use crate::test_helper::*;
use crate::{reset_test_env, test_helper::*};

widget_layout_test!(
smoke,
Expand All @@ -75,4 +64,19 @@ mod tests {
.with_size(Size::new(100., 100.))
.with_x(1.)
);

#[test]
fn fix_padding_draw() {
reset_test_env!();

assert_widget_eq_image!(
WidgetTester::new(text! {
padding: EdgeInsets::all(10.),
background: Color::GREEN,
text: "Hello, Ribir!"
})
.with_wnd_size(Size::new(128., 48.)),
"padding_draw"
);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d1a44db

Please sign in to comment.