Add height method to Slider

This commit is contained in:
Héctor Ramón Jiménez 2020-08-01 08:18:52 +02:00
parent 72cfe85f7f
commit 9ba4cfd23f
3 changed files with 29 additions and 24 deletions

View file

@ -19,17 +19,13 @@ pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet};
pub type Slider<'a, T, Message, Backend> =
iced_native::Slider<'a, T, Message, Renderer<Backend>>;
const HANDLE_HEIGHT: f32 = 22.0;
impl<B> slider::Renderer for Renderer<B>
where
B: Backend,
{
type Style = Box<dyn StyleSheet>;
fn height(&self) -> u32 {
30
}
const DEFAULT_HEIGHT: u16 = 22;
fn draw(
&mut self,
@ -81,16 +77,18 @@ where
let (range_start, range_end) = range.into_inner();
let (handle_width, handle_height, handle_border_radius) =
match style.handle.shape {
HandleShape::Circle { radius } => {
(f32::from(radius * 2), f32::from(radius * 2), radius)
}
HandleShape::Rectangle {
width,
border_radius,
} => (f32::from(width), HANDLE_HEIGHT, border_radius),
};
let (handle_width, handle_height, handle_border_radius) = match style
.handle
.shape
{
HandleShape::Circle { radius } => {
(f32::from(radius * 2), f32::from(radius * 2), radius)
}
HandleShape::Rectangle {
width,
border_radius,
} => (f32::from(width), f32::from(bounds.height), border_radius),
};
let handle_offset = (bounds.width - handle_width)
* ((value - range_start) / (range_end - range_start).max(1.0));