Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow wrapping Widgets in Pair #78

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:

steps:
- name: Checkout Commit
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Rust
uses: hecrj/setup-rust-action@v1
uses: hecrj/setup-rust-action@v2
with:
rust-version: ${{ matrix.toolchain || 'stable' }}

Expand Down Expand Up @@ -67,10 +67,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Commit
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Rust
uses: hecrj/setup-rust-action@v1
uses: hecrj/setup-rust-action@v2
with:
components: clippy

Expand All @@ -82,10 +82,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Commit
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Rust
uses: hecrj/setup-rust-action@v1
uses: hecrj/setup-rust-action@v2
with:
components: rustfmt

Expand Down
23 changes: 19 additions & 4 deletions src/runtime/settings/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[cfg(feature = "derive")]
pub use asr_derive::Gui;

use crate::runtime::sys;
use crate::{runtime::sys, watcher::Pair};

use super::map::Map;

Expand Down Expand Up @@ -78,9 +78,7 @@ pub trait Gui {
fn update_from(&mut self, settings_map: &Map);
}

/// A settings widget that can be added to the settings GUI. This is an internal
/// trait that you don't need to worry about.
#[doc(hidden)]
/// A settings widget that can be used as a field when defining a settings [`Gui`].
pub trait Widget {
/// The arguments that are needed to register the widget.
type Args: Default;
Expand Down Expand Up @@ -146,3 +144,20 @@ impl Widget for Title {
#[inline]
fn update_from(&mut self, _settings_map: &Map, _key: &str, _args: Self::Args) {}
}

impl<T: Copy + Widget> Widget for Pair<T> {
type Args = T::Args;

fn register(key: &str, description: &str, args: Self::Args) -> Self {
let value = T::register(key, description, args);
Pair {
old: value,
current: value,
}
}

fn update_from(&mut self, settings_map: &Map, key: &str, args: Self::Args) {
self.old = self.current;
self.current.update_from(settings_map, key, args);
}
}
Loading