diff options
| author | 2020-01-09 18:46:06 +0100 | |
|---|---|---|
| committer | 2020-01-09 18:46:06 +0100 | |
| commit | 0a8302450557877cb667b51fc84383aaf0a11b02 (patch) | |
| tree | fe3a8a6b0ae82f7fd1fa0c0de34b4b09d0b9edda /wgpu/src/renderer/widget/radio.rs | |
| parent | 6699329d3f91c5b9d8e8e55ad88de24bd3894955 (diff) | |
| parent | 7b278755fc7929633b5771824beac4d39b16e82e (diff) | |
| download | iced-0a8302450557877cb667b51fc84383aaf0a11b02.tar.gz iced-0a8302450557877cb667b51fc84383aaf0a11b02.tar.bz2 iced-0a8302450557877cb667b51fc84383aaf0a11b02.zip  | |
Merge pull request #146 from hecrj/feature/custom-styling
Custom styling
Diffstat (limited to 'wgpu/src/renderer/widget/radio.rs')
| -rw-r--r-- | wgpu/src/renderer/widget/radio.rs | 52 | 
1 files changed, 23 insertions, 29 deletions
diff --git a/wgpu/src/renderer/widget/radio.rs b/wgpu/src/renderer/widget/radio.rs index 3c00a4c2..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 iced_native::{radio, Background, MouseCursor, Rectangle}; +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,31 +17,21 @@ impl radio::Renderer for Renderer {          is_selected: bool,          is_mouse_over: bool,          (label, _): Self::Output, +        style_sheet: &Self::Style,      ) -> Self::Output { -        let (radio_border, radio_box) = ( -            Primitive::Quad { -                bounds, -                background: Background::Color([0.6, 0.6, 0.6].into()), -                border_radius: (SIZE / 2.0) as u16, -            }, -            Primitive::Quad { -                bounds: Rectangle { -                    x: bounds.x + 1.0, -                    y: bounds.y + 1.0, -                    width: bounds.width - 2.0, -                    height: bounds.height - 2.0, -                }, -                background: Background::Color( -                    if is_mouse_over { -                        [0.90, 0.90, 0.90] -                    } else { -                        [0.95, 0.95, 0.95] -                    } -                    .into(), -                ), -                border_radius: (SIZE / 2.0 - 1.0) as u16, -            }, -        ); +        let style = if is_mouse_over { +            style_sheet.hovered() +        } else { +            style_sheet.active() +        }; + +        let radio = Primitive::Quad { +            bounds, +            background: style.background, +            border_radius: (SIZE / 2.0) as u16, +            border_width: style.border_width, +            border_color: style.border_color, +        };          (              Primitive::Group { @@ -51,13 +43,15 @@ 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,                      }; -                    vec![radio_border, radio_box, radio_circle, label] +                    vec![radio, radio_circle, label]                  } else { -                    vec![radio_border, radio_box, label] +                    vec![radio, label]                  },              },              if is_mouse_over {  | 
