allow for centering on box layout
This commit is contained in:
parent
8b56dcd3dd
commit
f4fcca122b
2 changed files with 16 additions and 2 deletions
|
@ -118,7 +118,11 @@ int box_layout_handle(UINode *component, enum UIEvent ev, size_t d, void *p)
|
|||
x += gap;
|
||||
}
|
||||
current->rect.x = x;
|
||||
if (box_layout_node->justify_secondary_dimension == UI_BOX_LAYOUT_JUSTIFY_CENTER) {
|
||||
current->rect.y = margin_top + (maximum_secondary_position - current->rect.h) / 2;
|
||||
} else {
|
||||
current->rect.y = y;
|
||||
}
|
||||
x += current->rect.w;
|
||||
} else {
|
||||
if (current->height_policy == UI_SIZE_POLICY_GROW) {
|
||||
|
@ -130,7 +134,11 @@ int box_layout_handle(UINode *component, enum UIEvent ev, size_t d, void *p)
|
|||
if (current_index) {
|
||||
y += gap;
|
||||
}
|
||||
if (box_layout_node->justify_secondary_dimension == UI_BOX_LAYOUT_JUSTIFY_CENTER) {
|
||||
current->rect.x = margin_left + (maximum_secondary_position - current->rect.w) / 2;
|
||||
} else {
|
||||
current->rect.x = x;
|
||||
}
|
||||
current->rect.y = y;
|
||||
y += current->rect.h;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,15 @@
|
|||
|
||||
#include "node.h"
|
||||
|
||||
enum UIBoxLayoutJustify {
|
||||
UI_BOX_LAYOUT_JUSTIFY_START,
|
||||
UI_BOX_LAYOUT_JUSTIFY_CENTER
|
||||
};
|
||||
|
||||
typedef struct UIBoxLayoutNode {
|
||||
UINode node;
|
||||
enum UIDirection direction;
|
||||
enum UIBoxLayoutJustify justify_secondary_dimension;
|
||||
double margin_top, margin_left, margin_bottom, margin_right, gap;
|
||||
} UIBoxLayoutNode;
|
||||
|
||||
|
|
Loading…
Reference in a new issue