Make anchoring explicit and improve reusability of text pipelines

This commit is contained in:
Héctor Ramón Jiménez 2025-05-04 03:54:42 +02:00
parent d643bd5ba2
commit 6bf709e03e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
13 changed files with 423 additions and 325 deletions

View file

@ -287,16 +287,18 @@ where
state,
renderer,
limits,
self.width,
Length::Shrink,
&self.label,
self.text_line_height,
self.text_size,
self.font,
text::Alignment::Default,
alignment::Vertical::Top,
self.text_shaping,
self.text_wrapping,
widget::text::Format {
width: self.width,
height: Length::Shrink,
line_height: self.text_line_height,
size: self.text_size,
font: self.font,
align_x: text::Alignment::Default,
align_y: alignment::Vertical::Top,
shaping: self.text_shaping,
wrapping: self.text_wrapping,
},
)
},
)
@ -436,8 +438,8 @@ where
crate::text::draw(
renderer,
defaults,
label_layout,
state.0.raw(),
label_layout.bounds(),
state.raw(),
crate::text::Style {
color: style.text_color,
},

View file

@ -308,16 +308,18 @@ where
state,
renderer,
limits,
self.width,
Length::Shrink,
&self.label,
self.text_line_height,
self.text_size,
self.font,
text::Alignment::Default,
alignment::Vertical::Top,
self.text_shaping,
self.text_wrapping,
widget::text::Format {
width: self.width,
height: Length::Shrink,
line_height: self.text_line_height,
size: self.text_size,
font: self.font,
align_x: text::Alignment::Default,
align_y: alignment::Vertical::Top,
shaping: self.text_shaping,
wrapping: self.text_wrapping,
},
)
},
)
@ -445,8 +447,8 @@ where
crate::text::draw(
renderer,
defaults,
label_layout,
state.0.raw(),
label_layout.bounds(),
state.raw(),
crate::text::Style {
color: style.text_color,
},

View file

@ -365,7 +365,7 @@ where
text::draw(
renderer,
defaults,
layout,
layout.bounds(),
&state.paragraph,
style,
viewport,

View file

@ -57,8 +57,9 @@ use crate::core::widget::operation::{self, Operation};
use crate::core::widget::tree::{self, Tree};
use crate::core::window;
use crate::core::{
Background, Border, Color, Element, Event, InputMethod, Layout, Length,
Padding, Pixels, Point, Rectangle, Shell, Size, Theme, Vector, Widget,
Alignment, Background, Border, Color, Element, Event, InputMethod, Layout,
Length, Padding, Pixels, Point, Rectangle, Shell, Size, Theme, Vector,
Widget,
};
use crate::runtime::Action;
use crate::runtime::task::{self, Task};
@ -481,9 +482,15 @@ where
if self.icon.is_some() {
let icon_layout = children_layout.next().unwrap();
let icon = state.icon.raw();
renderer.fill_paragraph(
state.icon.raw(),
icon_layout.bounds().center(),
icon,
icon_layout.bounds().anchor(
icon.min_bounds(),
Alignment::Center,
Alignment::Center,
),
style.icon,
*viewport,
);
@ -609,8 +616,11 @@ where
renderer.fill_paragraph(
paragraph,
Point::new(text_bounds.x, text_bounds.center_y())
+ Vector::new(alignment_offset - offset, 0.0),
text_bounds.anchor(
paragraph.min_bounds(),
Alignment::Start,
Alignment::Center,
) + Vector::new(alignment_offset - offset, 0.0),
if text.is_empty() {
style.placeholder
} else {
@ -1724,7 +1734,7 @@ fn replace_paragraph<Renderer>(
state.value = paragraph::Plain::new(Text {
font,
line_height,
content: &value.to_string(),
content: value.to_string(),
bounds: Size::new(f32::INFINITY, text_bounds.height),
size: text_size,
align_x: text::Alignment::Default,

View file

@ -291,16 +291,18 @@ where
state,
renderer,
limits,
self.width,
Length::Shrink,
label,
self.text_line_height,
self.text_size,
self.font,
self.text_alignment,
alignment::Vertical::Top,
self.text_shaping,
self.text_wrapping,
widget::text::Format {
width: self.width,
height: Length::Shrink,
line_height: self.text_line_height,
size: self.text_size,
font: self.font,
align_x: self.text_alignment,
align_y: alignment::Vertical::Top,
shaping: self.text_shaping,
wrapping: self.text_wrapping,
},
)
} else {
layout::Node::new(Size::ZERO)
@ -406,8 +408,8 @@ where
crate::text::draw(
renderer,
style,
label_layout,
state.0.raw(),
label_layout.bounds(),
state.raw(),
crate::text::Style::default(),
viewport,
);