non uniform border radius for quads

This commit is contained in:
Robert Krahn 2022-11-03 00:35:01 +01:00
parent d222b5c8b0
commit c0596179bd
25 changed files with 121 additions and 60 deletions

View file

@ -503,7 +503,7 @@ where
bounds: layout.bounds(),
border_color: color,
border_width: 1.0,
border_radius: 0.0,
border_radius: 0.0.into(),
},
Color::TRANSPARENT,
);

View file

@ -299,7 +299,7 @@ where
},
border_color: appearance.border_color,
border_width: appearance.border_width,
border_radius: appearance.border_radius,
border_radius: appearance.border_radius.into(),
},
appearance.background,
);
@ -491,7 +491,7 @@ where
bounds,
border_color: Color::TRANSPARENT,
border_width: 0.0,
border_radius: appearance.border_radius,
border_radius: appearance.border_radius.into(),
},
appearance.selected_background,
);

View file

@ -50,7 +50,7 @@ pub struct Quad {
pub bounds: Rectangle,
/// The border radius of the [`Quad`].
pub border_radius: f32,
pub border_radius: QuadBorderRadius,
/// The border width of the [`Quad`].
pub border_width: f32,
@ -59,6 +59,30 @@ pub struct Quad {
pub border_color: Color,
}
/// The border radi for the corners of a [`Quad`] in the order:
/// top-left, top-right, bottom-right, bottom-left.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct QuadBorderRadius([f32; 4]);
impl QuadBorderRadius {
/// Convert the corners of the Quad into an array [top_left, top_right, bottom_left, bottom_right].
pub fn to_array(self) -> [f32; 4] {
self.0
}
}
impl From<f32> for QuadBorderRadius {
fn from(w: f32) -> Self {
Self([w; 4])
}
}
impl From<[f32; 4]> for QuadBorderRadius {
fn from(radi: [f32; 4]) -> Self {
Self(radi)
}
}
/// The styling attributes of a [`Renderer`].
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {

View file

@ -393,7 +393,7 @@ where
y: bounds.y + styling.shadow_offset.y,
..bounds
},
border_radius: styling.border_radius,
border_radius: styling.border_radius.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
@ -404,7 +404,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: styling.border_radius,
border_radius: styling.border_radius.into(),
border_width: styling.border_width,
border_color: styling.border_color,
},

View file

@ -236,7 +236,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: custom_style.border_radius,
border_radius: custom_style.border_radius.into(),
border_width: custom_style.border_width,
border_color: custom_style.border_color,
},

View file

@ -321,7 +321,7 @@ pub fn draw_background<Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_radius: appearance.border_radius.into(),
border_width: appearance.border_width,
border_color: appearance.border_color,
},

View file

@ -828,7 +828,7 @@ pub fn draw<Renderer, T>(
height: split_region.height,
},
},
border_radius: 0.0,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},

View file

@ -514,7 +514,7 @@ pub fn draw<T, Renderer>(
bounds,
border_color: style.border_color,
border_width: style.border_width,
border_radius: style.border_radius,
border_radius: style.border_radius.into(),
},
style.background,
);

View file

@ -129,7 +129,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle { ..bounds },
border_radius: style.border_radius,
border_radius: style.border_radius.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
@ -143,7 +143,7 @@ where
width: active_progress_width,
..bounds
},
border_radius: style.border_radius,
border_radius: style.border_radius.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},

View file

@ -245,7 +245,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: size / 2.0,
border_radius: (size / 2.0).into(),
border_width: custom_style.border_width,
border_color: custom_style.border_color,
},
@ -261,7 +261,7 @@ where
width: bounds.width - dot_size,
height: bounds.height - dot_size,
},
border_radius: dot_size / 2.0,
border_radius: (dot_size / 2.0).into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},

View file

@ -123,7 +123,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: style.radius,
border_radius: style.radius.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},

View file

@ -698,7 +698,7 @@ pub fn draw<Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds: scrollbar.bounds,
border_radius: style.border_radius,
border_radius: style.border_radius.into(),
border_width: style.border_width,
border_color: style.border_color,
},
@ -715,7 +715,7 @@ pub fn draw<Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds: scrollbar.scroller.bounds,
border_radius: style.scroller.border_radius,
border_radius: style.scroller.border_radius.into(),
border_width: style.scroller.border_width,
border_color: style.scroller.border_color,
},

View file

@ -380,7 +380,7 @@ pub fn draw<T, R>(
width: bounds.width,
height: 2.0,
},
border_radius: 0.0,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
@ -395,7 +395,7 @@ pub fn draw<T, R>(
width: bounds.width,
height: 2.0,
},
border_radius: 0.0,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
@ -435,7 +435,7 @@ pub fn draw<T, R>(
width: handle_width,
height: handle_height,
},
border_radius: handle_border_radius,
border_radius: handle_border_radius.into(),
border_width: style.handle.border_width,
border_color: style.handle.border_color,
},

View file

@ -766,7 +766,7 @@ pub fn draw<Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_radius: appearance.border_radius.into(),
border_width: appearance.border_width,
border_color: appearance.border_color,
},
@ -798,7 +798,7 @@ pub fn draw<Renderer>(
width: 1.0,
height: text_bounds.height,
},
border_radius: 0.0,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
@ -842,7 +842,7 @@ pub fn draw<Renderer>(
width,
height: text_bounds.height,
},
border_radius: 0.0,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},

View file

@ -278,7 +278,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: toggler_background_bounds,
border_radius,
border_radius: border_radius.into(),
border_width: 1.0,
border_color: style
.background_border
@ -302,7 +302,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: toggler_foreground_bounds,
border_radius,
border_radius: border_radius.into(),
border_width: 1.0,
border_color: style
.foreground_border