From 387fc0be26ccd1adc66c1dc80420f9b08d0c023a Mon Sep 17 00:00:00 2001
From: Héctor Ramón Jiménez <hector0193@gmail.com>
Date: Tue, 7 Jan 2020 02:25:57 +0100
Subject: Implement styling for `Radio`

---
 wgpu/src/renderer/widget/radio.rs | 26 ++++++++++++++------------
 wgpu/src/widget.rs                |  1 +
 wgpu/src/widget/radio.rs          | 10 ++++++++++
 3 files changed, 25 insertions(+), 12 deletions(-)
 create mode 100644 wgpu/src/widget/radio.rs

(limited to 'wgpu/src')

diff --git a/wgpu/src/renderer/widget/radio.rs b/wgpu/src/renderer/widget/radio.rs
index aa1dbadc..564f066b 100644
--- a/wgpu/src/renderer/widget/radio.rs
+++ b/wgpu/src/renderer/widget/radio.rs
@@ -1,10 +1,12 @@
-use crate::{Primitive, Renderer};
+use crate::{radio::StyleSheet, Primitive, Renderer};
 use iced_native::{radio, Background, Color, MouseCursor, Rectangle};
 
 const SIZE: f32 = 28.0;
 const DOT_SIZE: f32 = SIZE / 2.0;
 
 impl radio::Renderer for Renderer {
+    type Style = Box<dyn StyleSheet>;
+
     fn default_size(&self) -> u32 {
         SIZE as u32
     }
@@ -15,20 +17,20 @@ impl radio::Renderer for Renderer {
         is_selected: bool,
         is_mouse_over: bool,
         (label, _): Self::Output,
+        style_sheet: &Self::Style,
     ) -> Self::Output {
+        let style = if is_mouse_over {
+            style_sheet.hovered()
+        } else {
+            style_sheet.active()
+        };
+
         let radio = Primitive::Quad {
             bounds,
-            background: Background::Color(
-                if is_mouse_over {
-                    [0.90, 0.90, 0.90]
-                } else {
-                    [0.95, 0.95, 0.95]
-                }
-                .into(),
-            ),
+            background: style.background,
             border_radius: (SIZE / 2.0) as u16,
-            border_width: 1,
-            border_color: Color::from_rgb(0.6, 0.6, 0.6),
+            border_width: style.border_width,
+            border_color: style.border_color,
         };
 
         (
@@ -41,7 +43,7 @@ impl radio::Renderer for Renderer {
                             width: bounds.width - DOT_SIZE,
                             height: bounds.height - DOT_SIZE,
                         },
-                        background: Background::Color([0.3, 0.3, 0.3].into()),
+                        background: Background::Color(style.dot_color),
                         border_radius: (DOT_SIZE / 2.0) as u16,
                         border_width: 0,
                         border_color: Color::TRANSPARENT,
diff --git a/wgpu/src/widget.rs b/wgpu/src/widget.rs
index 3f3dc0b0..991e0644 100644
--- a/wgpu/src/widget.rs
+++ b/wgpu/src/widget.rs
@@ -1,6 +1,7 @@
 pub mod button;
 pub mod container;
 pub mod progress_bar;
+pub mod radio;
 pub mod scrollable;
 pub mod slider;
 pub mod text_input;
diff --git a/wgpu/src/widget/radio.rs b/wgpu/src/widget/radio.rs
new file mode 100644
index 00000000..6e5cf042
--- /dev/null
+++ b/wgpu/src/widget/radio.rs
@@ -0,0 +1,10 @@
+//! Create choices using radio buttons.
+use crate::Renderer;
+
+pub use iced_style::radio::{Style, StyleSheet};
+
+/// A circular button representing a choice.
+///
+/// This is an alias of an `iced_native` radio button with an
+/// `iced_wgpu::Renderer`.
+pub type Radio<Message> = iced_native::Radio<Message, Renderer>;
-- 
cgit