refactor(theme): make Theme Copy
This commit is contained in:
parent
3245ff1b0e
commit
844aeba379
4 changed files with 97 additions and 83 deletions
|
|
@ -25,7 +25,7 @@ mod bluetooth;
|
|||
|
||||
mod demo;
|
||||
|
||||
use self::{demo::ThemeMode, desktop::DesktopPage};
|
||||
use self::desktop::DesktopPage;
|
||||
mod desktop;
|
||||
|
||||
mod editor;
|
||||
|
|
@ -176,7 +176,7 @@ impl Window {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Message {
|
||||
Bluetooth(bluetooth::Message),
|
||||
Close,
|
||||
|
|
@ -390,10 +390,9 @@ impl Application for Window {
|
|||
Message::Demo(message) => match self.demo.update(message) {
|
||||
Some(demo::Output::Debug(debug)) => self.debug = debug,
|
||||
Some(demo::Output::ScalingFactor(factor)) => self.set_scale_factor(factor),
|
||||
Some(demo::Output::ThemeChanged(theme)) => match theme {
|
||||
ThemeMode::Light => self.theme = Theme::light(),
|
||||
ThemeMode::Dark => self.theme = Theme::dark(),
|
||||
},
|
||||
Some(demo::Output::ThemeChanged(theme)) => {
|
||||
self.theme = theme;
|
||||
}
|
||||
Some(demo::Output::ToggleWarning) => self.toggle_warning(),
|
||||
None => (),
|
||||
},
|
||||
|
|
@ -568,6 +567,6 @@ impl Application for Window {
|
|||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme.clone()
|
||||
self.theme
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,13 +29,7 @@ pub enum MultiOption {
|
|||
OptionE,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum ThemeMode {
|
||||
Light,
|
||||
Dark,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Message {
|
||||
ButtonPressed,
|
||||
CheckboxToggled(bool),
|
||||
|
|
@ -48,7 +42,7 @@ pub enum Message {
|
|||
Selection(segmented_button::Entity),
|
||||
SliderChanged(f32),
|
||||
SpinButton(spin_button::Message),
|
||||
ThemeChanged(ThemeMode),
|
||||
ThemeChanged(Theme),
|
||||
ToggleWarning,
|
||||
TogglerToggled(bool),
|
||||
ViewSwitcher(segmented_button::Entity),
|
||||
|
|
@ -57,7 +51,7 @@ pub enum Message {
|
|||
pub enum Output {
|
||||
Debug(bool),
|
||||
ScalingFactor(f32),
|
||||
ThemeChanged(ThemeMode),
|
||||
ThemeChanged(Theme),
|
||||
ToggleWarning,
|
||||
}
|
||||
|
||||
|
|
@ -148,15 +142,20 @@ impl State {
|
|||
}
|
||||
|
||||
pub(super) fn view<'a>(&'a self, window: &'a Window) -> Element<'a, Message> {
|
||||
let choose_theme = [ThemeMode::Light, ThemeMode::Dark].iter().fold(
|
||||
let choose_theme = [
|
||||
Theme::light(),
|
||||
Theme::dark(),
|
||||
Theme::light_hc(),
|
||||
Theme::dark_hc(),
|
||||
]
|
||||
.iter()
|
||||
.fold(
|
||||
row![].spacing(10).align_items(Alignment::Center),
|
||||
|row, theme| {
|
||||
row.push(radio(
|
||||
format!("{:?}", theme),
|
||||
format!("{:?}", theme.theme_type),
|
||||
*theme,
|
||||
if window.theme.cosmic().is_dark && matches!(theme, ThemeMode::Dark)
|
||||
|| !window.theme.cosmic().is_dark && matches!(theme, ThemeMode::Light)
|
||||
{
|
||||
if window.theme == *theme {
|
||||
Some(*theme)
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue