Fix horizontal text alignment

This commit is contained in:
Héctor Ramón Jiménez 2025-03-11 00:43:51 +01:00
parent 35c0e14452
commit 179a34d37b
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
23 changed files with 141 additions and 67 deletions

View file

@ -87,8 +87,8 @@ impl text::Paragraph for () {
text::Difference::None text::Difference::None
} }
fn horizontal_alignment(&self) -> alignment::Horizontal { fn horizontal_alignment(&self) -> Option<alignment::Horizontal> {
alignment::Horizontal::Left None
} }
fn vertical_alignment(&self) -> alignment::Vertical { fn vertical_alignment(&self) -> alignment::Vertical {

View file

@ -34,7 +34,7 @@ pub struct Text<Content = String, Font = crate::Font> {
pub font: Font, pub font: Font,
/// The horizontal alignment of the [`Text`]. /// The horizontal alignment of the [`Text`].
pub horizontal_alignment: alignment::Horizontal, pub horizontal_alignment: Option<alignment::Horizontal>,
/// The vertical alignment of the [`Text`]. /// The vertical alignment of the [`Text`].
pub vertical_alignment: alignment::Vertical, pub vertical_alignment: alignment::Vertical,

View file

@ -24,7 +24,7 @@ pub trait Paragraph: Sized + Default {
fn compare(&self, text: Text<(), Self::Font>) -> Difference; fn compare(&self, text: Text<(), Self::Font>) -> Difference;
/// Returns the horizontal alignment of the [`Paragraph`]. /// Returns the horizontal alignment of the [`Paragraph`].
fn horizontal_alignment(&self) -> alignment::Horizontal; fn horizontal_alignment(&self) -> Option<alignment::Horizontal>;
/// Returns the vertical alignment of the [`Paragraph`]. /// Returns the vertical alignment of the [`Paragraph`].
fn vertical_alignment(&self) -> alignment::Vertical; fn vertical_alignment(&self) -> alignment::Vertical;
@ -108,7 +108,7 @@ impl<P: Paragraph> Plain<P> {
} }
/// Returns the horizontal alignment of the [`Paragraph`]. /// Returns the horizontal alignment of the [`Paragraph`].
pub fn horizontal_alignment(&self) -> alignment::Horizontal { pub fn horizontal_alignment(&self) -> Option<alignment::Horizontal> {
self.raw.horizontal_alignment() self.raw.horizontal_alignment()
} }

View file

@ -67,7 +67,7 @@ where
line_height: LineHeight, line_height: LineHeight,
width: Length, width: Length,
height: Length, height: Length,
horizontal_alignment: alignment::Horizontal, horizontal_alignment: Option<alignment::Horizontal>,
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
font: Option<Renderer::Font>, font: Option<Renderer::Font>,
shaping: Shaping, shaping: Shaping,
@ -89,7 +89,7 @@ where
font: None, font: None,
width: Length::Shrink, width: Length::Shrink,
height: Length::Shrink, height: Length::Shrink,
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Top, vertical_alignment: alignment::Vertical::Top,
shaping: Shaping::default(), shaping: Shaping::default(),
wrapping: Wrapping::default(), wrapping: Wrapping::default(),
@ -140,7 +140,7 @@ where
mut self, mut self,
alignment: impl Into<alignment::Horizontal>, alignment: impl Into<alignment::Horizontal>,
) -> Self { ) -> Self {
self.horizontal_alignment = alignment.into(); self.horizontal_alignment = Some(alignment.into());
self self
} }
@ -290,7 +290,7 @@ pub fn layout<Renderer>(
line_height: LineHeight, line_height: LineHeight,
size: Option<Pixels>, size: Option<Pixels>,
font: Option<Renderer::Font>, font: Option<Renderer::Font>,
horizontal_alignment: alignment::Horizontal, horizontal_alignment: Option<alignment::Horizontal>,
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
shaping: Shaping, shaping: Shaping,
wrapping: Wrapping, wrapping: Wrapping,
@ -345,9 +345,9 @@ pub fn draw<Renderer>(
let bounds = layout.bounds(); let bounds = layout.bounds();
let x = match paragraph.horizontal_alignment() { let x = match paragraph.horizontal_alignment() {
alignment::Horizontal::Left => bounds.x, None | Some(alignment::Horizontal::Left) => bounds.x,
alignment::Horizontal::Center => bounds.center_x(), Some(alignment::Horizontal::Center) => bounds.center_x(),
alignment::Horizontal::Right => bounds.x + bounds.width, Some(alignment::Horizontal::Right) => bounds.x + bounds.width,
}; };
let y = match paragraph.vertical_alignment() { let y = match paragraph.vertical_alignment() {

View file

@ -10,11 +10,14 @@ pub struct Text {
/// The contents of the text /// The contents of the text
pub content: String, pub content: String,
/// The position of the text relative to the alignment properties. /// The position of the text relative to the alignment properties.
///
/// By default, this position will be relative to the top-left corner coordinate meaning that /// By default, this position will be relative to the top-left corner coordinate meaning that
/// if the horizontal and vertical alignments are unchanged, this property will tell where the /// if the horizontal and vertical alignments are unchanged, this property will tell where the
/// top-left corner of the text should be placed. /// top-left corner of the text should be placed.
///
/// By changing the horizontal_alignment and vertical_alignment properties, you are are able to /// By changing the horizontal_alignment and vertical_alignment properties, you are are able to
/// change what part of text is placed at this positions. /// change what part of text is placed at this positions.
///
/// For example, when the horizontal_alignment and vertical_alignment are set to Center, the /// For example, when the horizontal_alignment and vertical_alignment are set to Center, the
/// center of the text will be placed at the given position NOT the top-left coordinate. /// center of the text will be placed at the given position NOT the top-left coordinate.
pub position: Point, pub position: Point,

View file

@ -54,7 +54,7 @@ pub enum Text {
/// The font of the text. /// The font of the text.
font: Font, font: Font,
/// The horizontal alignment of the text. /// The horizontal alignment of the text.
horizontal_alignment: alignment::Horizontal, horizontal_alignment: Option<alignment::Horizontal>,
/// The vertical alignment of the text. /// The vertical alignment of the text.
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
/// The shaping strategy of the text. /// The shaping strategy of the text.
@ -84,7 +84,7 @@ impl Text {
Rectangle::new(*position, paragraph.min_bounds) Rectangle::new(*position, paragraph.min_bounds)
.intersection(clip_bounds) .intersection(clip_bounds)
.map(|bounds| bounds * *transformation), .map(|bounds| bounds * *transformation),
Some(paragraph.horizontal_alignment), paragraph.horizontal_alignment,
Some(paragraph.vertical_alignment), Some(paragraph.vertical_alignment),
), ),
Text::Editor { Text::Editor {
@ -108,7 +108,7 @@ impl Text {
.. ..
} => ( } => (
bounds.intersection(clip_bounds), bounds.intersection(clip_bounds),
Some(*horizontal_alignment), *horizontal_alignment,
Some(*vertical_alignment), Some(*vertical_alignment),
), ),
Text::Raw { raw, .. } => (Some(raw.clip_bounds), None, None), Text::Raw { raw, .. } => (Some(raw.clip_bounds), None, None),
@ -242,15 +242,19 @@ impl PartialEq for Raw {
} }
/// Measures the dimensions of the given [`cosmic_text::Buffer`]. /// Measures the dimensions of the given [`cosmic_text::Buffer`].
pub fn measure(buffer: &cosmic_text::Buffer) -> Size { pub fn measure(buffer: &cosmic_text::Buffer) -> (Size, bool) {
let (width, height) = let (width, height, has_rtl) = buffer.layout_runs().fold(
buffer (0.0, 0.0, false),
.layout_runs() |(width, height, has_rtl), run| {
.fold((0.0, 0.0), |(width, height), run| { (
(run.line_w.max(width), height + run.line_height) run.line_w.max(width),
}); height + run.line_height,
has_rtl || run.rtl,
)
},
);
Size::new(width, height) (Size::new(width, height), has_rtl)
} }
/// Returns the attributes of the given [`Font`]. /// Returns the attributes of the given [`Font`].
@ -309,6 +313,14 @@ fn to_style(style: font::Style) -> cosmic_text::Style {
} }
} }
fn to_align(alignment: alignment::Horizontal) -> cosmic_text::Align {
match alignment {
alignment::Horizontal::Left => cosmic_text::Align::Left,
alignment::Horizontal::Center => cosmic_text::Align::Center,
alignment::Horizontal::Right => cosmic_text::Align::Right,
}
}
/// Converts some [`Shaping`] strategy to a [`cosmic_text::Shaping`] strategy. /// Converts some [`Shaping`] strategy to a [`cosmic_text::Shaping`] strategy.
pub fn to_shaping(shaping: Shaping) -> cosmic_text::Shaping { pub fn to_shaping(shaping: Shaping) -> cosmic_text::Shaping {
match shaping { match shaping {

View file

@ -58,7 +58,16 @@ impl Cache {
text::to_shaping(key.shaping), text::to_shaping(key.shaping),
); );
let bounds = text::measure(&buffer); let (bounds, has_rtl) = text::measure(&buffer);
if has_rtl {
buffer.set_size(
font_system,
Some(bounds.width),
Some(bounds.height),
);
}
let _ = entry.insert(Entry { let _ = entry.insert(Entry {
buffer, buffer,
min_bounds: bounds, min_bounds: bounds,

View file

@ -450,7 +450,10 @@ impl editor::Editor for Editor {
fn min_bounds(&self) -> Size { fn min_bounds(&self) -> Size {
let internal = self.internal(); let internal = self.internal();
text::measure(buffer_from_editor(&internal.editor)) let (bounds, _has_rtl) =
text::measure(buffer_from_editor(&internal.editor));
bounds
} }
fn update( fn update(

View file

@ -18,7 +18,7 @@ struct Internal {
font: Font, font: Font,
shaping: Shaping, shaping: Shaping,
wrapping: Wrapping, wrapping: Wrapping,
horizontal_alignment: alignment::Horizontal, horizontal_alignment: Option<alignment::Horizontal>,
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
bounds: Size, bounds: Size,
min_bounds: Size, min_bounds: Size,
@ -89,7 +89,8 @@ impl core::text::Paragraph for Paragraph {
text::to_shaping(text.shaping), text::to_shaping(text.shaping),
); );
let min_bounds = text::measure(&buffer); let min_bounds =
align(&mut buffer, &mut font_system, text.horizontal_alignment);
Self(Arc::new(Internal { Self(Arc::new(Internal {
buffer, buffer,
@ -159,7 +160,8 @@ impl core::text::Paragraph for Paragraph {
None, None,
); );
let min_bounds = text::measure(&buffer); let min_bounds =
align(&mut buffer, &mut font_system, text.horizontal_alignment);
Self(Arc::new(Internal { Self(Arc::new(Internal {
buffer, buffer,
@ -186,8 +188,10 @@ impl core::text::Paragraph for Paragraph {
Some(new_bounds.height), Some(new_bounds.height),
); );
let (min_bounds, _has_rtl) = text::measure(&paragraph.buffer);
paragraph.bounds = new_bounds; paragraph.bounds = new_bounds;
paragraph.min_bounds = text::measure(&paragraph.buffer); paragraph.min_bounds = min_bounds;
} }
fn compare(&self, text: Text<()>) -> core::text::Difference { fn compare(&self, text: Text<()>) -> core::text::Difference {
@ -212,7 +216,7 @@ impl core::text::Paragraph for Paragraph {
} }
} }
fn horizontal_alignment(&self) -> alignment::Horizontal { fn horizontal_alignment(&self) -> Option<alignment::Horizontal> {
self.internal().horizontal_alignment self.internal().horizontal_alignment
} }
@ -354,6 +358,42 @@ impl core::text::Paragraph for Paragraph {
} }
} }
fn align(
buffer: &mut cosmic_text::Buffer,
font_system: &mut text::FontSystem,
align_x: Option<alignment::Horizontal>,
) -> Size {
let (min_bounds, has_rtl) = text::measure(buffer);
let mut needs_relayout = has_rtl;
if let Some(align_x) = align_x {
let has_multiple_lines = buffer.lines.len() > 1
|| buffer.lines.first().is_some_and(|line| {
line.layout_opt().is_some_and(|layout| layout.len() > 1)
});
if has_multiple_lines {
for line in &mut buffer.lines {
let _ = line.set_align(Some(text::to_align(align_x)));
}
needs_relayout = true;
}
}
if needs_relayout {
log::trace!("Relayouting paragraph...");
buffer.set_size(
font_system.raw(),
Some(min_bounds.width),
Some(min_bounds.height),
);
}
min_bounds
}
impl Default for Paragraph { impl Default for Paragraph {
fn default() -> Self { fn default() -> Self {
Self(Arc::new(Internal::default())) Self(Arc::new(Internal::default()))
@ -397,7 +437,7 @@ impl Default for Internal {
font: Font::default(), font: Font::default(),
shaping: Shaping::default(), shaping: Shaping::default(),
wrapping: Wrapping::default(), wrapping: Wrapping::default(),
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Top, vertical_alignment: alignment::Vertical::Top,
bounds: Size::ZERO, bounds: Size::ZERO,
min_bounds: Size::ZERO, min_bounds: Size::ZERO,
@ -413,7 +453,7 @@ pub struct Weak {
/// The minimum bounds of the [`Paragraph`]. /// The minimum bounds of the [`Paragraph`].
pub min_bounds: Size, pub min_bounds: Size,
/// The horizontal alignment of the [`Paragraph`]. /// The horizontal alignment of the [`Paragraph`].
pub horizontal_alignment: alignment::Horizontal, pub horizontal_alignment: Option<alignment::Horizontal>,
/// The vertical alignment of the [`Paragraph`]. /// The vertical alignment of the [`Paragraph`].
pub vertical_alignment: alignment::Vertical, pub vertical_alignment: alignment::Vertical,
} }

View file

@ -231,7 +231,7 @@ impl geometry::frame::Backend for Frame {
size, size,
line_height: line_height.to_absolute(size), line_height: line_height.to_absolute(size),
font: text.font, font: text.font,
horizontal_alignment: text.horizontal_alignment, horizontal_alignment: Some(text.horizontal_alignment),
vertical_alignment: text.vertical_alignment, vertical_alignment: text.vertical_alignment,
shaping: text.shaping, shaping: text.shaping,
clip_bounds: Rectangle::with_size(Size::INFINITY), clip_bounds: Rectangle::with_size(Size::INFINITY),

View file

@ -92,7 +92,7 @@ impl Pipeline {
editor.buffer(), editor.buffer(),
Rectangle::new(position, editor.bounds()), Rectangle::new(position, editor.bounds()),
color, color,
alignment::Horizontal::Left, None,
alignment::Vertical::Top, alignment::Vertical::Top,
pixels, pixels,
clip_mask, clip_mask,
@ -108,7 +108,7 @@ impl Pipeline {
size: Pixels, size: Pixels,
line_height: Pixels, line_height: Pixels,
font: Font, font: Font,
horizontal_alignment: alignment::Horizontal, horizontal_alignment: Option<alignment::Horizontal>,
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
shaping: Shaping, shaping: Shaping,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
@ -177,7 +177,7 @@ impl Pipeline {
), ),
), ),
color, color,
alignment::Horizontal::Left, None,
alignment::Vertical::Top, alignment::Vertical::Top,
pixels, pixels,
clip_mask, clip_mask,
@ -197,7 +197,7 @@ fn draw(
buffer: &cosmic_text::Buffer, buffer: &cosmic_text::Buffer,
bounds: Rectangle, bounds: Rectangle,
color: Color, color: Color,
horizontal_alignment: alignment::Horizontal, horizontal_alignment: Option<alignment::Horizontal>,
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::Mask>, clip_mask: Option<&tiny_skia::Mask>,
@ -206,9 +206,9 @@ fn draw(
let bounds = bounds * transformation; let bounds = bounds * transformation;
let x = match horizontal_alignment { let x = match horizontal_alignment {
alignment::Horizontal::Left => bounds.x, None | Some(alignment::Horizontal::Left) => bounds.x,
alignment::Horizontal::Center => bounds.x - bounds.width / 2.0, Some(alignment::Horizontal::Center) => bounds.x - bounds.width / 2.0,
alignment::Horizontal::Right => bounds.x - bounds.width, Some(alignment::Horizontal::Right) => bounds.x - bounds.width,
}; };
let y = match vertical_alignment { let y = match vertical_alignment {

View file

@ -336,7 +336,7 @@ impl geometry::frame::Backend for Frame {
size, size,
line_height: line_height.to_absolute(size), line_height: line_height.to_absolute(size),
font: text.font, font: text.font,
horizontal_alignment: text.horizontal_alignment, horizontal_alignment: Some(text.horizontal_alignment),
vertical_alignment: text.vertical_alignment, vertical_alignment: text.vertical_alignment,
shaping: text.shaping, shaping: text.shaping,
clip_bounds: self.clip_bounds, clip_bounds: self.clip_bounds,

View file

@ -417,7 +417,7 @@ impl Renderer {
size: Pixels(20.0), size: Pixels(20.0),
line_height: core::text::LineHeight::default(), line_height: core::text::LineHeight::default(),
font: Font::MONOSPACE, font: Font::MONOSPACE,
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Top, vertical_alignment: alignment::Vertical::Top,
shaping: core::text::Shaping::Basic, shaping: core::text::Shaping::Basic,
wrapping: core::text::Wrapping::Word, wrapping: core::text::Wrapping::Word,

View file

@ -540,7 +540,7 @@ fn prepare(
( (
editor.buffer(), editor.buffer(),
Rectangle::new(*position, editor.bounds()), Rectangle::new(*position, editor.bounds()),
alignment::Horizontal::Left, None,
alignment::Vertical::Top, alignment::Vertical::Top,
*color, *color,
*clip_bounds, *clip_bounds,
@ -591,7 +591,7 @@ fn prepare(
height.unwrap_or(layer_bounds.height), height.unwrap_or(layer_bounds.height),
), ),
), ),
alignment::Horizontal::Left, None,
alignment::Vertical::Top, alignment::Vertical::Top,
raw.color, raw.color,
raw.clip_bounds, raw.clip_bounds,
@ -603,9 +603,11 @@ fn prepare(
let bounds = bounds * transformation * layer_transformation; let bounds = bounds * transformation * layer_transformation;
let left = match horizontal_alignment { let left = match horizontal_alignment {
alignment::Horizontal::Left => bounds.x, None | Some(alignment::Horizontal::Left) => bounds.x,
alignment::Horizontal::Center => bounds.x - bounds.width / 2.0, Some(alignment::Horizontal::Center) => {
alignment::Horizontal::Right => bounds.x - bounds.width, bounds.x - bounds.width / 2.0
}
Some(alignment::Horizontal::Right) => bounds.x - bounds.width,
}; };
let top = match vertical_alignment { let top = match vertical_alignment {

View file

@ -293,7 +293,7 @@ where
self.text_line_height, self.text_line_height,
self.text_size, self.text_size,
self.font, self.font,
alignment::Horizontal::Left, None,
alignment::Vertical::Top, alignment::Vertical::Top,
self.text_shaping, self.text_shaping,
self.text_wrapping, self.text_wrapping,
@ -416,7 +416,9 @@ where
size, size,
line_height: *line_height, line_height: *line_height,
bounds: bounds.size(), bounds: bounds.size(),
horizontal_alignment: alignment::Horizontal::Center, horizontal_alignment: Some(
alignment::Horizontal::Center,
),
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping: *shaping, shaping: *shaping,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),

View file

@ -552,7 +552,7 @@ where
size: text_size, size: text_size,
line_height: self.text_line_height, line_height: self.text_line_height,
font: self.font.unwrap_or_else(|| renderer.default_font()), font: self.font.unwrap_or_else(|| renderer.default_font()),
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping: self.text_shaping, shaping: self.text_shaping,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),

View file

@ -371,7 +371,7 @@ where
size: text_size, size: text_size,
line_height: self.text_line_height, line_height: self.text_line_height,
font, font,
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping: self.text_shaping, shaping: self.text_shaping,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),
@ -639,7 +639,7 @@ where
bounds.width, bounds.width,
f32::from(line_height.to_absolute(size)), f32::from(line_height.to_absolute(size)),
), ),
horizontal_alignment: alignment::Horizontal::Right, horizontal_alignment: Some(alignment::Horizontal::Right),
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping, shaping,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),
@ -669,7 +669,7 @@ where
bounds.width - self.padding.horizontal(), bounds.width - self.padding.horizontal(),
f32::from(self.text_line_height.to_absolute(text_size)), f32::from(self.text_line_height.to_absolute(text_size)),
), ),
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping: self.text_shaping, shaping: self.text_shaping,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),

View file

@ -314,7 +314,7 @@ where
self.text_line_height, self.text_line_height,
self.text_size, self.text_size,
self.font, self.font,
alignment::Horizontal::Left, None,
alignment::Vertical::Top, alignment::Vertical::Top,
self.text_shaping, self.text_shaping,
self.text_wrapping, self.text_wrapping,

View file

@ -31,7 +31,7 @@ pub struct Rich<
width: Length, width: Length,
height: Length, height: Length,
font: Option<Renderer::Font>, font: Option<Renderer::Font>,
align_x: alignment::Horizontal, align_x: Option<alignment::Horizontal>,
align_y: alignment::Vertical, align_y: alignment::Vertical,
wrapping: Wrapping, wrapping: Wrapping,
class: Theme::Class<'a>, class: Theme::Class<'a>,
@ -56,7 +56,7 @@ where
width: Length::Shrink, width: Length::Shrink,
height: Length::Shrink, height: Length::Shrink,
font: None, font: None,
align_x: alignment::Horizontal::Left, align_x: None,
align_y: alignment::Vertical::Top, align_y: alignment::Vertical::Top,
wrapping: Wrapping::default(), wrapping: Wrapping::default(),
class: Theme::default(), class: Theme::default(),
@ -116,7 +116,7 @@ where
mut self, mut self,
alignment: impl Into<alignment::Horizontal>, alignment: impl Into<alignment::Horizontal>,
) -> Self { ) -> Self {
self.align_x = alignment.into(); self.align_x = Some(alignment.into());
self self
} }
@ -476,7 +476,7 @@ fn layout<Link, Renderer>(
line_height: LineHeight, line_height: LineHeight,
size: Option<Pixels>, size: Option<Pixels>,
font: Option<Renderer::Font>, font: Option<Renderer::Font>,
horizontal_alignment: alignment::Horizontal, horizontal_alignment: Option<alignment::Horizontal>,
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
wrapping: Wrapping, wrapping: Wrapping,
) -> layout::Node ) -> layout::Node

View file

@ -955,7 +955,7 @@ where
.unwrap_or_else(|| renderer.default_size()), .unwrap_or_else(|| renderer.default_size()),
line_height: self.line_height, line_height: self.line_height,
font, font,
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Top, vertical_alignment: alignment::Vertical::Top,
shaping: text::Shaping::Advanced, shaping: text::Shaping::Advanced,
wrapping: self.wrapping, wrapping: self.wrapping,

View file

@ -319,7 +319,7 @@ where
content: self.placeholder.as_str(), content: self.placeholder.as_str(),
bounds: Size::new(f32::INFINITY, text_bounds.height), bounds: Size::new(f32::INFINITY, text_bounds.height),
size: text_size, size: text_size,
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping: text::Shaping::Advanced, shaping: text::Shaping::Advanced,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),
@ -344,7 +344,7 @@ where
font: icon.font, font: icon.font,
size: icon.size.unwrap_or_else(|| renderer.default_size()), size: icon.size.unwrap_or_else(|| renderer.default_size()),
bounds: Size::new(f32::INFINITY, text_bounds.height), bounds: Size::new(f32::INFINITY, text_bounds.height),
horizontal_alignment: alignment::Horizontal::Center, horizontal_alignment: Some(alignment::Horizontal::Center),
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping: text::Shaping::Advanced, shaping: text::Shaping::Advanced,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),
@ -1727,7 +1727,7 @@ fn replace_paragraph<Renderer>(
content: &value.to_string(), content: &value.to_string(),
bounds: Size::new(f32::INFINITY, text_bounds.height), bounds: Size::new(f32::INFINITY, text_bounds.height),
size: text_size, size: text_size,
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
shaping: text::Shaping::Advanced, shaping: text::Shaping::Advanced,
wrapping: text::Wrapping::default(), wrapping: text::Wrapping::default(),

View file

@ -93,7 +93,7 @@ pub struct Toggler<
size: f32, size: f32,
text_size: Option<Pixels>, text_size: Option<Pixels>,
text_line_height: text::LineHeight, text_line_height: text::LineHeight,
text_alignment: alignment::Horizontal, text_alignment: Option<alignment::Horizontal>,
text_shaping: text::Shaping, text_shaping: text::Shaping,
text_wrapping: text::Wrapping, text_wrapping: text::Wrapping,
spacing: f32, spacing: f32,
@ -127,7 +127,7 @@ where
size: Self::DEFAULT_SIZE, size: Self::DEFAULT_SIZE,
text_size: None, text_size: None,
text_line_height: text::LineHeight::default(), text_line_height: text::LineHeight::default(),
text_alignment: alignment::Horizontal::Left, text_alignment: None,
text_shaping: text::Shaping::default(), text_shaping: text::Shaping::default(),
text_wrapping: text::Wrapping::default(), text_wrapping: text::Wrapping::default(),
spacing: Self::DEFAULT_SIZE / 2.0, spacing: Self::DEFAULT_SIZE / 2.0,
@ -195,8 +195,11 @@ where
} }
/// Sets the horizontal alignment of the text of the [`Toggler`] /// Sets the horizontal alignment of the text of the [`Toggler`]
pub fn text_alignment(mut self, alignment: alignment::Horizontal) -> Self { pub fn text_alignment(
self.text_alignment = alignment; mut self,
alignment: impl Into<alignment::Horizontal>,
) -> Self {
self.text_alignment = Some(alignment.into());
self self
} }

View file

@ -338,7 +338,7 @@ where
.unwrap_or_else(|| renderer.default_size()), .unwrap_or_else(|| renderer.default_size()),
line_height: text::LineHeight::default(), line_height: text::LineHeight::default(),
font: renderer.default_font(), font: renderer.default_font(),
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: None,
vertical_alignment: alignment::Vertical::Top, vertical_alignment: alignment::Vertical::Top,
shaping: text::Shaping::Advanced, shaping: text::Shaping::Advanced,
wrapping: text::Wrapping::None, wrapping: text::Wrapping::None,