Skip to main content

freya_core/style/
text_overflow.rs

1/// How text that does not fit its bounds is truncated.
2#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3#[derive(Default, Clone, Debug, PartialEq, Hash)]
4pub enum TextOverflow {
5    /// Cut the text off at the edge. This is the default.
6    #[default]
7    Clip,
8    /// Replace the cut-off text with an ellipsis (`…`).
9    Ellipsis,
10    /// Replace the cut-off text with a custom string.
11    Custom(String),
12}
13
14impl TextOverflow {
15    pub fn get_ellipsis(&self) -> Option<&str> {
16        match self {
17            Self::Clip => None,
18            Self::Ellipsis => Some("…"),
19            Self::Custom(custom) => Some(custom),
20        }
21    }
22
23    pub fn pretty(&self) -> String {
24        match self {
25            TextOverflow::Clip => "clip".to_string(),
26            TextOverflow::Ellipsis => "ellipsis".to_string(),
27            TextOverflow::Custom(text_overflow) => text_overflow.to_string(),
28        }
29    }
30}