From c0ee1d11f96f157c50fb2ff36d26a48e12771f72 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 8 Sep 2022 17:39:59 -0400 Subject: [PATCH] refactor: remove once_cell from styling example --- examples/styling/Cargo.toml | 1 - examples/styling/src/main.rs | 28 +++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/styling/Cargo.toml b/examples/styling/Cargo.toml index 344cd0d69d..f771708c8e 100644 --- a/examples/styling/Cargo.toml +++ b/examples/styling/Cargo.toml @@ -7,4 +7,3 @@ publish = false [dependencies] iced = { path = "../.." } -once_cell = "1.14.0" \ No newline at end of file diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 6982713048..625a2b9a21 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -6,22 +6,12 @@ use iced::widget::{ vertical_space, }; use iced::{Alignment, Element, Length, Sandbox, Settings, Theme, Color}; -use once_cell::sync::OnceCell; pub fn main() -> iced::Result { - let palette = Palette { - background: Color::from_rgb(1.0, 0.9, 1.0), - text: Color::BLACK, - primary: Color::from_rgb(0.5, 0.5, 0.0), - success: Color::from_rgb(0.0, 1.0, 0.0), - danger: Color::from_rgb(1.0, 0.0, 0.0), - }; - let extended = Extended::generate(palette); - CUSTOM_THEME.set(Theme::Custom { palette, extended }).unwrap(); + Styling::run(Settings::default()) } -static CUSTOM_THEME: OnceCell = OnceCell::new(); #[derive(Debug, PartialEq, Eq, Clone, Copy)] enum ThemeType { @@ -32,6 +22,7 @@ enum ThemeType { #[derive(Default)] struct Styling { + custom_theme: Theme, theme: Theme, input_value: String, slider_value: f32, @@ -53,7 +44,18 @@ impl Sandbox for Styling { type Message = Message; fn new() -> Self { - Styling::default() + let palette = Palette { + background: Color::from_rgb(1.0, 0.9, 1.0), + text: Color::BLACK, + primary: Color::from_rgb(0.5, 0.5, 0.0), + success: Color::from_rgb(0.0, 1.0, 0.0), + danger: Color::from_rgb(1.0, 0.0, 0.0), + }; + let extended = Extended::generate(palette); + Styling { + custom_theme: Theme::Custom { palette, extended }, + ..Default::default() + } } fn title(&self) -> String { @@ -65,7 +67,7 @@ impl Sandbox for Styling { Message::ThemeChanged(theme) => self.theme = match theme { ThemeType::Light => Theme::Light, ThemeType::Dark => Theme::Dark, - ThemeType::Custom => *CUSTOM_THEME.get().unwrap(), + ThemeType::Custom => self.custom_theme, }, Message::InputChanged(value) => self.input_value = value, Message::ButtonPressed => {}