summaryrefslogtreecommitdiffstats
path: root/graphics/src/text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/text.rs')
-rw-r--r--graphics/src/text.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/graphics/src/text.rs b/graphics/src/text.rs
index 30269e69..feb9932a 100644
--- a/graphics/src/text.rs
+++ b/graphics/src/text.rs
@@ -11,7 +11,7 @@ pub use cosmic_text;
use crate::core::alignment;
use crate::core::font::{self, Font};
-use crate::core::text::Shaping;
+use crate::core::text::{Shaping, Wrapping};
use crate::core::{Color, Pixels, Point, Rectangle, Size, Transformation};
use once_cell::sync::OnceCell;
@@ -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`].
@@ -305,6 +306,16 @@ pub fn to_shaping(shaping: Shaping) -> cosmic_text::Shaping {
}
}
+/// Converts some [`Wrapping`] strategy to a [`cosmic_text::Wrap`] strategy.
+pub fn to_wrap(wrapping: Wrapping) -> cosmic_text::Wrap {
+ match wrapping {
+ Wrapping::None => cosmic_text::Wrap::None,
+ Wrapping::Word => cosmic_text::Wrap::Word,
+ Wrapping::Glyph => cosmic_text::Wrap::Glyph,
+ Wrapping::WordOrGlyph => cosmic_text::Wrap::WordOrGlyph,
+ }
+}
+
/// Converts some [`Color`] to a [`cosmic_text::Color`].
pub fn to_color(color: Color) -> cosmic_text::Color {
let [r, g, b, a] = color.into_rgba8();