Skip to main content

qframe/widgets/file_manager/
mark.rs

1//! What an application says about the look of one row of a [`FileManager`](super::FileManager).
2//!
3//! The manager knows names and folders; what an entry *means* to the application it cannot know.
4//! A mark is how the application says it: a sign with a tone, a faint row, or both.
5
6/// How one row of a file manager looks, beyond what the manager itself knows.
7///
8/// An application marks a row to say something about the entry the manager cannot know: that a
9/// backup leaves it out, that it is ignored by a version control system, that it has not been
10/// saved. Give one with [`FileManager::row_mark`](super::FileManager::row_mark).
11///
12/// A tone never comes on its own: [`sign`](Self::sign) takes the icon and the colour together, so
13/// a marked row is still told apart where colours are off or cannot be told apart.
14///
15/// ```
16/// use qframe::widgets::RowMark;
17///
18/// // An entry the backup leaves out: a warning sign, and the row faint.
19/// let left_out = RowMark::new().sign("warning", "warning").faint(true);
20/// assert_eq!(left_out.icon(), Some("warning"));
21/// assert_eq!(left_out.tone(), Some("warning"));
22/// assert!(left_out.is_faint());
23///
24/// // Faintness alone needs no sign: nothing is being said in colour.
25/// let quiet = RowMark::new().faint(true);
26/// assert_eq!(quiet.icon(), None);
27/// ```
28#[derive(Debug, Clone, Default, PartialEq, Eq)]
29pub struct RowMark {
30    icon: Option<String>,
31    tone: Option<String>,
32    faint: bool,
33}
34
35impl RowMark {
36    /// A mark that says nothing yet.
37    #[must_use]
38    pub fn new() -> Self {
39        Self::default()
40    }
41
42    /// The row's icon becomes `icon` in the colour `tone`, both of the icon set and the theme:
43    /// `"warning"`, `"danger"`, `"success"` and the rest of the theme's own tokens.
44    ///
45    /// The two come together on purpose: a colour alone says nothing to a person who cannot tell
46    /// it from another, and says nothing at all in the sixteen-colour or the ASCII mode.
47    #[must_use]
48    pub fn sign(mut self, icon: impl Into<String>, tone: impl Into<String>) -> Self {
49        self.icon = Some(icon.into());
50        self.tone = Some(tone.into());
51        self
52    }
53
54    /// Draws the row faint, the way a cut entry is drawn: there, but not what the eye goes to.
55    #[must_use]
56    pub fn faint(mut self, faint: bool) -> Self {
57        self.faint = faint;
58        self
59    }
60
61    /// The icon of the mark's sign, when it has one.
62    #[must_use]
63    pub fn icon(&self) -> Option<&str> {
64        self.icon.as_deref()
65    }
66
67    /// The colour of the mark's sign, when it has one.
68    #[must_use]
69    pub fn tone(&self) -> Option<&str> {
70        self.tone.as_deref()
71    }
72
73    /// Whether the row is drawn faint.
74    #[must_use]
75    pub fn is_faint(&self) -> bool {
76        self.faint
77    }
78
79    /// Whether the mark says nothing at all, so a row that has one looks like a row that has none.
80    #[must_use]
81    pub fn is_empty(&self) -> bool {
82        self.icon.is_none() && self.tone.is_none() && !self.faint
83    }
84}