Skip to content

Commit f90a7c0

Browse files
committed
Word wrapping can now be added and read from attributes
1 parent 15e972d commit f90a7c0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

anathema-widgets/src/layout/text.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ impl TryFrom<&ValueKind<'_>> for Wrap {
3838
}
3939
}
4040

41+
impl From<Wrap> for ValueKind<'_> {
42+
fn from(value: Wrap) -> Self {
43+
let value = match value {
44+
Wrap::Normal => "normal",
45+
Wrap::WordBreak => "break"
46+
};
47+
48+
ValueKind::Str(value.into())
49+
}
50+
}
51+
4152
#[derive(Debug)]
4253
pub(crate) struct LineWidth(usize);
4354

@@ -510,4 +521,17 @@ mod test {
510521
fn limited_space() {
511522
test_layout(Size::new(58, 0), &["meh"], "", Wrap::Normal);
512523
}
524+
525+
#[test]
526+
fn wrap_from_attribute() {
527+
let mut attributes = anathema_value_resolver::Attributes::empty();
528+
529+
attributes.set("break", Wrap::WordBreak);
530+
let word_break = attributes.get_as::<Wrap>("break").unwrap();
531+
assert_eq!(word_break, Wrap::WordBreak);
532+
533+
attributes.set("normal", Wrap::Normal);
534+
let word_break = attributes.get_as::<Wrap>("normal").unwrap();
535+
assert_eq!(word_break, Wrap::Normal);
536+
}
513537
}

0 commit comments

Comments
 (0)