diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/progress_bar.rs | 14 | ||||
-rw-r--r-- | examples/styling.rs | 40 |
2 files changed, 36 insertions, 18 deletions
diff --git a/examples/progress_bar.rs b/examples/progress_bar.rs index 901428de..43b09928 100644 --- a/examples/progress_bar.rs +++ b/examples/progress_bar.rs @@ -1,7 +1,4 @@ -use iced::{ - slider, Background, Color, Column, Element, Length, ProgressBar, Sandbox, - Settings, Slider, -}; +use iced::{slider, Column, Element, ProgressBar, Sandbox, Settings, Slider}; pub fn main() { Progress::run(Settings::default()) @@ -38,14 +35,7 @@ impl Sandbox for Progress { fn view(&mut self) -> Element<Message> { Column::new() .padding(20) - .push( - ProgressBar::new(0.0..=100.0, self.value) - .background(Background::Color(Color::from_rgb( - 0.6, 0.6, 0.6, - ))) - .active_color(Color::from_rgb(0.0, 0.95, 0.0)) - .height(Length::Units(30)), - ) + .push(ProgressBar::new(0.0..=100.0, self.value)) .push(Slider::new( &mut self.progress_bar_slider, 0.0..=100.0, diff --git a/examples/styling.rs b/examples/styling.rs index 215185e3..426e0638 100644 --- a/examples/styling.rs +++ b/examples/styling.rs @@ -1,6 +1,7 @@ use iced::{ button, scrollable, slider, text_input, Button, Column, Container, Element, - Length, Radio, Row, Sandbox, Scrollable, Settings, Slider, Text, TextInput, + Length, ProgressBar, Radio, Row, Sandbox, Scrollable, Settings, Slider, + Text, TextInput, }; pub fn main() { @@ -82,13 +83,17 @@ impl Sandbox for Styling { ) .style(self.theme); + let progress_bar = + ProgressBar::new(0.0..=100.0, self.slider_value).style(self.theme); + let content = Column::new() .spacing(20) .padding(20) .max_width(600) .push(choose_theme) .push(Row::new().spacing(10).push(text_input).push(button)) - .push(slider); + .push(slider) + .push(progress_bar); let scrollable = Scrollable::new(&mut self.scroll) .style(self.theme) @@ -104,7 +109,9 @@ impl Sandbox for Styling { } mod style { - use iced::{button, container, scrollable, slider, text_input}; + use iced::{ + button, container, progress_bar, scrollable, slider, text_input, + }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Theme { @@ -167,6 +174,15 @@ mod style { } } + impl From<Theme> for Box<dyn progress_bar::StyleSheet> { + fn from(theme: Theme) -> Self { + match theme { + Theme::Light => Default::default(), + Theme::Dark => dark::ProgressBar.into(), + } + } + } + mod light { use iced::{button, Background, Color, Vector}; @@ -197,8 +213,8 @@ mod style { mod dark { use iced::{ - button, container, scrollable, slider, text_input, Background, - Color, + button, container, progress_bar, scrollable, slider, text_input, + Background, Color, }; const SURFACE: Color = Color::from_rgb( @@ -268,7 +284,7 @@ mod style { } fn placeholder_color(&self) -> Color { - Color::from_rgb(0.7, 0.7, 0.7) + Color::from_rgb(0.4, 0.4, 0.4) } fn value_color(&self) -> Color { @@ -372,5 +388,17 @@ mod style { } } } + + pub struct ProgressBar; + + impl progress_bar::StyleSheet for ProgressBar { + fn style(&self) -> progress_bar::Style { + progress_bar::Style { + background: Background::Color(SURFACE), + bar: Background::Color(ACTIVE), + border_radius: 10, + } + } + } } } |