[ui, styling] finished first pass on core layout/styling system

This commit is contained in:
Martin Fouilleul 2023-03-07 19:27:01 +01:00
parent 8032c7340b
commit 2466241b1e
2 changed files with 10 additions and 9 deletions

View File

@ -301,7 +301,7 @@ int main()
} }
ui_style_next(ui_pattern_owner(), ui_style_next(ui_pattern_owner(),
&(ui_style){.size.width = {UI_SIZE_PIXELS, 200, 0}, &(ui_style){.size.width = {UI_SIZE_PARENT, 1},
.size.height = {UI_SIZE_PIXELS, 20, 0}}, .size.height = {UI_SIZE_PIXELS, 20, 0}},
UI_STYLE_SIZE_X|UI_STYLE_SIZE_Y); UI_STYLE_SIZE_X|UI_STYLE_SIZE_Y);
static f32 slider1 = 0; static f32 slider1 = 0;
@ -309,15 +309,15 @@ int main()
ui_style_next(ui_pattern_owner(), ui_style_next(ui_pattern_owner(),
&(ui_style){.size.width = {UI_SIZE_PIXELS, 200, 0}, &(ui_style){.size.width = {UI_SIZE_PARENT, 1},
.size.height = {UI_SIZE_PIXELS, 20, 0}}, .size.height = {UI_SIZE_PIXELS, 20, 0}},
UI_STYLE_SIZE_X|UI_STYLE_SIZE_Y); UI_STYLE_SIZE_X|UI_STYLE_SIZE_Y);
static f32 slider2 = 0; static f32 slider2 = 0;
ui_slider("slider2", 0.3, &slider2); ui_slider("slider2", 0.3, &slider2);
ui_style_next(ui_pattern_owner(), ui_style_next(ui_pattern_owner(),
&(ui_style){.size.width = {UI_SIZE_PIXELS, 200, 0}, &(ui_style){.size.width = {UI_SIZE_PARENT, 1},
.size.height = {UI_SIZE_PIXELS, 20, 0}}, .size.height = {UI_SIZE_PIXELS, 20}},
UI_STYLE_SIZE_X|UI_STYLE_SIZE_Y); UI_STYLE_SIZE_X|UI_STYLE_SIZE_Y);
static f32 slider3 = 0; static f32 slider3 = 0;
ui_slider("slider3", 0.3, &slider3); ui_slider("slider3", 0.3, &slider3);

View File

@ -987,7 +987,8 @@ void ui_styling_prepass(ui_context* ui, ui_box* box, list_info* before, list_inf
if(size.kind == UI_SIZE_TEXT) if(size.kind == UI_SIZE_TEXT)
{ {
box->rect.c[2+i] = textBox.c[2+i] + desiredSize[i].value*2; f32 margin = style->layout.margin.m[i];
box->rect.c[2+i] = textBox.c[2+i] + margin*2;
} }
else if(size.kind == UI_SIZE_PIXELS) else if(size.kind == UI_SIZE_PIXELS)
{ {
@ -1024,8 +1025,7 @@ void ui_layout_upward_dependent_size(ui_context* ui, ui_box* box, int axis)
if(size->kind == UI_SIZE_PARENT) if(size->kind == UI_SIZE_PARENT)
{ {
ui_box* parent = box->parent; ui_box* parent = box->parent;
if( parent if(parent)
&& parent->style.size.s[axis].kind != UI_SIZE_CHILDREN)
{ {
f32 margin = parent->style.layout.margin.m[axis]; f32 margin = parent->style.layout.margin.m[axis];
box->rect.c[2+axis] = maximum(0, parent->rect.c[2+axis] - 2*margin) * size->value; box->rect.c[2+axis] = maximum(0, parent->rect.c[2+axis] - 2*margin) * size->value;
@ -1051,8 +1051,9 @@ void ui_layout_downward_dependent_size(ui_context* ui, ui_box* box, int axis)
if(!ui_box_hidden(child)) if(!ui_box_hidden(child))
{ {
ui_layout_downward_dependent_size(ui, child, axis); ui_layout_downward_dependent_size(ui, child, axis);
if(!child->style.floating[axis]) if(!child->style.floating[axis] && child->style.size.s[axis].kind != UI_SIZE_PARENT)
{ {
//TODO: maybe log an error if child is dependant on parent
sum += child->rect.c[2+axis]; sum += child->rect.c[2+axis];
count++; count++;
} }
@ -1204,8 +1205,8 @@ void ui_solve_layout(ui_context* ui)
for(int axis=0; axis<UI_AXIS_COUNT; axis++) for(int axis=0; axis<UI_AXIS_COUNT; axis++)
{ {
ui_layout_upward_dependent_size(ui, ui->root, axis);
ui_layout_downward_dependent_size(ui, ui->root, axis); ui_layout_downward_dependent_size(ui, ui->root, axis);
ui_layout_upward_dependent_size(ui, ui->root, axis);
ui_layout_solve_conflicts(ui, ui->root, axis); ui_layout_solve_conflicts(ui, ui->root, axis);
} }
ui_layout_compute_rect(ui, ui->root, (vec2){0, 0}); ui_layout_compute_rect(ui, ui->root, (vec2){0, 0});