Fix rows with fixed last item (D2524)
This commit is contained in:
@@ -189,7 +189,7 @@ static const char *ui_item_name_add_colon(const char *name, char namestr[UI_MAX_
|
||||
return name;
|
||||
}
|
||||
|
||||
static int ui_item_fit(int item, int pos, int all, int available, bool is_last, int alignment)
|
||||
static int ui_item_fit(int item, int pos, int all, int available, bool is_last, int alignment, float *extra_pixel)
|
||||
{
|
||||
/* available == 0 is unlimited */
|
||||
if (available == 0)
|
||||
@@ -199,16 +199,22 @@ static int ui_item_fit(int item, int pos, int all, int available, bool is_last,
|
||||
/* contents is bigger than available space */
|
||||
if (is_last)
|
||||
return available - pos;
|
||||
else
|
||||
return (item * available) / all;
|
||||
else {
|
||||
float width = *extra_pixel + (item * available) / (float)all;
|
||||
*extra_pixel = width - (int)width;
|
||||
return (int)width;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* contents is smaller or equal to available space */
|
||||
if (alignment == UI_LAYOUT_ALIGN_EXPAND) {
|
||||
if (is_last)
|
||||
return available - pos;
|
||||
else
|
||||
return (item * available) / all;
|
||||
else {
|
||||
float width = *extra_pixel + (item * available) / (float)all;
|
||||
*extra_pixel = width - (int)width;
|
||||
return (int)width;
|
||||
}
|
||||
}
|
||||
else
|
||||
return item;
|
||||
@@ -302,6 +308,26 @@ static void ui_item_position(uiItem *item, int x, int y, int w, int h)
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_item_move(uiItem *item, int delta_xmin, int delta_xmax)
|
||||
{
|
||||
if (item->type == ITEM_BUTTON) {
|
||||
uiButtonItem *bitem = (uiButtonItem *)item;
|
||||
|
||||
bitem->but->rect.xmin += delta_xmin;
|
||||
bitem->but->rect.xmax += delta_xmax;
|
||||
|
||||
ui_but_update(bitem->but); /* for strlen */
|
||||
}
|
||||
else {
|
||||
uiLayout *litem = (uiLayout *)item;
|
||||
|
||||
if (delta_xmin > 0)
|
||||
litem->x += delta_xmin;
|
||||
else
|
||||
litem->w += delta_xmax;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** Special RNA Items *********************/
|
||||
|
||||
static int ui_layout_local_dir(uiLayout *layout)
|
||||
@@ -2099,9 +2125,10 @@ static int ui_litem_min_width(int itemw)
|
||||
|
||||
static void ui_litem_layout_row(uiLayout *litem)
|
||||
{
|
||||
uiItem *item;
|
||||
uiItem *item, *last_free_item = NULL;
|
||||
int x, y, w, tot, totw, neww, newtotw, itemw, minw, itemh, offset;
|
||||
int fixedw, freew, fixedx, freex, flag = 0, lastw = 0;
|
||||
float extra_pixel;
|
||||
|
||||
/* x = litem->x; */ /* UNUSED */
|
||||
y = litem->y;
|
||||
@@ -2128,6 +2155,7 @@ static void ui_litem_layout_row(uiLayout *litem)
|
||||
x = 0;
|
||||
flag = 0;
|
||||
newtotw = totw;
|
||||
extra_pixel = 0.0f;
|
||||
|
||||
for (item = litem->items.first; item; item = item->next) {
|
||||
if (item->flag & UI_ITEM_FIXED)
|
||||
@@ -2137,7 +2165,7 @@ static void ui_litem_layout_row(uiLayout *litem)
|
||||
minw = ui_litem_min_width(itemw);
|
||||
|
||||
if (w - lastw > 0)
|
||||
neww = ui_item_fit(itemw, x, totw, w - lastw, !item->next, litem->alignment);
|
||||
neww = ui_item_fit(itemw, x, totw, w - lastw, !item->next, litem->alignment, &extra_pixel);
|
||||
else
|
||||
neww = 0; /* no space left, all will need clamping to minimum size */
|
||||
|
||||
@@ -2166,6 +2194,7 @@ static void ui_litem_layout_row(uiLayout *litem)
|
||||
|
||||
freex = 0;
|
||||
fixedx = 0;
|
||||
extra_pixel = 0.0f;
|
||||
x = litem->x;
|
||||
|
||||
for (item = litem->items.first; item; item = item->next) {
|
||||
@@ -2177,13 +2206,14 @@ static void ui_litem_layout_row(uiLayout *litem)
|
||||
if (item->type != ITEM_BUTTON && item->flag & UI_ITEM_MIN) {
|
||||
minw = itemw;
|
||||
}
|
||||
itemw = ui_item_fit(minw, fixedx, fixedw, min_ii(w, fixedw), !item->next, litem->alignment);
|
||||
itemw = ui_item_fit(minw, fixedx, fixedw, min_ii(w, fixedw), !item->next, litem->alignment, &extra_pixel);
|
||||
fixedx += itemw;
|
||||
}
|
||||
else {
|
||||
/* free size item */
|
||||
itemw = ui_item_fit(itemw, freex, freew, w - fixedw, !item->next, litem->alignment);
|
||||
itemw = ui_item_fit(itemw, freex, freew, w - fixedw, !item->next, litem->alignment, &extra_pixel);
|
||||
freex += itemw;
|
||||
last_free_item = item;
|
||||
}
|
||||
|
||||
/* align right/center */
|
||||
@@ -2205,6 +2235,16 @@ static void ui_litem_layout_row(uiLayout *litem)
|
||||
x += litem->space;
|
||||
}
|
||||
|
||||
/* add extra pixel */
|
||||
uiItem *last_item = litem->items.last;
|
||||
extra_pixel = litem->w - (x - litem->x);
|
||||
if (extra_pixel > 0 && litem->alignment == UI_LAYOUT_ALIGN_EXPAND &&
|
||||
last_free_item && last_item && last_item->flag & UI_ITEM_FIXED) {
|
||||
ui_item_move(last_free_item, 0, extra_pixel);
|
||||
for (item = last_free_item->next; item; item = item->next)
|
||||
ui_item_move(item, extra_pixel, extra_pixel);
|
||||
}
|
||||
|
||||
litem->w = x - litem->x;
|
||||
litem->h = litem->y - y;
|
||||
litem->x = x;
|
||||
|
||||
Reference in New Issue
Block a user