summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-07 02:25:57 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-07 02:26:39 +0100
commit387fc0be26ccd1adc66c1dc80420f9b08d0c023a (patch)
treed7bcc53ac945e3f52af6de9af29726f224e6d2bd /wgpu
parent48b3b78a3840778eef1035f4585d5ba9dd3d6291 (diff)
downloadiced-387fc0be26ccd1adc66c1dc80420f9b08d0c023a.tar.gz
iced-387fc0be26ccd1adc66c1dc80420f9b08d0c023a.tar.bz2
iced-387fc0be26ccd1adc66c1dc80420f9b08d0c023a.zip
Implement styling for `Radio`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer/widget/radio.rs26
-rw-r--r--wgpu/src/widget.rs1
-rw-r--r--wgpu/src/widget/radio.rs10
3 files changed, 25 insertions, 12 deletions
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>;