Add support for asymmetrical padding
This commit is contained in:
parent
a9eb591628
commit
fe0a27c56d
27 changed files with 339 additions and 195 deletions
|
|
@ -8,8 +8,8 @@ use crate::scrollable;
|
|||
use crate::text;
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
Clipboard, Container, Element, Hasher, Layout, Length, Point, Rectangle,
|
||||
Scrollable, Size, Vector, Widget,
|
||||
Clipboard, Container, Element, Hasher, Layout, Length, Padding, Point,
|
||||
Rectangle, Scrollable, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
/// A list of selectable options.
|
||||
|
|
@ -20,7 +20,7 @@ pub struct Menu<'a, T, Renderer: self::Renderer> {
|
|||
hovered_option: &'a mut Option<usize>,
|
||||
last_selection: &'a mut Option<T>,
|
||||
width: u16,
|
||||
padding: u16,
|
||||
padding: Padding,
|
||||
text_size: Option<u16>,
|
||||
font: Renderer::Font,
|
||||
style: <Renderer as self::Renderer>::Style,
|
||||
|
|
@ -45,7 +45,7 @@ where
|
|||
hovered_option,
|
||||
last_selection,
|
||||
width: 0,
|
||||
padding: 0,
|
||||
padding: Padding::ZERO,
|
||||
text_size: None,
|
||||
font: Default::default(),
|
||||
style: Default::default(),
|
||||
|
|
@ -58,9 +58,14 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the padding of the [`Menu`].
|
||||
pub fn padding(mut self, padding: u16) -> Self {
|
||||
self.padding = padding;
|
||||
/// Sets the [`Padding`] of the [`Menu`].
|
||||
///```ignore
|
||||
/// Menu::new(/*...*/).padding(20); // 20px on all sides
|
||||
/// Menu::new(/*...*/).padding([10, 20]); // top/bottom, left/right
|
||||
/// Menu::new(/*...*/).padding([5, 10, 15, 20]); // top, right, bottom, left
|
||||
/// ```
|
||||
pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
|
||||
self.padding = padding.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -261,7 +266,7 @@ struct List<'a, T, Renderer: self::Renderer> {
|
|||
options: &'a [T],
|
||||
hovered_option: &'a mut Option<usize>,
|
||||
last_selection: &'a mut Option<T>,
|
||||
padding: u16,
|
||||
padding: Padding,
|
||||
text_size: Option<u16>,
|
||||
font: Renderer::Font,
|
||||
style: <Renderer as self::Renderer>::Style,
|
||||
|
|
@ -294,7 +299,7 @@ where
|
|||
let size = {
|
||||
let intrinsic = Size::new(
|
||||
0.0,
|
||||
f32::from(text_size + self.padding * 2)
|
||||
f32::from(text_size + self.padding.top + self.padding.bottom)
|
||||
* self.options.len() as f32,
|
||||
);
|
||||
|
||||
|
|
@ -359,8 +364,11 @@ where
|
|||
|
||||
*self.hovered_option = Some(
|
||||
((cursor_position.y - bounds.y)
|
||||
/ f32::from(text_size + self.padding * 2))
|
||||
as usize,
|
||||
/ f32::from(
|
||||
text_size
|
||||
+ self.padding.top
|
||||
+ self.padding.bottom,
|
||||
)) as usize,
|
||||
);
|
||||
|
||||
if let Some(index) = *self.hovered_option {
|
||||
|
|
@ -430,7 +438,7 @@ pub trait Renderer:
|
|||
viewport: &Rectangle,
|
||||
options: &[T],
|
||||
hovered_option: Option<usize>,
|
||||
padding: u16,
|
||||
padding: Padding,
|
||||
text_size: u16,
|
||||
font: Self::Font,
|
||||
style: &<Self as Renderer>::Style,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue