From f52a15009bbe80c9c9b038fa34e89054082aa6d2 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 25 Mar 2024 14:14:12 +0100 Subject: [PATCH] fix gap/padding layout (kinda) for remaining size --- hui-examples/examples/vscode_layout.rs | 11 ++--------- hui/src/element/builtin/container.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/hui-examples/examples/vscode_layout.rs b/hui-examples/examples/vscode_layout.rs index 7620c98..9415034 100644 --- a/hui-examples/examples/vscode_layout.rs +++ b/hui-examples/examples/vscode_layout.rs @@ -4,7 +4,6 @@ use hui::{ color, size, draw::{ImageHandle, TextureFormat}, layout::{Alignment, Direction}, - rect::Sides, element::{ container::Container, fill_rect::FillRect, @@ -39,12 +38,7 @@ ui_main!( .with_size(size!(100%, auto)) .with_direction(Direction::Horizontal) .with_align((Alignment::Begin, Alignment::Center)) - .with_padding(Sides { - left: 5., - right: 0., - top: 5., - bottom: 5., - }) + .with_padding(5.) .with_gap(15.) .with_background(color::rgb_hex(0x3d3c3e)) .with_wrap(true) //XXX: not authentic but great for demostration @@ -58,8 +52,7 @@ ui_main!( .add_child(ui); } Container::default() - //HACK: due to a bug in the layout system, 100%= doesn't work as expected - .with_size(size!(94%=, 100%)) + .with_size(size!(100%=, 100%)) .with_align((Alignment::End, Alignment::Center)) .with_children(|ui| { Text::new("- ×") diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index 403e9dc..2eec01c 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -224,9 +224,10 @@ impl UiElement for Container { { let last_line = lines.last_mut().unwrap(); last_line.content_size = line_size; - last_line.remaining_space = max_line_pri - match self.direction { - Direction::Horizontal => line_size.x, - Direction::Vertical => line_size.y, + //HACK: why? - self.gap, may be different for the last element or if it's the only element in the line + last_line.remaining_space = max_line_pri - self.gap - match self.direction { + Direction::Horizontal => line_size.x + self.padding.left + self.padding.right, + Direction::Vertical => line_size.y + self.padding.top + self.padding.bottom, }; } @@ -286,11 +287,12 @@ impl UiElement for Container { //Update the content size of the last line { + //HACK: why? - self.gap, may be different for the last element or if it's the only element in the line let cur_line = lines.last_mut().unwrap(); cur_line.content_size = line_size; - cur_line.remaining_space = max_line_pri - match self.direction { - Direction::Horizontal => line_size.x, - Direction::Vertical => line_size.y, + cur_line.remaining_space = max_line_pri - self.gap - match self.direction { + Direction::Horizontal => line_size.x + self.padding.left + self.padding.right, + Direction::Vertical => line_size.y + self.padding.top + self.padding.bottom, }; }