Skip to main content

takumi_css/style/properties/
word_break.rs

1use crate::style::declare_enum_from_css_impl;
2
3/// Controls how text should be broken at word boundaries.
4///
5/// Corresponds to CSS word-break property.
6#[derive(Debug, Default, Copy, Clone, PartialEq)]
7#[non_exhaustive]
8pub enum WordBreak {
9  /// Normal line breaking behavior—lines may break according to language rules.
10  #[default]
11  Normal,
12  /// Break words at arbitrary points to prevent overflow.
13  BreakAll,
14  /// Prevents word breaks within words. Useful for languages like Japanese.
15  KeepAll,
16  /// Allow breaking within long words if necessary to prevent overflow.
17  BreakWord,
18}
19
20declare_enum_from_css_impl!(
21  WordBreak,
22  "normal" => WordBreak::Normal,
23  "break-all" => WordBreak::BreakAll,
24  "keep-all" => WordBreak::KeepAll,
25  "break-word" => WordBreak::BreakWord,
26);
27
28impl From<WordBreak> for parley::WordBreak {
29  fn from(value: WordBreak) -> Self {
30    match value {
31      WordBreak::Normal | WordBreak::BreakWord => parley::WordBreak::Normal,
32      WordBreak::BreakAll => parley::WordBreak::BreakAll,
33      WordBreak::KeepAll => parley::WordBreak::KeepAll,
34    }
35  }
36}