Use `Padding::horizontal` and `Padding::vertical` helpers

This commit is contained in:
Héctor Ramón 2021-06-01 19:21:43 +07:00
parent 2e17d7860b
commit b94cd7a2a8
5 changed files with 10 additions and 14 deletions

View File

@ -30,8 +30,8 @@ impl Size {
/// Increments the [`Size`] to account for the given padding. /// Increments the [`Size`] to account for the given padding.
pub fn pad(&self, padding: Padding) -> Self { pub fn pad(&self, padding: Padding) -> Self {
Size { Size {
width: self.width + (padding.left + padding.right) as f32, width: self.width + padding.horizontal() as f32,
height: self.height + (padding.top + padding.bottom) as f32, height: self.height + padding.vertical() as f32,
} }
} }
} }

View File

@ -53,7 +53,7 @@ where
use std::f32; use std::f32;
let is_mouse_over = bounds.contains(cursor_position); let is_mouse_over = bounds.contains(cursor_position);
let option_height = (text_size + padding.top + padding.bottom) as usize; let option_height = (text_size + padding.vertical()) as usize;
let mut primitives = Vec::new(); let mut primitives = Vec::new();
@ -72,7 +72,7 @@ where
x: bounds.x, x: bounds.x,
y: bounds.y + (option_height * i) as f32, y: bounds.y + (option_height * i) as f32,
width: bounds.width, width: bounds.width,
height: f32::from(text_size + padding.top + padding.bottom), height: f32::from(text_size + padding.vertical()),
}; };
if is_selected { if is_selected {

View File

@ -57,8 +57,7 @@ where
font: B::ICON_FONT, font: B::ICON_FONT,
size: bounds.height * style.icon_size, size: bounds.height * style.icon_size,
bounds: Rectangle { bounds: Rectangle {
x: bounds.x + bounds.width x: bounds.x + bounds.width - f32::from(padding.horizontal()),
- f32::from(padding.left + padding.right),
y: bounds.center_y(), y: bounds.center_y(),
..bounds ..bounds
}, },

View File

@ -119,8 +119,8 @@ impl Limits {
/// Shrinks the current [`Limits`] to account for the given padding. /// Shrinks the current [`Limits`] to account for the given padding.
pub fn pad(&self, padding: Padding) -> Limits { pub fn pad(&self, padding: Padding) -> Limits {
self.shrink(Size::new( self.shrink(Size::new(
(padding.left + padding.right) as f32, padding.horizontal() as f32,
(padding.top + padding.bottom) as f32, padding.vertical() as f32,
)) ))
} }

View File

@ -299,7 +299,7 @@ where
let size = { let size = {
let intrinsic = Size::new( let intrinsic = Size::new(
0.0, 0.0,
f32::from(text_size + self.padding.top + self.padding.bottom) f32::from(text_size + self.padding.vertical())
* self.options.len() as f32, * self.options.len() as f32,
); );
@ -364,11 +364,8 @@ where
*self.hovered_option = Some( *self.hovered_option = Some(
((cursor_position.y - bounds.y) ((cursor_position.y - bounds.y)
/ f32::from( / f32::from(text_size + self.padding.vertical()))
text_size as usize,
+ self.padding.top
+ self.padding.bottom,
)) as usize,
); );
if let Some(index) = *self.hovered_option { if let Some(index) = *self.hovered_option {