summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-31 05:13:57 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-06-01 01:46:04 +0200
commit3e2b6247f72815b6e928237f242c2d66478cf15d (patch)
tree694eba8c2bbf28565d598e02627b0b8e026e1e78 /examples
parent28d09bfff1dde55190986bab10d7aaeb0ceb49de (diff)
downloadiced-3e2b6247f72815b6e928237f242c2d66478cf15d.tar.gz
iced-3e2b6247f72815b6e928237f242c2d66478cf15d.tar.bz2
iced-3e2b6247f72815b6e928237f242c2d66478cf15d.zip
Implement theme styling for `Toggler`
... and wire up theming to the `styling` example.
Diffstat (limited to 'examples')
-rw-r--r--examples/styling/src/main.rs53
1 files changed, 10 insertions, 43 deletions
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs
index 27b3ead4..044f75a9 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -5,7 +5,7 @@ use iced::text_input;
use iced::{
Alignment, Button, Checkbox, Column, Container, Element, Length,
ProgressBar, Radio, Row, Rule, Sandbox, Scrollable, Settings, Slider,
- Space, Text, TextInput, Toggler,
+ Space, Text, TextInput, Theme, Toggler,
};
pub fn main() -> iced::Result {
@@ -115,8 +115,7 @@ impl Sandbox for Styling {
Message::TogglerToggled,
)
.width(Length::Shrink)
- .spacing(10)
- .style(self.theme);
+ .spacing(10);
let content = Column::new()
.spacing(20)
@@ -151,12 +150,18 @@ impl Sandbox for Styling {
.style(self.theme)
.into()
}
+
+ fn theme(&self) -> Theme {
+ match self.theme {
+ style::Theme::Light => Theme::Light,
+ style::Theme::Dark => Theme::Dark,
+ }
+ }
}
mod style {
use iced::{
checkbox, container, progress_bar, rule, scrollable, text_input,
- toggler,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -220,15 +225,6 @@ mod style {
}
}
- impl From<Theme> for Box<dyn toggler::StyleSheet> {
- fn from(theme: Theme) -> Self {
- match theme {
- Theme::Light => Default::default(),
- Theme::Dark => dark::Toggler.into(),
- }
- }
- }
-
impl From<Theme> for Box<dyn rule::StyleSheet> {
fn from(theme: Theme) -> Self {
match theme {
@@ -241,7 +237,7 @@ mod style {
mod dark {
use iced::{
checkbox, container, progress_bar, rule, scrollable, text_input,
- toggler, Color,
+ Color,
};
const SURFACE: Color = Color::from_rgb(
@@ -404,35 +400,6 @@ mod style {
}
}
- pub struct Toggler;
-
- impl toggler::StyleSheet for Toggler {
- fn active(&self, is_active: bool) -> toggler::Style {
- toggler::Style {
- background: if is_active { ACTIVE } else { SURFACE },
- background_border: None,
- foreground: if is_active { Color::WHITE } else { ACTIVE },
- foreground_border: None,
- }
- }
-
- fn hovered(&self, is_active: bool) -> toggler::Style {
- toggler::Style {
- background: if is_active { ACTIVE } else { SURFACE },
- background_border: None,
- foreground: if is_active {
- Color {
- a: 0.5,
- ..Color::WHITE
- }
- } else {
- Color { a: 0.5, ..ACTIVE }
- },
- foreground_border: None,
- }
- }
- }
-
pub struct Rule;
impl rule::StyleSheet for Rule {