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,15 +77,17 @@ where
let (range_start, range_end) = range.into_inner();
let (handle_width, handle_height, handle_border_radius) =
match style.handle.shape {
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),
} => (f32::from(width), f32::from(bounds.height), border_radius),
};
let handle_offset = (bounds.width - handle_width)

View File

@ -197,9 +197,7 @@ impl checkbox::Renderer for Null {
impl slider::Renderer for Null {
type Style = ();
fn height(&self) -> u32 {
30
}
const DEFAULT_HEIGHT: u16 = 30;
fn draw(
&mut self,

View File

@ -46,6 +46,7 @@ pub struct Slider<'a, T, Message, Renderer: self::Renderer> {
on_change: Box<dyn Fn(T) -> Message>,
on_release: Option<Message>,
width: Length,
height: u16,
style: Renderer::Style,
}
@ -95,6 +96,7 @@ where
on_change: Box::new(on_change),
on_release: None,
width: Length::Fill,
height: Renderer::DEFAULT_HEIGHT,
style: Renderer::Style::default(),
}
}
@ -120,6 +122,14 @@ where
self
}
/// Sets the height of the [`Slider`].
///
/// [`Slider`]: struct.Slider.html
pub fn height(mut self, height: u16) -> Self {
self.height = height;
self
}
/// Sets the style of the [`Slider`].
///
/// [`Slider`]: struct.Slider.html
@ -171,12 +181,11 @@ where
fn layout(
&self,
renderer: &Renderer,
_renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
let limits = limits
.width(self.width)
.height(Length::Units(renderer.height() as u16));
let limits =
limits.width(self.width).height(Length::Units(self.height));
let size = limits.resolve(Size::ZERO);
@ -281,10 +290,10 @@ pub trait Renderer: crate::Renderer {
/// The style supported by this renderer.
type Style: Default;
/// Returns the height of the [`Slider`].
/// The default height of a [`Slider`].
///
/// [`Slider`]: struct.Slider.html
fn height(&self) -> u32;
const DEFAULT_HEIGHT: u16;
/// Draws a [`Slider`].
///