Introduce useful helpers in layout module

This commit is contained in:
Héctor Ramón Jiménez 2024-01-09 06:35:33 +01:00
parent d24e50c1a6
commit d62bb8193c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
26 changed files with 189 additions and 127 deletions

View file

@ -206,28 +206,27 @@ pub fn layout<Renderer>(
where
Renderer: text::Renderer,
{
let limits = limits.width(width).height(height);
let bounds = limits.max();
layout::sized(limits, width, height, |limits| {
let bounds = limits.max();
let size = size.unwrap_or_else(|| renderer.default_size());
let font = font.unwrap_or_else(|| renderer.default_font());
let size = size.unwrap_or_else(|| renderer.default_size());
let font = font.unwrap_or_else(|| renderer.default_font());
let State(ref mut paragraph) = state;
let State(ref mut paragraph) = state;
paragraph.update(text::Text {
content,
bounds,
size,
line_height,
font,
horizontal_alignment,
vertical_alignment,
shaping,
});
paragraph.update(text::Text {
content,
bounds,
size,
line_height,
font,
horizontal_alignment,
vertical_alignment,
shaping,
});
let size = limits.resolve(paragraph.min_bounds(), width, height);
layout::Node::new(size)
paragraph.min_bounds()
})
}
/// Draws text using the same logic as the [`Text`] widget.