mirror of
https://github.com/danbulant/cushy
synced 2026-06-20 15:01:11 +00:00
Lerp for ThemeMode
This commit is contained in:
parent
27d5baef5d
commit
019412543c
2 changed files with 32 additions and 12 deletions
|
|
@ -72,18 +72,11 @@ fn main() -> gooey::Result {
|
|||
}
|
||||
|
||||
fn dark_mode_slider() -> (Dynamic<ThemeMode>, impl MakeWidget) {
|
||||
let on_off = Dynamic::new(true);
|
||||
let theme_mode = on_off.map_each(|dark| {
|
||||
if *dark {
|
||||
ThemeMode::Dark
|
||||
} else {
|
||||
ThemeMode::Light
|
||||
}
|
||||
});
|
||||
let theme_mode = Dynamic::default();
|
||||
|
||||
(
|
||||
theme_mode,
|
||||
Stack::rows(Label::new("Theme Mode").and(Slider::<bool>::from_value(on_off))),
|
||||
theme_mode.clone(),
|
||||
Stack::rows(Label::new("Theme Mode").and(Slider::<ThemeMode>::from_value(theme_mode))),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,13 @@ use kludgine::app::winit::keyboard::Key;
|
|||
use kludgine::app::winit::window;
|
||||
use kludgine::app::WindowBehavior as _;
|
||||
use kludgine::figures::units::{Px, UPx};
|
||||
use kludgine::figures::{IntoSigned, IntoUnsigned, Point, Rect, ScreenScale, Size};
|
||||
use kludgine::figures::{IntoSigned, IntoUnsigned, Point, Ranged, Rect, ScreenScale, Size};
|
||||
use kludgine::render::Drawing;
|
||||
use kludgine::wgpu::CompositeAlphaMode;
|
||||
use kludgine::Kludgine;
|
||||
use tracing::Level;
|
||||
|
||||
use crate::animation::{LinearInterpolate, PercentBetween, ZeroToOne};
|
||||
use crate::context::{
|
||||
AsEventContext, EventContext, Exclusive, GraphicsContext, LayoutContext, RedrawStatus,
|
||||
WidgetContext,
|
||||
|
|
@ -1057,11 +1058,12 @@ pub(crate) mod sealed {
|
|||
}
|
||||
|
||||
/// Controls whether the light or dark theme is applied.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
|
||||
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum ThemeMode {
|
||||
/// Applies the light theme
|
||||
Light,
|
||||
/// Applies the dark theme
|
||||
#[default]
|
||||
Dark,
|
||||
}
|
||||
|
||||
|
|
@ -1082,3 +1084,28 @@ impl From<ThemeMode> for window::Theme {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LinearInterpolate for ThemeMode {
|
||||
fn lerp(&self, target: &Self, percent: f32) -> Self {
|
||||
if percent >= 0.5 {
|
||||
*target
|
||||
} else {
|
||||
*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PercentBetween for ThemeMode {
|
||||
fn percent_between(&self, min: &Self, max: &Self) -> ZeroToOne {
|
||||
if *min == *max || *self == *min {
|
||||
ZeroToOne::ZERO
|
||||
} else {
|
||||
ZeroToOne::ONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for ThemeMode {
|
||||
const MAX: Self = Self::Dark;
|
||||
const MIN: Self = Self::Light;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue