summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Robert Krahn <robert.krahn@gmail.com>2022-11-03 00:35:01 +0100
committerLibravatar Robert Krahn <robert.krahn@gmail.com>2022-11-03 22:48:26 +0100
commitc0596179bd8582e4f4b5289cdeee8de4fa3de464 (patch)
treeb1ed80cf49aa846ba7a93cc97128c3ec6eadd123 /native
parentd222b5c8b0befab665c20ba0112b28199df0ae44 (diff)
downloadiced-c0596179bd8582e4f4b5289cdeee8de4fa3de464.tar.gz
iced-c0596179bd8582e4f4b5289cdeee8de4fa3de464.tar.bz2
iced-c0596179bd8582e4f4b5289cdeee8de4fa3de464.zip
non uniform border radius for quads
Diffstat (limited to 'native')
-rw-r--r--native/src/element.rs2
-rw-r--r--native/src/overlay/menu.rs4
-rw-r--r--native/src/renderer.rs26
-rw-r--r--native/src/widget/button.rs4
-rw-r--r--native/src/widget/checkbox.rs2
-rw-r--r--native/src/widget/container.rs2
-rw-r--r--native/src/widget/pane_grid.rs2
-rw-r--r--native/src/widget/pick_list.rs2
-rw-r--r--native/src/widget/progress_bar.rs4
-rw-r--r--native/src/widget/radio.rs4
-rw-r--r--native/src/widget/rule.rs2
-rw-r--r--native/src/widget/scrollable.rs4
-rw-r--r--native/src/widget/slider.rs6
-rw-r--r--native/src/widget/text_input.rs6
-rw-r--r--native/src/widget/toggler.rs4
15 files changed, 49 insertions, 25 deletions
diff --git a/native/src/element.rs b/native/src/element.rs
index 074e422e..955e1bee 100644
--- a/native/src/element.rs
+++ b/native/src/element.rs
@@ -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,
);
diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs
index 08135872..dbcf23d4 100644
--- a/native/src/overlay/menu.rs
+++ b/native/src/overlay/menu.rs
@@ -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,
);
diff --git a/native/src/renderer.rs b/native/src/renderer.rs
index ef64ac36..39c1b4c7 100644
--- a/native/src/renderer.rs
+++ b/native/src/renderer.rs
@@ -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 {
diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs
index 6c0b8f6e..14759cfd 100644
--- a/native/src/widget/button.rs
+++ b/native/src/widget/button.rs
@@ -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,
},
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index dc3c0bd0..8f30037a 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -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,
},
diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs
index 2afad3f2..b0c4938a 100644
--- a/native/src/widget/container.rs
+++ b/native/src/widget/container.rs
@@ -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,
},
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index 96cf78ef..45090ecf 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -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,
},
diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs
index 896f5b35..a92ea655 100644
--- a/native/src/widget/pick_list.rs
+++ b/native/src/widget/pick_list.rs
@@ -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,
);
diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs
index 8a945433..5f8892fe 100644
--- a/native/src/widget/progress_bar.rs
+++ b/native/src/widget/progress_bar.rs
@@ -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,
},
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index cb83f745..10e89870 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -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,
},
diff --git a/native/src/widget/rule.rs b/native/src/widget/rule.rs
index 56f8c80d..1d1c04cf 100644
--- a/native/src/widget/rule.rs
+++ b/native/src/widget/rule.rs
@@ -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,
},
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs
index 4ebb07a0..b445e505 100644
--- a/native/src/widget/scrollable.rs
+++ b/native/src/widget/scrollable.rs
@@ -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,
},
diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs
index 585d9c35..011454de 100644
--- a/native/src/widget/slider.rs
+++ b/native/src/widget/slider.rs
@@ -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,
},
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index 54a6aaf8..ae0305dc 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -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,
},
diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs
index 7893f78c..c5c2d82a 100644
--- a/native/src/widget/toggler.rs
+++ b/native/src/widget/toggler.rs
@@ -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