summaryrefslogtreecommitdiffstats
path: root/core/src/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-05 06:38:33 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-05 06:38:33 +0200
commit7ae549aba8b5f651a6e7b1a84ddd48288b77f50c (patch)
tree54074dd8b1fc17d63ad92d84b6d2b4415ad29df6 /core/src/widget
parent8e8808f0e187ed6671441f5016f07bfcba426452 (diff)
parent9499a8f9e6f9971dedfae563cb133232aa3cebc2 (diff)
downloadiced-7ae549aba8b5f651a6e7b1a84ddd48288b77f50c.tar.gz
iced-7ae549aba8b5f651a6e7b1a84ddd48288b77f50c.tar.bz2
iced-7ae549aba8b5f651a6e7b1a84ddd48288b77f50c.zip
Merge pull request #1828 from iced-rs/feature/line-height
Support configurable `LineHeight` in text widgets
Diffstat (limited to 'core/src/widget')
-rw-r--r--core/src/widget/text.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/core/src/widget/text.rs b/core/src/widget/text.rs
index f0392168..2d86e735 100644
--- a/core/src/widget/text.rs
+++ b/core/src/widget/text.rs
@@ -19,6 +19,7 @@ where
{
content: Cow<'a, str>,
size: Option<f32>,
+ line_height: text::LineHeight,
width: Length,
height: Length,
horizontal_alignment: alignment::Horizontal,
@@ -38,6 +39,7 @@ where
Text {
content: content.into(),
size: None,
+ line_height: text::LineHeight::default(),
font: None,
width: Length::Shrink,
height: Length::Shrink,
@@ -54,6 +56,15 @@ where
self
}
+ /// Sets the [`LineHeight`] of the [`Text`].
+ pub fn line_height(
+ mut self,
+ line_height: impl Into<text::LineHeight>,
+ ) -> Self {
+ self.line_height = line_height.into();
+ self
+ }
+
/// Sets the [`Font`] of the [`Text`].
///
/// [`Font`]: crate::text::Renderer::Font
@@ -135,6 +146,7 @@ where
let (width, height) = renderer.measure(
&self.content,
size,
+ self.line_height,
self.font.unwrap_or_else(|| renderer.default_font()),
bounds,
self.shaping,
@@ -161,6 +173,7 @@ where
layout,
&self.content,
self.size,
+ self.line_height,
self.font,
theme.appearance(self.style.clone()),
self.horizontal_alignment,
@@ -186,6 +199,7 @@ pub fn draw<Renderer>(
layout: Layout<'_>,
content: &str,
size: Option<f32>,
+ line_height: text::LineHeight,
font: Option<Renderer::Font>,
appearance: Appearance,
horizontal_alignment: alignment::Horizontal,
@@ -208,9 +222,12 @@ pub fn draw<Renderer>(
alignment::Vertical::Bottom => bounds.y + bounds.height,
};
+ let size = size.unwrap_or_else(|| renderer.default_size());
+
renderer.fill_text(crate::Text {
content,
- size: size.unwrap_or_else(|| renderer.default_size()),
+ size,
+ line_height,
bounds: Rectangle { x, y, ..bounds },
color: appearance.color.unwrap_or(style.text_color),
font: font.unwrap_or_else(|| renderer.default_font()),
@@ -240,6 +257,7 @@ where
Self {
content: self.content.clone(),
size: self.size,
+ line_height: self.line_height,
width: self.width,
height: self.height,
horizontal_alignment: self.horizontal_alignment,