summaryrefslogtreecommitdiffstats
path: root/graphics/src/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-17 22:04:11 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-17 22:04:11 +0200
commit910eb72a0620b34e5b3d7793bbd5ab7290e08dd6 (patch)
tree0a0940d56a9bc4147b7ef06fe9fb5099c761090a /graphics/src/text.rs
parentffb520fb3703ce4ece9fb6d5ee2c7aa0b846879f (diff)
downloadiced-910eb72a0620b34e5b3d7793bbd5ab7290e08dd6.tar.gz
iced-910eb72a0620b34e5b3d7793bbd5ab7290e08dd6.tar.bz2
iced-910eb72a0620b34e5b3d7793bbd5ab7290e08dd6.zip
Implement `rich_text` widget and `markdown` example
Diffstat (limited to '')
-rw-r--r--graphics/src/text.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/graphics/src/text.rs b/graphics/src/text.rs
index 30269e69..23ec14d4 100644
--- a/graphics/src/text.rs
+++ b/graphics/src/text.rs
@@ -232,13 +232,14 @@ impl PartialEq for Raw {
/// Measures the dimensions of the given [`cosmic_text::Buffer`].
pub fn measure(buffer: &cosmic_text::Buffer) -> Size {
- let (width, total_lines) = buffer
- .layout_runs()
- .fold((0.0, 0usize), |(width, total_lines), run| {
- (run.line_w.max(width), total_lines + 1)
- });
+ let (width, height) =
+ buffer
+ .layout_runs()
+ .fold((0.0, 0.0), |(width, height), run| {
+ (run.line_w.max(width), height + run.line_height)
+ });
- Size::new(width, total_lines as f32 * buffer.metrics().line_height)
+ Size::new(width, height)
}
/// Returns the attributes of the given [`Font`].