Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2017-01-10 18:19:10 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2017-01-10 18:24:22 +0300
commitda026249abbe058321f815a9ac39c92761e405ea (patch)
treefd05dad414933bae3834ff97dc2161155d987f47 /source/blender/editors/interface/interface_layout.c
parentd5cf90f59f7f416663963bca0d765f4a5c615a9b (diff)
UI Layout: fix some cases mixing fixed and expandable sizes
When layout has only small buttons (buttons with icon and without label) its size should be fixed. Code was modified to be able to add a new UI_ITEM_MIN flag which indicates that the layout has only small fixed-width buttons. Patch by @raa, with minor style edits by @mont29. Reviewers: Severin, mont29 Reviewed By: mont29 Tags: #bf_blender, #user_interface Differential Revision: https://developer.blender.org/D2423
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r--source/blender/editors/interface/interface_layout.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 940e982d326..b02a909d009 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -125,6 +125,11 @@ typedef struct uiItem {
int flag;
} uiItem;
+enum {
+ UI_ITEM_FIXED = 1 << 0,
+ UI_ITEM_MIN = 1 << 1,
+};
+
typedef struct uiButtonItem {
uiItem item;
uiBut *but;
@@ -232,6 +237,7 @@ static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool
variable = (ui_layout_vary_direction(layout) == UI_ITEM_VARY_X);
if (variable) {
+ layout->item.flag |= UI_ITEM_MIN;
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
/* it may seem odd that the icon only adds (UI_UNIT_X / 4)
* but taking margins into account its fine */
@@ -2060,6 +2066,7 @@ static void ui_litem_estimate_row(uiLayout *litem)
{
uiItem *item;
int itemw, itemh;
+ bool min_size_flag = true;
litem->w = 0;
litem->h = 0;
@@ -2067,12 +2074,26 @@ static void ui_litem_estimate_row(uiLayout *litem)
for (item = litem->items.first; item; item = item->next) {
ui_item_size(item, &itemw, &itemh);
+ if (item->type == ITEM_BUTTON) {
+ const uiBut *but = ((uiButtonItem *)item)->but;
+ const bool icon_only = (but->flag & UI_HAS_ICON) && (but->str == NULL || but->str[0] == '\0');
+
+ min_size_flag = min_size_flag && icon_only;
+ }
+ else {
+ min_size_flag = min_size_flag && (item->flag & UI_ITEM_MIN);
+ }
+
litem->w += itemw;
litem->h = MAX2(itemh, litem->h);
if (item->next)
litem->w += litem->space;
}
+
+ if (min_size_flag) {
+ litem->item.flag |= UI_ITEM_MIN;
+ }
}
static int ui_litem_min_width(int itemw)
@@ -2113,7 +2134,7 @@ static void ui_litem_layout_row(uiLayout *litem)
newtotw = totw;
for (item = litem->items.first; item; item = item->next) {
- if (item->flag)
+ if (item->flag & UI_ITEM_FIXED)
continue;
ui_item_size(item, &itemw, &itemh);
@@ -2126,16 +2147,19 @@ static void ui_litem_layout_row(uiLayout *litem)
x += neww;
- if ((neww < minw || itemw == minw) && w != 0) {
+ if ((neww < minw || itemw == minw || item->flag & UI_ITEM_MIN) && w != 0) {
/* fixed size */
- item->flag = 1;
+ item->flag |= UI_ITEM_FIXED;
+ if (item->type != ITEM_BUTTON && item->flag & UI_ITEM_MIN) {
+ minw = itemw;
+ }
fixedw += minw;
flag = 1;
newtotw -= itemw;
}
else {
/* keep free size */
- item->flag = 0;
+ item->flag &= ~UI_ITEM_FIXED;
freew += itemw;
}
}
@@ -2152,8 +2176,11 @@ static void ui_litem_layout_row(uiLayout *litem)
ui_item_size(item, &itemw, &itemh);
minw = ui_litem_min_width(itemw);
- if (item->flag) {
+ if (item->flag & UI_ITEM_FIXED) {
/* fixed minimum size items */
+ 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);
fixedx += itemw;
}
@@ -2193,6 +2220,7 @@ static void ui_litem_estimate_column(uiLayout *litem)
{
uiItem *item;
int itemw, itemh;
+ bool min_size_flag = true;
litem->w = 0;
litem->h = 0;
@@ -2200,12 +2228,26 @@ static void ui_litem_estimate_column(uiLayout *litem)
for (item = litem->items.first; item; item = item->next) {
ui_item_size(item, &itemw, &itemh);
+ if (item->type == ITEM_BUTTON) {
+ const uiBut *but = ((uiButtonItem *)item)->but;
+ const bool icon_only = (but->flag & UI_HAS_ICON) && (but->str == NULL || but->str[0] == '\0');
+
+ min_size_flag = min_size_flag && icon_only;
+ }
+ else {
+ min_size_flag = min_size_flag && (item->flag & UI_ITEM_MIN);
+ }
+
litem->w = MAX2(litem->w, itemw);
litem->h += itemh;
if (item->next)
litem->h += litem->space;
}
+
+ if (min_size_flag) {
+ litem->item.flag |= UI_ITEM_MIN;
+ }
}
static void ui_litem_layout_column(uiLayout *litem)