Add support for asymmetrical padding

This commit is contained in:
Ben LeFevre 2020-11-23 17:19:21 +00:00 committed by Héctor Ramón
parent a9eb591628
commit fe0a27c56d
27 changed files with 339 additions and 195 deletions

View file

@ -5,7 +5,8 @@ use crate::event::{self, Event};
use crate::layout;
use crate::overlay;
use crate::{
Align, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Widget,
Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
Rectangle, Widget,
};
use std::u32;
@ -14,7 +15,7 @@ use std::u32;
#[allow(missing_debug_implementations)]
pub struct Column<'a, Message, Renderer> {
spacing: u16,
padding: u16,
padding: Padding,
width: Length,
height: Length,
max_width: u32,
@ -35,7 +36,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
) -> Self {
Column {
spacing: 0,
padding: 0,
padding: Padding::ZERO,
width: Length::Shrink,
height: Length::Shrink,
max_width: u32::MAX,
@ -55,9 +56,14 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
self
}
/// Sets the padding of the [`Column`].
pub fn padding(mut self, units: u16) -> Self {
self.padding = units;
/// Sets the [`Padding`] of the [`Column`].
///```ignore
/// Column::new(/*...*/).padding(20); // 20px on all sides
/// Column::new(/*...*/).padding([10, 20]); // top/bottom, left/right
/// Column::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
}
@ -129,7 +135,7 @@ where
layout::flex::Axis::Vertical,
renderer,
&limits,
self.padding as f32,
self.padding,
self.spacing as f32,
self.align_items,
&self.children,