Commit: da026249abbe058321f815a9ac39c92761e405ea
Author: Bastien Montagne
Date:   Tue Jan 10 16:19:10 2017 +0100
Branches: master
https://developer.blender.org/rBda026249abbe058321f815a9ac39c92761e405ea

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

===================================================================

M       source/blender/editors/interface/interface_layout.c

===================================================================

diff --git a/source/blender/editors/interface/interface_layout.c 
b/source/blender/editors/interface/interface_layout.c
index 940e982d32..b02a909d00 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)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to