Fix padding and align calculation for box layouts

This commit is contained in:
raa 2017-03-26 18:02:11 +03:00
parent 2830f687aa
commit 505b3b7328

@ -2262,7 +2262,7 @@ static void ui_litem_layout_row(uiLayout *litem)
} }
/* single-column layout */ /* single-column layout */
static void ui_litem_estimate_column(uiLayout *litem) static void ui_litem_estimate_column(uiLayout *litem, bool is_box)
{ {
uiItem *item; uiItem *item;
int itemw, itemh; int itemw, itemh;
@ -2276,12 +2276,12 @@ static void ui_litem_estimate_column(uiLayout *litem)
litem->w = MAX2(litem->w, itemw); litem->w = MAX2(litem->w, itemw);
litem->h += itemh; litem->h += itemh;
if (item->next) if (item->next && (!is_box || item != litem->items.first))
litem->h += litem->space; litem->h += litem->space;
} }
} }
static void ui_litem_layout_column(uiLayout *litem) static void ui_litem_layout_column(uiLayout *litem, bool is_box)
{ {
uiItem *item; uiItem *item;
int itemh, x, y; int itemh, x, y;
@ -2295,7 +2295,7 @@ static void ui_litem_layout_column(uiLayout *litem)
y -= itemh; y -= itemh;
ui_item_position(item, x, y, litem->w, itemh); ui_item_position(item, x, y, litem->w, itemh);
if (item->next) if (item->next && (!is_box || item != litem->items.first))
y -= litem->space; y -= litem->space;
} }
@ -2437,7 +2437,7 @@ static void ui_litem_layout_root(uiLayout *litem)
else if (litem->root->type == UI_LAYOUT_PIEMENU) else if (litem->root->type == UI_LAYOUT_PIEMENU)
ui_litem_layout_root_radial(litem); ui_litem_layout_root_radial(litem);
else else
ui_litem_layout_column(litem); ui_litem_layout_column(litem, false);
} }
/* box layout */ /* box layout */
@ -2445,9 +2445,9 @@ static void ui_litem_estimate_box(uiLayout *litem)
{ {
uiStyle *style = litem->root->style; uiStyle *style = litem->root->style;
ui_litem_estimate_column(litem); ui_litem_estimate_column(litem, true);
litem->w += 2 * style->boxspace; litem->w += 2 * style->boxspace;
litem->h += style->boxspace; litem->h += 2 * style->boxspace;
} }
static void ui_litem_layout_box(uiLayout *litem) static void ui_litem_layout_box(uiLayout *litem)
@ -2461,17 +2461,18 @@ static void ui_litem_layout_box(uiLayout *litem)
h = litem->h; h = litem->h;
litem->x += style->boxspace; litem->x += style->boxspace;
litem->y -= style->boxspace;
if (w != 0) litem->w -= 2 * style->boxspace; if (w != 0) litem->w -= 2 * style->boxspace;
if (h != 0) litem->h -= 2 * style->boxspace; if (h != 0) litem->h -= 2 * style->boxspace;
ui_litem_layout_column(litem); ui_litem_layout_column(litem, true);
litem->x -= style->boxspace; litem->x -= style->boxspace;
litem->y -= style->boxspace; litem->y -= style->boxspace;
if (w != 0) litem->w += 2 * style->boxspace; if (w != 0) litem->w += 2 * style->boxspace;
if (h != 0) litem->h += style->boxspace; if (h != 0) litem->h += 2 * style->boxspace;
/* roundbox around the sublayout */ /* roundbox around the sublayout */
but = box->roundbox; but = box->roundbox;
@ -3124,7 +3125,7 @@ static void ui_item_estimate(uiItem *item)
switch (litem->item.type) { switch (litem->item.type) {
case ITEM_LAYOUT_COLUMN: case ITEM_LAYOUT_COLUMN:
ui_litem_estimate_column(litem); ui_litem_estimate_column(litem, false);
break; break;
case ITEM_LAYOUT_COLUMN_FLOW: case ITEM_LAYOUT_COLUMN_FLOW:
ui_litem_estimate_column_flow(litem); ui_litem_estimate_column_flow(litem);
@ -3179,8 +3180,10 @@ static void ui_item_align(uiLayout *litem, short nr)
} }
else if (item->type == ITEM_LAYOUT_BOX) { else if (item->type == ITEM_LAYOUT_BOX) {
box = (uiLayoutItemBx *)item; box = (uiLayoutItemBx *)item;
if (!box->roundbox->alignnr) {
box->roundbox->alignnr = nr; box->roundbox->alignnr = nr;
} }
}
else if (((uiLayout *)item)->align) { else if (((uiLayout *)item)->align) {
ui_item_align((uiLayout *)item, nr); ui_item_align((uiLayout *)item, nr);
} }
@ -3221,7 +3224,7 @@ static void ui_item_layout(uiItem *item)
switch (litem->item.type) { switch (litem->item.type) {
case ITEM_LAYOUT_COLUMN: case ITEM_LAYOUT_COLUMN:
ui_litem_layout_column(litem); ui_litem_layout_column(litem, false);
break; break;
case ITEM_LAYOUT_COLUMN_FLOW: case ITEM_LAYOUT_COLUMN_FLOW:
ui_litem_layout_column_flow(litem); ui_litem_layout_column_flow(litem);