Merge pull request #513 from hecrj/fix/custom-radio-size
Fix `Radio` border radius when using custom size
This commit is contained in:
commit
faa12382d4
|
@ -13,16 +13,13 @@ pub use iced_style::radio::{Style, StyleSheet};
|
||||||
pub type Radio<Message, Backend> =
|
pub type Radio<Message, Backend> =
|
||||||
iced_native::Radio<Message, Renderer<Backend>>;
|
iced_native::Radio<Message, Renderer<Backend>>;
|
||||||
|
|
||||||
const SIZE: f32 = 28.0;
|
|
||||||
const DOT_SIZE: f32 = SIZE / 2.0;
|
|
||||||
|
|
||||||
impl<B> radio::Renderer for Renderer<B>
|
impl<B> radio::Renderer for Renderer<B>
|
||||||
where
|
where
|
||||||
B: Backend,
|
B: Backend,
|
||||||
{
|
{
|
||||||
type Style = Box<dyn StyleSheet>;
|
type Style = Box<dyn StyleSheet>;
|
||||||
|
|
||||||
const DEFAULT_SIZE: u16 = SIZE as u16;
|
const DEFAULT_SIZE: u16 = 28;
|
||||||
const DEFAULT_SPACING: u16 = 15;
|
const DEFAULT_SPACING: u16 = 15;
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
@ -39,10 +36,13 @@ where
|
||||||
style_sheet.active()
|
style_sheet.active()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let size = bounds.width;
|
||||||
|
let dot_size = size / 2.0;
|
||||||
|
|
||||||
let radio = Primitive::Quad {
|
let radio = Primitive::Quad {
|
||||||
bounds,
|
bounds,
|
||||||
background: style.background,
|
background: style.background,
|
||||||
border_radius: (SIZE / 2.0) as u16,
|
border_radius: (size / 2.0) as u16,
|
||||||
border_width: style.border_width,
|
border_width: style.border_width,
|
||||||
border_color: style.border_color,
|
border_color: style.border_color,
|
||||||
};
|
};
|
||||||
|
@ -52,13 +52,13 @@ where
|
||||||
primitives: if is_selected {
|
primitives: if is_selected {
|
||||||
let radio_circle = Primitive::Quad {
|
let radio_circle = Primitive::Quad {
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bounds.x + DOT_SIZE / 2.0,
|
x: bounds.x + dot_size / 2.0,
|
||||||
y: bounds.y + DOT_SIZE / 2.0,
|
y: bounds.y + dot_size / 2.0,
|
||||||
width: bounds.width - DOT_SIZE,
|
width: bounds.width - dot_size,
|
||||||
height: bounds.height - DOT_SIZE,
|
height: bounds.height - dot_size,
|
||||||
},
|
},
|
||||||
background: Background::Color(style.dot_color),
|
background: Background::Color(style.dot_color),
|
||||||
border_radius: (DOT_SIZE / 2.0) as u16,
|
border_radius: (dot_size / 2.0) as u16,
|
||||||
border_width: 0,
|
border_width: 0,
|
||||||
border_color: Color::TRANSPARENT,
|
border_color: Color::TRANSPARENT,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue