Skip to content

Commit

Permalink
Refactor the settings module (#739)
Browse files Browse the repository at this point in the history
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
CryZe authored Nov 11, 2023
1 parent fb17a18 commit e127cdc
Show file tree
Hide file tree
Showing 10 changed files with 585 additions and 342 deletions.
8 changes: 4 additions & 4 deletions crates/livesplit-auto-splitting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ extern "C" {
/// to free it.
pub fn settings_list_push(list: SettingsList, value: SettingValue);
/// Inserts a copy of the setting value into the settings list at the index
/// given. If the index is out of bounds, the setting value is pushed to the
/// end of the settings list. You still retain ownership of the setting
/// value, which means you still need to free it.
pub fn settings_list_insert(list: SettingsList, idx: u64, value: SettingValue);
/// given. Returns `false` if the index is out of bounds. No matter what
/// happens, you still retain ownership of the setting value, which means
/// you still need to free it.
pub fn settings_list_insert(list: SettingsList, idx: u64, value: SettingValue) -> bool;

/// Creates a new setting value from a settings map. The value is a copy of
/// the settings map. Any changes to the original settings map afterwards
Expand Down
11 changes: 5 additions & 6 deletions crates/livesplit-auto-splitting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@
//! /// to free it.
//! pub fn settings_list_push(list: SettingsList, value: SettingValue);
//! /// Inserts a copy of the setting value into the settings list at the index
//! /// given. If the index is out of bounds, the setting value is pushed to the
//! /// end of the settings list. You still retain ownership of the setting
//! /// value, which means you still need to free it.
//! pub fn settings_list_insert(list: SettingsList, idx: u64, value: SettingValue);
//! /// given. Returns `false` if the index is out of bounds. No matter what
//! /// happens, you still retain ownership of the setting value, which means
//! /// you still need to free it.
//! pub fn settings_list_insert(list: SettingsList, idx: u64, value: SettingValue) -> bool;
//!
//! /// Creates a new setting value from a settings map. The value is a copy of
//! /// the settings map. Any changes to the original settings map afterwards
Expand Down Expand Up @@ -452,11 +452,10 @@

mod process;
mod runtime;
mod settings;
pub mod settings;
mod timer;

pub use process::Process;
pub use runtime::{Config, CreationError, InterruptHandle, Runtime, RuntimeGuard};
pub use settings::{SettingValue, SettingsList, SettingsMap, UserSetting, UserSettingKind};
pub use time;
pub use timer::{Timer, TimerState};
127 changes: 66 additions & 61 deletions crates/livesplit-auto-splitting/src/runtime.rs

Large diffs are not rendered by default.

249 changes: 0 additions & 249 deletions crates/livesplit-auto-splitting/src/settings.rs

This file was deleted.

38 changes: 38 additions & 0 deletions crates/livesplit-auto-splitting/src/settings/gui.rs
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,
},
}
Loading

0 comments on commit e127cdc

Please sign in to comment.