mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-25 00:18:41 -06:00
fix gap/padding layout (kinda) for remaining size
This commit is contained in:
parent
3c6e6be754
commit
c1be9bf22b
|
@ -4,7 +4,6 @@ use hui::{
|
||||||
color, size,
|
color, size,
|
||||||
draw::{ImageHandle, TextureFormat},
|
draw::{ImageHandle, TextureFormat},
|
||||||
layout::{Alignment, Direction},
|
layout::{Alignment, Direction},
|
||||||
rect::Sides,
|
|
||||||
element::{
|
element::{
|
||||||
container::Container,
|
container::Container,
|
||||||
fill_rect::FillRect,
|
fill_rect::FillRect,
|
||||||
|
@ -39,12 +38,7 @@ ui_main!(
|
||||||
.with_size(size!(100%, auto))
|
.with_size(size!(100%, auto))
|
||||||
.with_direction(Direction::Horizontal)
|
.with_direction(Direction::Horizontal)
|
||||||
.with_align((Alignment::Begin, Alignment::Center))
|
.with_align((Alignment::Begin, Alignment::Center))
|
||||||
.with_padding(Sides {
|
.with_padding(5.)
|
||||||
left: 5.,
|
|
||||||
right: 0.,
|
|
||||||
top: 5.,
|
|
||||||
bottom: 5.,
|
|
||||||
})
|
|
||||||
.with_gap(15.)
|
.with_gap(15.)
|
||||||
.with_background(color::rgb_hex(0x3d3c3e))
|
.with_background(color::rgb_hex(0x3d3c3e))
|
||||||
.with_wrap(true) //XXX: not authentic but great for demostration
|
.with_wrap(true) //XXX: not authentic but great for demostration
|
||||||
|
@ -58,8 +52,7 @@ ui_main!(
|
||||||
.add_child(ui);
|
.add_child(ui);
|
||||||
}
|
}
|
||||||
Container::default()
|
Container::default()
|
||||||
//HACK: due to a bug in the layout system, 100%= doesn't work as expected
|
.with_size(size!(100%=, 100%))
|
||||||
.with_size(size!(94%=, 100%))
|
|
||||||
.with_align((Alignment::End, Alignment::Center))
|
.with_align((Alignment::End, Alignment::Center))
|
||||||
.with_children(|ui| {
|
.with_children(|ui| {
|
||||||
Text::new("- ×")
|
Text::new("- ×")
|
||||||
|
|
|
@ -224,9 +224,10 @@ impl UiElement for Container {
|
||||||
{
|
{
|
||||||
let last_line = lines.last_mut().unwrap();
|
let last_line = lines.last_mut().unwrap();
|
||||||
last_line.content_size = line_size;
|
last_line.content_size = line_size;
|
||||||
last_line.remaining_space = max_line_pri - match self.direction {
|
//HACK: why? - self.gap, may be different for the last element or if it's the only element in the line
|
||||||
Direction::Horizontal => line_size.x,
|
last_line.remaining_space = max_line_pri - self.gap - match self.direction {
|
||||||
Direction::Vertical => line_size.y,
|
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
|
//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();
|
let cur_line = lines.last_mut().unwrap();
|
||||||
cur_line.content_size = line_size;
|
cur_line.content_size = line_size;
|
||||||
cur_line.remaining_space = max_line_pri - match self.direction {
|
cur_line.remaining_space = max_line_pri - self.gap - match self.direction {
|
||||||
Direction::Horizontal => line_size.x,
|
Direction::Horizontal => line_size.x + self.padding.left + self.padding.right,
|
||||||
Direction::Vertical => line_size.y,
|
Direction::Vertical => line_size.y + self.padding.top + self.padding.bottom,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue