summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Ashley Wulber <ashley@system76.com>2022-09-08 17:39:59 -0400
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-03 03:23:36 +0100
commitd5a933b047a955158a31a35266bbc9b25307b0fc (patch)
tree563341bfb53d55b6e22df09f87fd91a364c76b86 /examples
parent269d6f9a3f47861ff6fe67d65baf226192a3c22f (diff)
downloadiced-d5a933b047a955158a31a35266bbc9b25307b0fc.tar.gz
iced-d5a933b047a955158a31a35266bbc9b25307b0fc.tar.bz2
iced-d5a933b047a955158a31a35266bbc9b25307b0fc.zip
refactor: remove once_cell from styling example
Diffstat (limited to 'examples')
-rw-r--r--examples/styling/Cargo.toml1
-rw-r--r--examples/styling/src/main.rs28
2 files changed, 15 insertions, 14 deletions
diff --git a/examples/styling/Cargo.toml b/examples/styling/Cargo.toml
index 344cd0d6..f771708c 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 69827130..625a2b9a 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<Theme> = 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 => {}