diff --git a/xilem/src/lib.rs b/xilem/src/lib.rs index 54e4e28c9..9972a80fe 100644 --- a/xilem/src/lib.rs +++ b/xilem/src/lib.rs @@ -53,6 +53,7 @@ use crate::core::{ ViewPathTracker, ViewSequence, }; pub use masonry::event_loop_runner::{EventLoop, EventLoopBuilder}; +pub use masonry::widget::LineBreaking; pub use masonry::{dpi, palette, Affine, Color, FontWeight, TextAlignment, Vec2}; pub use xilem_core as core; diff --git a/xilem/src/view/label.rs b/xilem/src/view/label.rs index caf921398..ee6705d4d 100644 --- a/xilem/src/view/label.rs +++ b/xilem/src/view/label.rs @@ -3,7 +3,7 @@ use masonry::parley::style::{FontStack, FontWeight}; use masonry::text::{ArcStr, StyleProperty}; -use masonry::widget; +use masonry::widget::{self, LineBreaking}; use vello::peniko::Brush; use crate::core::{DynMessage, Mut, ViewMarker}; @@ -19,6 +19,7 @@ pub fn label(label: impl Into) -> Label { text_size: masonry::theme::TEXT_SIZE_NORMAL, weight: FontWeight::NORMAL, font: FontStack::List(std::borrow::Cow::Borrowed(&[])), + line_break_mode: LineBreaking::Overflow, transform: Affine::IDENTITY, } } @@ -30,7 +31,8 @@ pub struct Label { alignment: TextAlignment, text_size: f32, weight: FontWeight, - font: FontStack<'static>, // TODO: add more attributes of `masonry::widget::Label` + font: FontStack<'static>, + line_break_mode: LineBreaking, // TODO: add more attributes of `masonry::widget::Label` transform: Affine, } @@ -65,6 +67,12 @@ impl Label { self.font = font.into(); self } + + /// Set how line breaks will be handled by this label (i.e. if there is insufficient horizontal space). + pub fn line_break_mode(mut self, line_break_mode: LineBreaking) -> Self { + self.line_break_mode = line_break_mode; + self + } } impl Transformable for Label { @@ -94,7 +102,8 @@ impl View for Label { .with_alignment(self.alignment) .with_style(StyleProperty::FontSize(self.text_size)) .with_style(StyleProperty::FontWeight(self.weight)) - .with_style(StyleProperty::FontStack(self.font.clone())), + .with_style(StyleProperty::FontStack(self.font.clone())) + .with_line_break_mode(self.line_break_mode), self.transform, ); (widget_pod, ()) @@ -128,6 +137,9 @@ impl View for Label { if prev.font != self.font { widget::Label::insert_style(&mut element, StyleProperty::FontStack(self.font.clone())); } + if prev.line_break_mode != self.line_break_mode { + widget::Label::set_line_break_mode(&mut element, self.line_break_mode); + } } fn teardown(&self, (): &mut Self::ViewState, _: &mut ViewCtx, _: Mut) {}