Skip to main content

freya_core/style/
cursor.rs

1/// Shape of the text cursor drawn in a [`paragraph`](crate::elements::paragraph).
2#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq)]
4pub enum CursorStyle {
5    /// A thin vertical line between glyphs. This is the default.
6    #[default]
7    Line = 0,
8    /// A filled block covering the glyph.
9    Block = 1,
10    /// A line under the glyph.
11    Underline = 2,
12}
13
14impl CursorStyle {
15    pub fn pretty(&self) -> String {
16        match self {
17            Self::Line => "line".to_string(),
18            Self::Block => "block".to_string(),
19            Self::Underline => "underline".to_string(),
20        }
21    }
22}
23
24/// Determines how the cursor and highlights are positioned within a Paragraph.
25#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
27pub enum CursorMode {
28    /// Cursor and highlights use the paragraph's visible_area.
29    /// VerticalAlign affects cursor/highlight positions.
30    #[default]
31    Fit,
32    /// Cursor and highlights use the paragraph's inner_area.
33    /// VerticalAlign does NOT affect cursor/highlight positions.
34    Expanded,
35}
36
37impl CursorMode {
38    pub fn pretty(&self) -> String {
39        match self {
40            Self::Fit => "fit".to_string(),
41            Self::Expanded => "expanded".to_string(),
42        }
43    }
44}