iced-yoda/wgpu/src/renderer/widget/radio.rs

64 lines
1.9 KiB
Rust
Raw Normal View History

2020-01-07 02:25:57 +01:00
use crate::{radio::StyleSheet, Primitive, Renderer};
use iced_native::{mouse, radio, Background, Color, Rectangle};
2019-10-12 18:48:35 +02:00
const SIZE: f32 = 28.0;
const DOT_SIZE: f32 = SIZE / 2.0;
2019-10-05 19:22:51 +02:00
impl radio::Renderer for Renderer {
2020-01-07 02:25:57 +01:00
type Style = Box<dyn StyleSheet>;
const DEFAULT_SIZE: u16 = SIZE as u16;
const DEFAULT_SPACING: u16 = 15;
2019-10-05 19:22:51 +02:00
fn draw(
2019-10-05 19:22:51 +02:00
&mut self,
bounds: Rectangle,
is_selected: bool,
is_mouse_over: bool,
(label, _): Self::Output,
2020-01-07 02:25:57 +01:00
style_sheet: &Self::Style,
) -> Self::Output {
2020-01-07 02:25:57 +01:00
let style = if is_mouse_over {
style_sheet.hovered()
} else {
style_sheet.active()
};
let radio = Primitive::Quad {
bounds,
2020-01-07 02:25:57 +01:00
background: style.background,
border_radius: (SIZE / 2.0) as u16,
2020-01-07 02:25:57 +01:00
border_width: style.border_width,
border_color: style.border_color,
};
2019-10-12 18:48:35 +02:00
(
Primitive::Group {
primitives: if is_selected {
2019-10-12 18:48:35 +02:00
let radio_circle = Primitive::Quad {
bounds: Rectangle {
x: bounds.x + DOT_SIZE / 2.0,
y: bounds.y + DOT_SIZE / 2.0,
width: bounds.width - DOT_SIZE,
height: bounds.height - DOT_SIZE,
2019-10-12 18:48:35 +02:00
},
2020-01-07 02:25:57 +01:00
background: Background::Color(style.dot_color),
2019-10-12 18:48:35 +02:00
border_radius: (DOT_SIZE / 2.0) as u16,
border_width: 0,
border_color: Color::TRANSPARENT,
2019-10-12 18:48:35 +02:00
};
vec![radio, radio_circle, label]
2019-10-12 18:48:35 +02:00
} else {
vec![radio, label]
2019-10-12 18:48:35 +02:00
},
},
if is_mouse_over {
mouse::Interaction::Pointer
2019-10-12 18:48:35 +02:00
} else {
mouse::Interaction::default()
2019-10-12 18:48:35 +02:00
},
)
2019-10-05 19:22:51 +02:00
}
}