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

@ -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,