-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This refactors the settings module into individual files for each type. Additionally this adds tests and also changes the list insert function to return an error if the index was out of bounds instead of inserting at the back.
- Loading branch information
Showing
10 changed files
with
585 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::sync::Arc; | ||
|
||
/// A setting widget that is meant to be shown to and modified by the user. | ||
#[non_exhaustive] | ||
#[derive(Clone)] | ||
pub struct Widget { | ||
/// A unique identifier for this setting. This is not meant to be shown to | ||
/// the user and is only used to keep track of the setting. This key is used | ||
/// to store and retrieve the value of the setting from the main settings | ||
/// [`Map`](super::Map). | ||
pub key: Arc<str>, | ||
/// The name of the setting that is shown to the user. | ||
pub description: Arc<str>, | ||
/// An optional tooltip that is shown to the user when hovering over the | ||
/// widget. | ||
pub tooltip: Option<Arc<str>>, | ||
/// The type of widget and additional information about it. | ||
pub kind: WidgetKind, | ||
} | ||
|
||
/// The type of a [`Widget`] and additional information about it. | ||
#[derive(Clone)] | ||
pub enum WidgetKind { | ||
/// A title that is shown to the user. It doesn't by itself store a value | ||
/// and is instead used to group settings together. | ||
Title { | ||
/// The heading level of the title. This is used to determine the size | ||
/// of the title and which other settings are grouped together with it. | ||
/// The top level titles use a heading level of 0. | ||
heading_level: u32, | ||
}, | ||
/// A boolean setting. This could be shown as a checkbox or a toggle. | ||
Bool { | ||
/// The default value of the setting, if it's not available in the | ||
/// settings [`Map`](super::Map) yet. | ||
default_value: bool, | ||
}, | ||
} |
Oops, something went wrong.