Skip to content

Commit 79e4047

Browse files
committed
Add BoxContainerAlignment
1 parent 6d2febc commit 79e4047

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/nodes/ui/container/box_container.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ void BoxContainer::adjust_layout() {
1515

1616
// In the first loop, we need to do some calculation.
1717
for (auto &ui_child : ui_children) {
18+
if (!ui_child->get_visibility()) {
19+
continue;
20+
}
21+
1822
if (horizontal) {
1923
if (ui_child->container_sizing.expand_h()) {
2024
expanding_children.push_back(ui_child);
@@ -42,10 +46,18 @@ void BoxContainer::adjust_layout() {
4246
uint32_t expanding_child_count = expanding_children.size();
4347

4448
// FIXME: same expanding space is not optimal.
45-
float extra_space_for_each_expanding_child = available_space_for_expanding / (float)expanding_child_count;
49+
float extra_space_for_each_expanding_child = 0;
50+
if (expanding_child_count > 0) {
51+
extra_space_for_each_expanding_child = available_space_for_expanding / (float)expanding_child_count;
52+
}
4653

4754
float pos_shift = 0;
4855

56+
// When there's at least one expanding child, the alignment doesn't matter because there's no space for it to make a difference.
57+
if (expanding_child_count == 0 && alignment == BoxContainerAlignment::End) {
58+
pos_shift = available_space_for_expanding;
59+
}
60+
4961
// In the second loop, we set child sizes and positions.
5062
for (auto &ui_child : ui_children) {
5163
auto child_min_size = ui_child->get_effective_minimum_size();
@@ -198,4 +210,8 @@ void BoxContainer::set_separation(float new_separation) {
198210
separation = new_separation;
199211
}
200212

213+
void BoxContainer::set_alignment(BoxContainerAlignment new_alignment) {
214+
alignment = new_alignment;
215+
}
216+
201217
} // namespace revector

src/nodes/ui/container/box_container.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@
44

55
namespace revector {
66

7+
enum struct BoxContainerAlignment {
8+
Begin,
9+
End,
10+
};
11+
712
class BoxContainer : public Container {
813
public:
14+
915
void adjust_layout() override;
1016

1117
void calc_minimum_size() override;
1218

1319
void set_separation(float new_separation);
1420

21+
void set_alignment(BoxContainerAlignment new_alignment);
22+
1523
protected:
1624
BoxContainer() {
1725
}
@@ -21,6 +29,8 @@ class BoxContainer : public Container {
2129

2230
/// Direction for organizing UI children.
2331
bool horizontal = true;
32+
33+
BoxContainerAlignment alignment = BoxContainerAlignment::Begin;
2434
};
2535

2636
class HBoxContainer : public BoxContainer {

0 commit comments

Comments
 (0)