summaryrefslogtreecommitdiffstats
path: root/native/src/widget/container.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-31 01:19:28 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-31 01:21:51 +0200
commit749a9588d738de9c3ae734e6f026768c77eb3cce (patch)
tree719597f4577c9329e738389847ff9224c2ac075d /native/src/widget/container.rs
parent6e9ab1cd6f5358d323040379e3aadbed2cc4f7f8 (diff)
downloadiced-749a9588d738de9c3ae734e6f026768c77eb3cce.tar.gz
iced-749a9588d738de9c3ae734e6f026768c77eb3cce.tar.bz2
iced-749a9588d738de9c3ae734e6f026768c77eb3cce.zip
Implement `padding` support for `Container`
Diffstat (limited to 'native/src/widget/container.rs')
-rw-r--r--native/src/widget/container.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs
index 11ef23a9..34032c3a 100644
--- a/native/src/widget/container.rs
+++ b/native/src/widget/container.rs
@@ -13,6 +13,7 @@ use std::u32;
/// It is normally used for alignment purposes.
#[allow(missing_debug_implementations)]
pub struct Container<'a, Message, Renderer: self::Renderer> {
+ padding: u16,
width: Length,
height: Length,
max_width: u32,
@@ -35,6 +36,7 @@ where
T: Into<Element<'a, Message, Renderer>>,
{
Container {
+ padding: 0,
width: Length::Shrink,
height: Length::Shrink,
max_width: u32::MAX,
@@ -46,6 +48,14 @@ where
}
}
+ /// Sets the padding of the [`Container`].
+ ///
+ /// [`Container`]: struct.Column.html
+ pub fn padding(mut self, units: u16) -> Self {
+ self.padding = units;
+ self
+ }
+
/// Sets the width of the [`Container`].
///
/// [`Container`]: struct.Container.html
@@ -137,19 +147,23 @@ where
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
+ let padding = f32::from(self.padding);
+
let limits = limits
.loose()
.max_width(self.max_width)
.max_height(self.max_height)
.width(self.width)
- .height(self.height);
+ .height(self.height)
+ .pad(padding);
let mut content = self.content.layout(renderer, &limits.loose());
let size = limits.resolve(content.size());
+ content.move_to(Point::new(padding, padding));
content.align(self.horizontal_alignment, self.vertical_alignment, size);
- layout::Node::with_children(size, vec![content])
+ layout::Node::with_children(size.pad(padding), vec![content])
}
fn on_event(
@@ -191,6 +205,7 @@ where
fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Container<'_, (), Renderer>>().hash(state);
+ self.padding.hash(state);
self.width.hash(state);
self.height.hash(state);
self.max_width.hash(state);