diff options
author | 2023-01-06 14:55:09 +1300 | |
---|---|---|
committer | 2023-04-12 05:09:16 +0200 | |
commit | de51bc3f41752634c0ccce8484d0a9bade62a45a (patch) | |
tree | 3353601f3f5e0d76422530e2d6671f587a7e09c0 /native/src/widget/vertical_slider.rs | |
parent | ce8e92ca7a4ed0f4fe284c9042f863f7c83ba03a (diff) | |
download | iced-de51bc3f41752634c0ccce8484d0a9bade62a45a.tar.gz iced-de51bc3f41752634c0ccce8484d0a9bade62a45a.tar.bz2 iced-de51bc3f41752634c0ccce8484d0a9bade62a45a.zip |
Introduce left and right colors for slider rails
Diffstat (limited to 'native/src/widget/vertical_slider.rs')
-rw-r--r-- | native/src/widget/vertical_slider.rs | 87 |
1 files changed, 50 insertions, 37 deletions
diff --git a/native/src/widget/vertical_slider.rs b/native/src/widget/vertical_slider.rs index f1687e38..3a8c30b6 100644 --- a/native/src/widget/vertical_slider.rs +++ b/native/src/widget/vertical_slider.rs @@ -8,8 +8,8 @@ pub use iced_style::slider::{Appearance, Handle, HandleShape, StyleSheet}; use crate::event::{self, Event}; use crate::widget::tree::{self, Tree}; use crate::{ - layout, mouse, renderer, touch, Background, Clipboard, Color, Element, - Layout, Length, Pixels, Point, Rectangle, Shell, Size, Widget, + layout, mouse, renderer, touch, Clipboard, Element, Layout, Length, Pixels, + Point, Rectangle, Shell, Size, Widget, }; /// An vertical bar and a handle that selects a single value from a range of @@ -363,38 +363,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 @@ -413,18 +381,63 @@ 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) / (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; + + renderer.fill_quad( + renderer::Quad { + bounds: Rectangle { + x: line_x, + y: bounds.y, + width: style.rail.size, + height: line_offset, + }, + border_radius: [ + style.rail.border_radius, + style.rail.border_radius, + 0.0, + 0.0, + ] + .into(), + border_width: style.rail.border_width, + border_color: style.rail.border_color, + }, + style.rail.colors.1, + ); + + renderer.fill_quad( + renderer::Quad { + bounds: Rectangle { + x: line_x, + y: bounds.y + line_offset.round(), + width: style.rail.size, + height: bounds.height - line_offset, + }, + border_radius: [ + 0.0, + 0.0, + style.rail.border_radius, + style.rail.border_radius, + ] + .into(), + border_width: style.rail.border_width, + border_color: style.rail.border_color, + }, + 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: bounds.x + bounds.width / 2.0 - handle_height / 2.0, + y: bounds.y + offset.round(), width: handle_height, height: handle_width, }, |