diff options
author | 2019-11-07 01:03:29 -0500 | |
---|---|---|
committer | 2019-11-07 01:03:29 -0500 | |
commit | e7bd24c13eb0c5c2b8ecf3f09f9e2de315bf8a41 (patch) | |
tree | cd15929a84965238b3aecf5d37214182079eb868 /wgpu | |
parent | 58bd0824bf458b6a5b21ade1efe998b1439469cd (diff) | |
download | iced-e7bd24c13eb0c5c2b8ecf3f09f9e2de315bf8a41.tar.gz iced-e7bd24c13eb0c5c2b8ecf3f09f9e2de315bf8a41.tar.bz2 iced-e7bd24c13eb0c5c2b8ecf3f09f9e2de315bf8a41.zip |
use Color's `From` impl in more places
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/renderer.rs | 7 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/button.rs | 18 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/checkbox.rs | 30 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/radio.rs | 37 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/scrollable.rs | 18 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/slider.rs | 44 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/text_input.rs | 34 |
7 files changed, 49 insertions, 139 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index c8e1e10d..799cb30c 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -444,12 +444,7 @@ fn explain_layout( // TODO: Draw borders instead primitives.push(Primitive::Quad { bounds: layout.bounds(), - background: Background::Color(Color { - r: 0.0, - g: 0.0, - b: 0.0, - a: 0.05, - }), + background: Background::Color([0.0, 0.0, 0.0, 0.05].into()), border_radius: 0, }); diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs index ad2186d6..0ac1c0a6 100644 --- a/wgpu/src/renderer/widget/button.rs +++ b/wgpu/src/renderer/widget/button.rs @@ -1,6 +1,6 @@ use crate::{Primitive, Renderer}; use iced_native::{ - button, Align, Background, Button, Color, Layout, Length, MouseCursor, + button, Align, Background, Button, Layout, Length, MouseCursor, Node, Point, Rectangle, Style, }; @@ -53,23 +53,15 @@ impl button::Renderer for Renderer { y: bounds.y + shadow_offset, ..bounds }, - background: Background::Color(Color { - r: 0.0, - b: 0.0, - g: 0.0, - a: 0.5, - }), + background: Background::Color( + [0.0, 0.0, 0.0, 0.5].into(), + ), border_radius: button.border_radius, }, Primitive::Quad { bounds, background: button.background.unwrap_or( - Background::Color(Color { - r: 0.8, - b: 0.8, - g: 0.8, - a: 1.0, - }), + Background::Color([0.8, 0.8, 0.8].into()), ), border_radius: button.border_radius, }, diff --git a/wgpu/src/renderer/widget/checkbox.rs b/wgpu/src/renderer/widget/checkbox.rs index 5867a36f..1594c769 100644 --- a/wgpu/src/renderer/widget/checkbox.rs +++ b/wgpu/src/renderer/widget/checkbox.rs @@ -1,7 +1,7 @@ use crate::{Primitive, Renderer}; use iced_native::{ checkbox, text, text::HorizontalAlignment, text::VerticalAlignment, Align, - Background, Checkbox, Color, Column, Layout, Length, MouseCursor, Node, + Background, Checkbox, Column, Layout, Length, MouseCursor, Node, Point, Rectangle, Row, Text, Widget, }; @@ -46,12 +46,7 @@ impl checkbox::Renderer for Renderer { let (checkbox_border, checkbox_box) = ( Primitive::Quad { bounds: checkbox_bounds, - background: Background::Color(Color { - r: 0.6, - g: 0.6, - b: 0.6, - a: 1.0, - }), + background: Background::Color([0.6, 0.6, 0.6].into()), border_radius: 6, }, Primitive::Quad { @@ -61,21 +56,14 @@ impl checkbox::Renderer for Renderer { width: checkbox_bounds.width - 2.0, height: checkbox_bounds.height - 2.0, }, - background: Background::Color(if is_mouse_over { - Color { - r: 0.90, - g: 0.90, - b: 0.90, - a: 1.0, + background: Background::Color( + if is_mouse_over { + [0.90, 0.90, 0.90] + } else { + [0.95, 0.95, 0.95] } - } else { - Color { - r: 0.95, - g: 0.95, - b: 0.95, - a: 1.0, - } - }), + .into(), + ), border_radius: 5, }, ); diff --git a/wgpu/src/renderer/widget/radio.rs b/wgpu/src/renderer/widget/radio.rs index 97b4f70e..61f5ce47 100644 --- a/wgpu/src/renderer/widget/radio.rs +++ b/wgpu/src/renderer/widget/radio.rs @@ -1,6 +1,6 @@ use crate::{Primitive, Renderer}; use iced_native::{ - radio, text, Align, Background, Color, Column, Layout, Length, MouseCursor, + radio, text, Align, Background, Column, Layout, Length, MouseCursor, Node, Point, Radio, Rectangle, Row, Text, Widget, }; @@ -41,12 +41,7 @@ impl radio::Renderer for Renderer { let (radio_border, radio_box) = ( Primitive::Quad { bounds: radio_bounds, - background: Background::Color(Color { - r: 0.6, - g: 0.6, - b: 0.6, - a: 1.0, - }), + background: Background::Color([0.6, 0.6, 0.6].into()), border_radius: (SIZE / 2.0) as u16, }, Primitive::Quad { @@ -56,21 +51,14 @@ impl radio::Renderer for Renderer { width: radio_bounds.width - 2.0, height: radio_bounds.height - 2.0, }, - background: Background::Color(if is_mouse_over { - Color { - r: 0.90, - g: 0.90, - b: 0.90, - a: 1.0, + background: Background::Color( + if is_mouse_over { + [0.90, 0.90, 0.90] + } else { + [0.95, 0.95, 0.95] } - } else { - Color { - r: 0.95, - g: 0.95, - b: 0.95, - a: 1.0, - } - }), + .into(), + ), border_radius: (SIZE / 2.0 - 1.0) as u16, }, ); @@ -85,12 +73,7 @@ impl radio::Renderer for Renderer { width: radio_bounds.width - DOT_SIZE, height: radio_bounds.height - DOT_SIZE, }, - background: Background::Color(Color { - r: 0.30, - g: 0.30, - b: 0.30, - a: 1.0, - }), + background: Background::Color([0.3, 0.3, 0.3].into()), border_radius: (DOT_SIZE / 2.0) as u16, }; diff --git a/wgpu/src/renderer/widget/scrollable.rs b/wgpu/src/renderer/widget/scrollable.rs index 360759a5..5eadf275 100644 --- a/wgpu/src/renderer/widget/scrollable.rs +++ b/wgpu/src/renderer/widget/scrollable.rs @@ -1,6 +1,6 @@ use crate::{Primitive, Renderer}; use iced_native::{ - scrollable, Background, Color, Layout, MouseCursor, Point, Rectangle, + scrollable, Background, Layout, MouseCursor, Point, Rectangle, Scrollable, Vector, Widget, }; @@ -78,12 +78,7 @@ impl scrollable::Renderer for Renderer { - f32::from(2 * SCROLLBAR_MARGIN), height: scrollbar_height, }, - background: Background::Color(Color { - r: 0.0, - g: 0.0, - b: 0.0, - a: 0.7, - }), + background: Background::Color([0.0, 0.0, 0.0, 0.7].into()), border_radius: 5, }; @@ -97,12 +92,9 @@ impl scrollable::Renderer for Renderer { - f32::from(2 * SCROLLBAR_MARGIN), ..scrollbar_bounds }, - background: Background::Color(Color { - r: 0.0, - g: 0.0, - b: 0.0, - a: 0.3, - }), + background: Background::Color( + [0.0, 0.0, 0.0, 0.3].into(), + ), border_radius: 5, }; diff --git a/wgpu/src/renderer/widget/slider.rs b/wgpu/src/renderer/widget/slider.rs index 4ae3abc4..789e7bd4 100644 --- a/wgpu/src/renderer/widget/slider.rs +++ b/wgpu/src/renderer/widget/slider.rs @@ -37,12 +37,7 @@ impl slider::Renderer for Renderer { width: bounds.width, height: 2.0, }, - background: Background::Color(Color { - r: 0.6, - g: 0.6, - b: 0.6, - a: 1.0, - }), + background: Background::Color([0.6, 0.6, 0.6].into()), border_radius: 0, }, Primitive::Quad { @@ -71,12 +66,7 @@ impl slider::Renderer for Renderer { width: HANDLE_WIDTH + 2.0, height: HANDLE_HEIGHT + 2.0, }, - background: Background::Color(Color { - r: 0.6, - g: 0.6, - b: 0.6, - a: 1.0, - }), + background: Background::Color([0.6, 0.6, 0.6].into()), border_radius: 5, }, Primitive::Quad { @@ -86,28 +76,16 @@ impl slider::Renderer for Renderer { width: HANDLE_WIDTH, height: HANDLE_HEIGHT, }, - background: Background::Color(if slider.state.is_dragging() { - Color { - r: 0.85, - g: 0.85, - b: 0.85, - a: 1.0, + background: Background::Color( + if slider.state.is_dragging() { + [0.85, 0.85, 0.85] + } else if is_mouse_over { + [0.90, 0.90, 0.90] + } else { + [0.95, 0.95, 0.95] } - } else if is_mouse_over { - Color { - r: 0.9, - g: 0.9, - b: 0.9, - a: 1.0, - } - } else { - Color { - r: 0.95, - g: 0.95, - b: 0.95, - a: 1.0, - } - }), + .into(), + ), border_radius: 4, }, ); diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs index cff8bf23..b5f6c5f6 100644 --- a/wgpu/src/renderer/widget/text_input.rs +++ b/wgpu/src/renderer/widget/text_input.rs @@ -25,20 +25,11 @@ impl text_input::Renderer for Renderer { bounds, background: Background::Color( if is_mouse_over || text_input.state.is_focused { - Color { - r: 0.5, - g: 0.5, - b: 0.5, - a: 1.0, - } + [0.5, 0.5, 0.5] } else { - Color { - r: 0.7, - g: 0.7, - b: 0.7, - a: 1.0, - } - }, + [0.7, 0.7, 0.7] + } + .into(), ), border_radius: 5, }; @@ -64,20 +55,11 @@ impl text_input::Renderer for Renderer { text.clone() }, color: if text.is_empty() { - Color { - r: 0.7, - g: 0.7, - b: 0.7, - a: 1.0, - } + [0.7, 0.7, 0.7] } else { - Color { - r: 0.3, - g: 0.3, - b: 0.3, - a: 1.0, - } - }, + [0.3, 0.3, 0.3] + } + .into(), bounds: Rectangle { width: f32::INFINITY, ..text_bounds |