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/// [`plain_sign`](Self::plain_sign) changes only the shape and leaves the colour to the row.
15///
16/// ```
17/// use qframe::widgets::RowMark;
18///
19/// // An entry the backup leaves out: a warning sign, and the row faint.
20/// let left_out = RowMark::new().sign("warning", "warning").faint(true);
21/// assert_eq!(left_out.icon(), Some("warning"));
22/// assert_eq!(left_out.tone(), Some("warning"));
23/// assert!(left_out.is_faint());
24///
25/// // Faintness alone needs no sign: nothing is being said in colour.
26/// let quiet = RowMark::new().faint(true);
27/// assert_eq!(quiet.icon(), None);
28/// ```
29#[derive(Debug, Clone, Default, PartialEq, Eq)]
30pub struct RowMark {
31 icon: Option<String>,
32 tone: Option<String>,
33 faint: bool,
34}
35
36impl RowMark {
37 /// A mark that says nothing yet.
38 #[must_use]
39 pub fn new() -> Self {
40 Self::default()
41 }
42
43 /// The row's icon becomes `icon` in the colour `tone`, both of the icon set and the theme:
44 /// `"warning"`, `"danger"`, `"success"` and the rest of the theme's own tokens.
45 ///
46 /// The two come together on purpose: a colour alone says nothing to a person who cannot tell
47 /// it from another, and says nothing at all in the sixteen-colour or the ASCII mode.
48 #[must_use]
49 pub fn sign(mut self, icon: impl Into<String>, tone: impl Into<String>) -> Self {
50 self.icon = Some(icon.into());
51 self.tone = Some(tone.into());
52 self
53 }
54
55 /// The row's icon becomes `icon` in the row's own colour, so it rests, rises and takes the
56 /// selection with the name beside it: a different shape for a row that is not saying anything
57 /// in colour, such as the root of a workspace.
58 #[must_use]
59 pub fn plain_sign(mut self, icon: impl Into<String>) -> Self {
60 self.icon = Some(icon.into());
61 self.tone = None;
62 self
63 }
64
65 /// Draws the row faint, the way a cut entry is drawn: there, but not what the eye goes to.
66 #[must_use]
67 pub fn faint(mut self, faint: bool) -> Self {
68 self.faint = faint;
69 self
70 }
71
72 /// The icon of the mark's sign, when it has one.
73 #[must_use]
74 pub fn icon(&self) -> Option<&str> {
75 self.icon.as_deref()
76 }
77
78 /// The colour of the mark's sign, when it has one.
79 #[must_use]
80 pub fn tone(&self) -> Option<&str> {
81 self.tone.as_deref()
82 }
83
84 /// Whether the row is drawn faint.
85 #[must_use]
86 pub fn is_faint(&self) -> bool {
87 self.faint
88 }
89
90 /// Whether the mark says nothing at all, so a row that has one looks like a row that has none.
91 #[must_use]
92 pub fn is_empty(&self) -> bool {
93 self.icon.is_none() && self.tone.is_none() && !self.faint
94 }
95}