[Bf-blender-cvs] [a4aa94c41cb] master: Cleanup: Declare variables where initialized

Hans Goudey noreply at git.blender.org
Fri Oct 2 20:02:38 CEST 2020


Commit: a4aa94c41cb79e917a5bfe78907ab4a4bcbdad3b
Author: Hans Goudey
Date:   Fri Oct 2 13:02:30 2020 -0500
Branches: master
https://developer.blender.org/rBa4aa94c41cb79e917a5bfe78907ab4a4bcbdad3b

Cleanup: Declare variables where initialized

Also reduce the scope of some variable declarations.
This also allows making some variables constant.

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

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 7fa7984c7e7..f8b9f4f0df1 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -312,16 +312,13 @@ static bool ui_layout_variable_size(uiLayout *layout)
 /* estimated size of text + icon */
 static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool compact)
 {
-  bool variable;
   const int unit_x = UI_UNIT_X * (layout->scale[0] ? layout->scale[0] : 1.0f);
 
   if (icon && !name[0]) {
     return unit_x; /* icon only */
   }
 
-  variable = ui_layout_variable_size(layout);
-
-  if (variable) {
+  if (ui_layout_variable_size(layout)) {
     if (!icon && !name[0]) {
       return unit_x; /* No icon or name. */
     }
@@ -510,7 +507,6 @@ int uiLayoutGetLocalDir(const uiLayout *layout)
 static uiLayout *ui_item_local_sublayout(uiLayout *test, uiLayout *layout, bool align)
 {
   uiLayout *sub;
-
   if (uiLayoutGetLocalDir(test) == UI_LAYOUT_HORIZONTAL) {
     sub = uiLayoutRow(layout, align);
   }
@@ -569,17 +565,12 @@ static void ui_item_array(uiLayout *layout,
                           bool show_text)
 {
   const uiStyle *style = layout->root->style;
-  uiBut *but;
-  PropertyType type;
-  PropertySubType subtype;
-  uiLayout *sub;
-  uint a, b;
 
   /* retrieve type and subtype */
-  type = RNA_property_type(prop);
-  subtype = RNA_property_subtype(prop);
+  const PropertyType type = RNA_property_type(prop);
+  const PropertySubType subtype = RNA_property_subtype(prop);
 
-  sub = ui_item_local_sublayout(layout, layout, 1);
+  uiLayout *sub = ui_item_local_sublayout(layout, layout, 1);
   UI_block_layout_set_current(block, sub);
 
   /* create label */
@@ -590,17 +581,15 @@ static void ui_item_array(uiLayout *layout,
   /* create buttons */
   if (type == PROP_BOOLEAN && ELEM(subtype, PROP_LAYER, PROP_LAYER_MEMBER)) {
     /* special check for layer layout */
-    int butw, buth, unit;
     const int cols = (len >= 20) ? 2 : 1;
-    const uint colbuts = len / (2 * cols);
+    const int colbuts = len / (2 * cols);
     uint layer_used = 0;
     uint layer_active = 0;
 
     UI_block_layout_set_current(block, uiLayoutAbsolute(layout, false));
 
-    unit = UI_UNIT_X * 0.75;
-    butw = unit;
-    buth = unit;
+    const int butw = UI_UNIT_X * 0.75;
+    const int buth = UI_UNIT_X * 0.75;
 
     if (ptr->type == &RNA_Armature) {
       bArmature *arm = ptr->data;
@@ -619,10 +608,10 @@ static void ui_item_array(uiLayout *layout,
       }
     }
 
-    for (b = 0; b < cols; b++) {
+    for (int b = 0; b < cols; b++) {
       UI_block_align_begin(block);
 
-      for (a = 0; a < colbuts; a++) {
+      for (int a = 0; a < colbuts; a++) {
         const int layer_num = a + b * colbuts;
         const uint layer_flag = (1u << layer_num);
 
@@ -638,13 +627,13 @@ static void ui_item_array(uiLayout *layout,
           icon = ICON_BLANK1;
         }
 
-        but = uiDefAutoButR(
+        uiBut *but = uiDefAutoButR(
             block, ptr, prop, layer_num, "", icon, x + butw * a, y + buth, butw, buth);
         if (subtype == PROP_LAYER_MEMBER) {
           UI_but_func_set(but, ui_layer_but_cb, but, POINTER_FROM_INT(layer_num));
         }
       }
-      for (a = 0; a < colbuts; a++) {
+      for (int a = 0; a < colbuts; a++) {
         const int layer_num = a + len / 2 + b * colbuts;
         const uint layer_flag = (1u << layer_num);
 
@@ -660,7 +649,8 @@ static void ui_item_array(uiLayout *layout,
           icon = ICON_BLANK1;
         }
 
-        but = uiDefAutoButR(block, ptr, prop, layer_num, "", icon, x + butw * a, y, butw, buth);
+        uiBut *but = uiDefAutoButR(
+            block, ptr, prop, layer_num, "", icon, x + butw * a, y, butw, buth);
         if (subtype == PROP_LAYER_MEMBER) {
           UI_but_func_set(but, ui_layer_but_cb, but, POINTER_FROM_INT(layer_num));
         }
@@ -685,20 +675,20 @@ static void ui_item_array(uiLayout *layout,
     w /= dim_size[0];
     /* h /= dim_size[1]; */ /* UNUSED */
 
-    for (a = 0; a < len; a++) {
+    for (int a = 0; a < len; a++) {
       col = a % dim_size[0];
       row = a / dim_size[0];
 
-      but = uiDefAutoButR(block,
-                          ptr,
-                          prop,
-                          a,
-                          "",
-                          ICON_NONE,
-                          x + w * col,
-                          y + (dim_size[1] * UI_UNIT_Y) - (row * UI_UNIT_Y),
-                          w,
-                          UI_UNIT_Y);
+      uiBut *but = uiDefAutoButR(block,
+                                 ptr,
+                                 prop,
+                                 a,
+                                 "",
+                                 ICON_NONE,
+                                 x + w * col,
+                                 y + (dim_size[1] * UI_UNIT_Y) - (row * UI_UNIT_Y),
+                                 w,
+                                 UI_UNIT_Y);
       if (slider && but->type == UI_BTYPE_NUM) {
         uiButNumber *number_but = (uiButNumber *)but;
 
@@ -734,8 +724,6 @@ static void ui_item_array(uiLayout *layout,
       uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, 0, 0, w, UI_UNIT_Y);
     }
     else {
-      bool *boolarr = NULL;
-
       /* even if 'expand' is fale, expanding anyway */
 
       /* layout for known array subtypes */
@@ -748,6 +736,7 @@ static void ui_item_array(uiLayout *layout,
       }
 
       /* show checkboxes for rna on a non-emboss block (menu for eg) */
+      bool *boolarr = NULL;
       if (type == PROP_BOOLEAN &&
           ELEM(layout->root->block->emboss, UI_EMBOSS_NONE, UI_EMBOSS_PULLDOWN)) {
         boolarr = MEM_callocN(sizeof(bool) * len, __func__);
@@ -755,9 +744,7 @@ static void ui_item_array(uiLayout *layout,
       }
 
       const char *str_buf = show_text ? str : "";
-      for (a = 0; a < len; a++) {
-        int width_item;
-
+      for (int a = 0; a < len; a++) {
         if (!icon_only && show_text) {
           str[0] = RNA_property_array_item_char(prop, a);
         }
@@ -765,11 +752,12 @@ static void ui_item_array(uiLayout *layout,
           icon = boolarr[a] ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
         }
 
-        width_item = ((compact && type == PROP_BOOLEAN) ?
-                          min_ii(w, ui_text_icon_width(layout, str_buf, icon, false)) :
-                          w);
+        const int width_item = ((compact && type == PROP_BOOLEAN) ?
+                                    min_ii(w, ui_text_icon_width(layout, str_buf, icon, false)) :
+                                    w);
 
-        but = uiDefAutoButR(block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y);
+        uiBut *but = uiDefAutoButR(
+            block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y);
         if (slider && but->type == UI_BTYPE_NUM) {
           uiButNumber *number_but = (uiButNumber *)but;
 
@@ -832,7 +820,6 @@ static void ui_item_enum_expand_elem_exec(uiLayout *layout,
   const int itemw = ui_text_icon_width(block->curlayout, icon_only ? "" : name, icon, 0);
 
   uiBut *but;
-
   if (icon && name[0] && !icon_only) {
     but = uiDefIconTextButR_prop(
         block, but_type, 0, icon, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL);
@@ -886,13 +873,12 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
    * - mont29
    */
 
-  const EnumPropertyItem *item, *item_array;
-  bool free;
-
   BLI_assert(RNA_property_type(prop) == PROP_ENUM);
 
-  uiLayout *layout_radial = NULL;
   const bool radial = (layout->root->type == UI_LAYOUT_PIEMENU);
+
+  bool free;
+  const EnumPropertyItem *item_array;
   if (radial) {
     RNA_property_enum_items_gettexted_all(block->evil_C, ptr, prop, &item_array, NULL, &free);
   }
@@ -901,6 +887,7 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
   }
 
   /* we dont want nested rows, cols in menus */
+  uiLayout *layout_radial = NULL;
   if (radial) {
     if (layout->root->layout == layout) {
       layout_radial = uiLayoutRadial(layout);
@@ -921,7 +908,7 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
     UI_block_layout_set_current(block, ui_item_local_sublayout(layout, layout, 1));
   }
 
-  for (item = item_array; item->identifier; item++) {
+  for (const EnumPropertyItem *item = item_array; item->identifier; item++) {
     const bool is_first = item == item_array;
 
     if (!item->identifier[0]) {
@@ -1016,9 +1003,6 @@ static uiBut *ui_item_with_label(uiLayout *layout,
                                  int flag)
 {
   uiLayout *sub = layout;
-  uiBut *but = NULL;
-  PropertyType type;
-  PropertySubType subtype;
   int prop_but_width = w_hint;
 #ifdef UI_PROP_DECORATE
   uiLayout *layout_prop_decorate = NULL;
@@ -1047,7 +1031,6 @@ static uiBut *ui_item_with_label(uiLayout *layout,
 #endif
     {
       int w_label;
-
       if (ui_layout_variable_size(layout)) {
         /* w_hint is width for label in this case.
          * Use a default width for property button(s) */
@@ -1061,9 +1044,10 @@ static uiBut *ui_item_with_label(uiLayout *layout,
     }
   }
 
-  type = RNA_property_type(prop);
-  subtype = RNA_property_subtype(prop);
+  const PropertyType type = RNA_property_type(prop);
+  const PropertySubType subtype = RNA_property_subtype(prop);
 
+  uiBut *but;
   if (subtype == PROP_FILEPATH || subtype == PROP_DIRPATH) {
     UI_block_layout_set_current(block, uiLayoutRow(sub, true));
     but = uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, prop_but_width - UI_UNIT_X, h);
@@ -1204,8 +1188,6 @@ static void ui_but_tip_from_enum_item(uiBut *but, const EnumPropertyItem *item)
 static void ui_item_disabled(uiLayout *layout, const char *name)
 {
   uiBlock *block = layout->root->block;
-  uiBut *but;
-  int w;
 
   UI_block_layout_set_current(block, layout);
 
@@ -1213,9 +1195,10 @@ static void ui_item_disabled(uiLayout *layout, const char *name)
     name = "";
   }
 
-  w = ui_text_icon_width(layout, name, 0, 0);
+  const int w = ui_text_icon_width(layout, name, 0, 0);
 
-  but = uiDefBut(block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list