diff options
author | 2023-04-17 23:41:12 +0200 | |
---|---|---|
committer | 2023-04-17 23:41:12 +0200 | |
commit | 4bae457c37b499f3cfddbdac9ff37a34cbce61d5 (patch) | |
tree | 79af93b2f7fabca1687900b48b165c5c74dcd26f /widget/src/vertical_slider.rs | |
parent | c0431aedd3bbef4161456f2fa5f29866e8f17fc5 (diff) | |
parent | 4b05f42fd6d18bf572b772dd60d6a4309ea5f343 (diff) | |
download | iced-4bae457c37b499f3cfddbdac9ff37a34cbce61d5.tar.gz iced-4bae457c37b499f3cfddbdac9ff37a34cbce61d5.tar.bz2 iced-4bae457c37b499f3cfddbdac9ff37a34cbce61d5.zip |
Merge branch 'master' into advanced-text
Diffstat (limited to 'widget/src/vertical_slider.rs')
-rw-r--r-- | widget/src/vertical_slider.rs | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs index 62dc997f..a7551aef 100644 --- a/widget/src/vertical_slider.rs +++ b/widget/src/vertical_slider.rs @@ -13,8 +13,8 @@ use crate::core::renderer; use crate::core::touch; use crate::core::widget::tree::{self, Tree}; use crate::core::{ - Background, Clipboard, Color, Element, Length, Pixels, Point, Rectangle, - Shell, Size, Widget, + Clipboard, Color, Element, Length, Pixels, Point, Rectangle, Shell, Size, + Widget, }; /// An vertical bar and a handle that selects a single value from a range of @@ -366,38 +366,6 @@ pub fn draw<T, R>( style_sheet.active(style) }; - let rail_x = bounds.x + (bounds.width / 2.0).round(); - - renderer.fill_quad( - renderer::Quad { - bounds: Rectangle { - x: rail_x - 1.0, - y: bounds.y, - width: 2.0, - height: bounds.height, - }, - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - style.rail_colors.0, - ); - - renderer.fill_quad( - renderer::Quad { - bounds: Rectangle { - x: rail_x + 1.0, - y: bounds.y, - width: 2.0, - height: bounds.height, - }, - border_radius: 0.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - Background::Color(style.rail_colors.1), - ); - let (handle_width, handle_height, handle_border_radius) = match style .handle .shape @@ -416,18 +384,50 @@ pub fn draw<T, R>( (start.into() as f32, end.into() as f32) }; - let handle_offset = if range_start >= range_end { + let offset = if range_start >= range_end { 0.0 } else { - (bounds.height - handle_width) * (value - range_end) + (bounds.height - handle_width / 2.0) * (value - range_end) / (range_start - range_end) }; + let rail_x = bounds.x + bounds.width / 2.0; + + renderer.fill_quad( + renderer::Quad { + bounds: Rectangle { + x: rail_x - style.rail.width / 2.0, + y: bounds.y, + width: style.rail.width, + height: offset + handle_width / 2.0, + }, + border_radius: Default::default(), + border_width: 0.0, + border_color: Color::TRANSPARENT, + }, + style.rail.colors.1, + ); + + renderer.fill_quad( + renderer::Quad { + bounds: Rectangle { + x: rail_x - style.rail.width / 2.0, + y: bounds.y + offset + handle_width / 2.0, + width: style.rail.width, + height: bounds.height - offset, + }, + border_radius: Default::default(), + border_width: 0.0, + border_color: Color::TRANSPARENT, + }, + style.rail.colors.0, + ); + renderer.fill_quad( renderer::Quad { bounds: Rectangle { - x: rail_x - (handle_height / 2.0), - y: bounds.y + handle_offset.round(), + x: rail_x - handle_height / 2.0, + y: bounds.y + offset, width: handle_height, height: handle_width, }, |