diff options
author | 2023-04-12 05:19:01 +0200 | |
---|---|---|
committer | 2023-04-12 05:19:01 +0200 | |
commit | 45cfce3f6dcf2773bc8ccc7e356906cb778f2f27 (patch) | |
tree | aacb579ac8628b99b1ddde55abe0d235085b7bfc | |
parent | de51bc3f41752634c0ccce8484d0a9bade62a45a (diff) | |
download | iced-45cfce3f6dcf2773bc8ccc7e356906cb778f2f27.tar.gz iced-45cfce3f6dcf2773bc8ccc7e356906cb778f2f27.tar.bz2 iced-45cfce3f6dcf2773bc8ccc7e356906cb778f2f27.zip |
Simplify `draw` logic of sliders
-rw-r--r-- | native/src/widget/slider.rs | 18 | ||||
-rw-r--r-- | native/src/widget/vertical_slider.rs | 15 |
2 files changed, 15 insertions, 18 deletions
diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index b3f3306c..2f946a8a 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -370,8 +370,6 @@ pub fn draw<T, R>( style_sheet.active(style) }; - let value = value.into() as f32; - let (handle_width, handle_height, handle_border_radius) = match style .handle .shape @@ -383,6 +381,7 @@ pub fn draw<T, R>( } => (f32::from(width), bounds.height, border_radius), }; + let value = value.into() as f32; let (range_start, range_end) = { let (start, end) = range.clone().into_inner(); @@ -396,15 +395,14 @@ pub fn draw<T, R>( / (range_end - range_start) }; - let line_y = bounds.y + bounds.height / 2.0 - style.rail.size / 2.0; - let line_offset = offset + handle_width / 2.0; + let rail_y = bounds.y + bounds.height / 2.0; renderer.fill_quad( renderer::Quad { bounds: Rectangle { x: bounds.x, - y: line_y, - width: line_offset, + y: rail_y - style.rail.size / 2.0, + width: offset, height: style.rail.size, }, border_radius: [ @@ -423,9 +421,9 @@ pub fn draw<T, R>( renderer.fill_quad( renderer::Quad { bounds: Rectangle { - x: bounds.x + line_offset.round(), - y: line_y, - width: bounds.width - line_offset, + x: bounds.x + offset, + y: rail_y - style.rail.size / 2.0, + width: bounds.width - offset, height: style.rail.size, }, border_radius: [ @@ -445,7 +443,7 @@ pub fn draw<T, R>( renderer::Quad { bounds: Rectangle { x: bounds.x + offset.round(), - y: bounds.y + bounds.height / 2.0 - handle_height / 2.0, + y: rail_y - handle_height / 2.0, width: handle_width, height: handle_height, }, diff --git a/native/src/widget/vertical_slider.rs b/native/src/widget/vertical_slider.rs index 3a8c30b6..8c6d1e5d 100644 --- a/native/src/widget/vertical_slider.rs +++ b/native/src/widget/vertical_slider.rs @@ -388,16 +388,15 @@ pub fn draw<T, R>( / (range_start - range_end) }; - let line_x = bounds.x + bounds.width / 2.0 - style.rail.size / 2.0; - let line_offset = offset + handle_width / 2.0; + let rail_x = bounds.x + bounds.width / 2.0; renderer.fill_quad( renderer::Quad { bounds: Rectangle { - x: line_x, + x: rail_x - style.rail.size / 2.0, y: bounds.y, width: style.rail.size, - height: line_offset, + height: offset, }, border_radius: [ style.rail.border_radius, @@ -415,10 +414,10 @@ pub fn draw<T, R>( renderer.fill_quad( renderer::Quad { bounds: Rectangle { - x: line_x, - y: bounds.y + line_offset.round(), + x: rail_x - style.rail.size / 2.0, + y: bounds.y + offset, width: style.rail.size, - height: bounds.height - line_offset, + height: bounds.height - offset, }, border_radius: [ 0.0, @@ -436,7 +435,7 @@ pub fn draw<T, R>( renderer.fill_quad( renderer::Quad { bounds: Rectangle { - x: bounds.x + bounds.width / 2.0 - handle_height / 2.0, + x: rail_x - handle_height / 2.0, y: bounds.y + offset.round(), width: handle_height, height: handle_width, |