summaryrefslogtreecommitdiffstats
path: root/native/src/overlay/menu.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-06-01 19:59:02 +0700
committerLibravatar GitHub <noreply@github.com>2021-06-01 19:59:02 +0700
commitaab2176802b6d745a7eab76ec13762b5b4ddf782 (patch)
tree3d1655b36aa8d7151c878e1879c03c8271a466a5 /native/src/overlay/menu.rs
parenta9eb591628017caaf7aa9af505d1206f7a143a9a (diff)
parent8a3b71df8b619571ce0a972826cb5a3987b66b3d (diff)
downloadiced-aab2176802b6d745a7eab76ec13762b5b4ddf782.tar.gz
iced-aab2176802b6d745a7eab76ec13762b5b4ddf782.tar.bz2
iced-aab2176802b6d745a7eab76ec13762b5b4ddf782.zip
Merge pull request #630 from blefevre/asymmetric-padding
Add support for asymmetrical padding
Diffstat (limited to '')
-rw-r--r--native/src/overlay/menu.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs
index afb17bd3..f62dcb46 100644
--- a/native/src/overlay/menu.rs
+++ b/native/src/overlay/menu.rs
@@ -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,9 @@ 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`].
+ pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
+ self.padding = padding.into();
self
}
@@ -261,7 +261,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 +294,7 @@ where
let size = {
let intrinsic = Size::new(
0.0,
- f32::from(text_size + self.padding * 2)
+ f32::from(text_size + self.padding.vertical())
* self.options.len() as f32,
);
@@ -345,7 +345,7 @@ where
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
- / f32::from(text_size + self.padding * 2))
+ / f32::from(text_size + self.padding.vertical()))
as usize,
);
}
@@ -359,7 +359,7 @@ where
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
- / f32::from(text_size + self.padding * 2))
+ / f32::from(text_size + self.padding.vertical()))
as usize,
);
@@ -430,7 +430,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,