From 1b980bc6e823b7e049f5bb86d039e3b7db5ce353 Mon Sep 17 00:00:00 2001 From: Kaiden42 Date: Wed, 19 Aug 2020 01:30:22 +0200 Subject: [PATCH 1/2] Implement From for Option --- core/src/background.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/background.rs b/core/src/background.rs index e1a37ddc..54a9cad2 100644 --- a/core/src/background.rs +++ b/core/src/background.rs @@ -13,3 +13,9 @@ impl From for Background { Background::Color(color) } } + +impl From for Option { + fn from(color: Color) -> Self { + Some(Background::from(color)) + } +} \ No newline at end of file From f0257949856a9a7edf747684925f85d2ce811198 Mon Sep 17 00:00:00 2001 From: Kaiden42 Date: Wed, 19 Aug 2020 01:30:46 +0200 Subject: [PATCH 2/2] Update styling example Also run `cargo fmt` --- core/src/background.rs | 2 +- examples/styling/src/main.rs | 47 +++++++++++++++--------------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/core/src/background.rs b/core/src/background.rs index 54a9cad2..cfb95867 100644 --- a/core/src/background.rs +++ b/core/src/background.rs @@ -18,4 +18,4 @@ impl From for Option { fn from(color: Color) -> Self { Some(Background::from(color)) } -} \ No newline at end of file +} diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 0c2cfc57..dcbc2744 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -241,16 +241,14 @@ mod style { } mod light { - use iced::{button, Background, Color, Vector}; + use iced::{button, Color, Vector}; pub struct Button; impl button::StyleSheet for Button { fn active(&self) -> button::Style { button::Style { - background: Some(Background::Color(Color::from_rgb( - 0.11, 0.42, 0.87, - ))), + background: Color::from_rgb(0.11, 0.42, 0.87).into(), border_radius: 12, shadow_offset: Vector::new(1.0, 1.0), text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE), @@ -271,7 +269,7 @@ mod style { mod dark { use iced::{ button, checkbox, container, progress_bar, radio, rule, scrollable, - slider, text_input, Background, Color, + slider, text_input, Color, }; const SURFACE: Color = Color::from_rgb( @@ -303,10 +301,8 @@ mod style { impl container::StyleSheet for Container { fn style(&self) -> container::Style { container::Style { - background: Some(Background::Color(Color::from_rgb8( - 0x36, 0x39, 0x3F, - ))), - text_color: Some(Color::WHITE), + background: Color::from_rgb8(0x36, 0x39, 0x3F).into(), + text_color: Color::WHITE.into(), ..container::Style::default() } } @@ -317,7 +313,7 @@ mod style { impl radio::StyleSheet for Radio { fn active(&self) -> radio::Style { radio::Style { - background: Background::Color(SURFACE), + background: SURFACE.into(), dot_color: ACTIVE, border_width: 1, border_color: ACTIVE, @@ -326,7 +322,7 @@ mod style { fn hovered(&self) -> radio::Style { radio::Style { - background: Background::Color(Color { a: 0.5, ..SURFACE }), + background: Color { a: 0.5, ..SURFACE }.into(), ..self.active() } } @@ -337,7 +333,7 @@ mod style { impl text_input::StyleSheet for TextInput { fn active(&self) -> text_input::Style { text_input::Style { - background: Background::Color(SURFACE), + background: SURFACE.into(), border_radius: 2, border_width: 0, border_color: Color::TRANSPARENT, @@ -378,7 +374,7 @@ mod style { impl button::StyleSheet for Button { fn active(&self) -> button::Style { button::Style { - background: Some(Background::Color(ACTIVE)), + background: ACTIVE.into(), border_radius: 3, text_color: Color::WHITE, ..button::Style::default() @@ -387,7 +383,7 @@ mod style { fn hovered(&self) -> button::Style { button::Style { - background: Some(Background::Color(HOVERED)), + background: HOVERED.into(), text_color: Color::WHITE, ..self.active() } @@ -407,7 +403,7 @@ mod style { impl scrollable::StyleSheet for Scrollable { fn active(&self) -> scrollable::Scrollbar { scrollable::Scrollbar { - background: Some(Background::Color(SURFACE)), + background: SURFACE.into(), border_radius: 2, border_width: 0, border_color: Color::TRANSPARENT, @@ -424,10 +420,7 @@ mod style { let active = self.active(); scrollable::Scrollbar { - background: Some(Background::Color(Color { - a: 0.5, - ..SURFACE - })), + background: Color { a: 0.5, ..SURFACE }.into(), scroller: scrollable::Scroller { color: HOVERED, ..active.scroller @@ -494,8 +487,8 @@ mod style { impl progress_bar::StyleSheet for ProgressBar { fn style(&self) -> progress_bar::Style { progress_bar::Style { - background: Background::Color(SURFACE), - bar: Background::Color(ACTIVE), + background: SURFACE.into(), + bar: ACTIVE.into(), border_radius: 10, } } @@ -506,11 +499,8 @@ mod style { impl checkbox::StyleSheet for Checkbox { fn active(&self, is_checked: bool) -> checkbox::Style { checkbox::Style { - background: Background::Color(if is_checked { - ACTIVE - } else { - SURFACE - }), + background: if is_checked { ACTIVE } else { SURFACE } + .into(), checkmark_color: Color::WHITE, border_radius: 2, border_width: 1, @@ -520,10 +510,11 @@ mod style { fn hovered(&self, is_checked: bool) -> checkbox::Style { checkbox::Style { - background: Background::Color(Color { + background: Color { a: 0.8, ..if is_checked { ACTIVE } else { SURFACE } - }), + } + .into(), ..self.active(is_checked) } }