[Bf-blender-cvs] [349eebd7d14] master: UI Code Quality: Use LISTBASE_FOREACH in interface directory
Hans Goudey
noreply at git.blender.org
Wed Aug 19 03:47:25 CEST 2020
Commit: 349eebd7d1459fa2525850751040963899ef7535
Author: Hans Goudey
Date: Tue Aug 18 21:46:29 2020 -0400
Branches: master
https://developer.blender.org/rB349eebd7d1459fa2525850751040963899ef7535
UI Code Quality: Use LISTBASE_FOREACH in interface directory
I only skipped a few loops in the monstrous ui_handle_menu_event
function. Also, I only changed variable names where necessary to
prevent redeclarations.
Differential Revision: https://developer.blender.org/D8586
===================================================================
M source/blender/editors/interface/interface.c
M source/blender/editors/interface/interface_align.c
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_layout.c
M source/blender/editors/interface/interface_ops.c
M source/blender/editors/interface/interface_query.c
M source/blender/editors/interface/interface_region_color_picker.c
M source/blender/editors/interface/interface_region_menu_popup.c
M source/blender/editors/interface/interface_region_popover.c
M source/blender/editors/interface/interface_region_popup.c
M source/blender/editors/interface/interface_style.c
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/interface/interface_utils.c
M source/blender/editors/interface/interface_widgets.c
M source/blender/editors/interface/view2d.c
===================================================================
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index c06c85e19d4..e04531bb1dd 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -358,9 +358,7 @@ void ui_region_winrct_get_no_margin(const struct ARegion *region, struct rcti *r
void UI_block_translate(uiBlock *block, int x, int y)
{
- uiBut *but;
-
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
BLI_rctf_translate(&but->rect, x, y);
}
@@ -370,12 +368,13 @@ void UI_block_translate(uiBlock *block, int x, int y)
static void ui_block_bounds_calc_text(uiBlock *block, float offset)
{
const uiStyle *style = UI_style_get();
- uiBut *bt, *init_col_bt, *col_bt;
+ uiBut *col_bt;
int i = 0, j, x1addval = offset;
UI_fontstyle_set(&style->widget);
- for (init_col_bt = bt = block->buttons.first; bt; bt = bt->next) {
+ uiBut *init_col_bt = block->buttons.first;
+ LISTBASE_FOREACH (uiBut *, bt, &block->buttons) {
if (!ELEM(bt->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR_SPACER)) {
j = BLF_width(style->widget.uifont_id, bt->drawstr, sizeof(bt->drawstr));
@@ -411,7 +410,6 @@ static void ui_block_bounds_calc_text(uiBlock *block, float offset)
void ui_block_bounds_calc(uiBlock *block)
{
- uiBut *bt;
int xof;
if (BLI_listbase_is_empty(&block->buttons)) {
@@ -426,7 +424,7 @@ void ui_block_bounds_calc(uiBlock *block)
BLI_rctf_init_minmax(&block->rect);
- for (bt = block->buttons.first; bt; bt = bt->next) {
+ LISTBASE_FOREACH (uiBut *, bt, &block->buttons) {
BLI_rctf_union(&block->rect, &bt->rect);
}
@@ -439,7 +437,7 @@ void ui_block_bounds_calc(uiBlock *block)
block->rect.xmax = block->rect.xmin + max_ff(BLI_rctf_size_x(&block->rect), block->minbounds);
/* hardcoded exception... but that one is annoying with larger safety */
- bt = block->buttons.first;
+ uiBut *bt = block->buttons.first;
if (bt && STREQLEN(bt->str, "ERROR", 5)) {
xof = 10;
}
@@ -701,9 +699,10 @@ static bool ui_but_equals_old(const uiBut *but, const uiBut *oldbut)
uiBut *ui_but_find_old(uiBlock *block_old, const uiBut *but_new)
{
- uiBut *but_old;
- for (but_old = block_old->buttons.first; but_old; but_old = but_old->next) {
- if (ui_but_equals_old(but_new, but_old)) {
+ uiBut *but_old = NULL;
+ LISTBASE_FOREACH (uiBut *, but, &block_old->buttons) {
+ if (ui_but_equals_old(but_new, but)) {
+ but_old = but;
break;
}
}
@@ -711,9 +710,10 @@ uiBut *ui_but_find_old(uiBlock *block_old, const uiBut *but_new)
}
uiBut *ui_but_find_new(uiBlock *block_new, const uiBut *but_old)
{
- uiBut *but_new;
- for (but_new = block_new->buttons.first; but_new; but_new = but_new->next) {
- if (ui_but_equals_old(but_new, but_old)) {
+ uiBut *but_new = NULL;
+ LISTBASE_FOREACH (uiBut *, but, &block_new->buttons) {
+ if (ui_but_equals_old(but, but_old)) {
+ but_new = but;
break;
}
}
@@ -1465,7 +1465,6 @@ static void ui_but_pie_direction_string(uiBut *but, char *buf, int size)
static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
{
- uiBut *but;
char buf[128];
BLI_assert(block->flag & (UI_BLOCK_LOOP | UI_BLOCK_SHOW_SHORTCUT_ALWAYS));
@@ -1479,7 +1478,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
}
if (block->flag & UI_BLOCK_RADIAL) {
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (but->pie_dir != UI_RADIAL_NONE) {
ui_but_pie_direction_string(but, buf, sizeof(buf));
ui_but_add_shortcut(but, buf, false);
@@ -1487,7 +1486,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
}
}
else {
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (block->flag & UI_BLOCK_SHOW_SHORTCUT_ALWAYS) {
/* Skip icon-only buttons (as used in the toolbar). */
if (but->drawstr[0] == '\0') {
@@ -1575,10 +1574,7 @@ static void ui_but_extra_operator_icon_free(uiButExtraOpIcon *extra_icon)
void ui_but_extra_operator_icons_free(uiBut *but)
{
-
- for (uiButExtraOpIcon *op_icon = but->extra_op_icons.first, *op_icon_next; op_icon;
- op_icon = op_icon_next) {
- op_icon_next = op_icon->next;
+ LISTBASE_FOREACH_MUTABLE (uiButExtraOpIcon *, op_icon, &but->extra_op_icons) {
ui_but_extra_operator_icon_free(op_icon);
}
BLI_listbase_clear(&but->extra_op_icons);
@@ -1710,7 +1706,6 @@ static void ui_but_predefined_extra_operator_icons_add(uiBut *but)
void UI_block_update_from_old(const bContext *C, uiBlock *block)
{
uiBut *but_old;
- uiBut *but;
if (!block->oldblock) {
return;
@@ -1722,7 +1717,7 @@ void UI_block_update_from_old(const bContext *C, uiBlock *block)
UI_butstore_update(block);
}
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (ui_but_update_from_old_block(C, block, &but, &but_old)) {
ui_but_update(but);
@@ -1747,7 +1742,6 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x
Scene *scene = CTX_data_scene(C);
ARegion *region = CTX_wm_region(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
- uiBut *but;
BLI_assert(block->active);
@@ -1757,7 +1751,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x
* on matching buttons, we need this to make button event handling non
* blocking, while still allowing buttons to be remade each redraw as it
* is expected by blender code */
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
/* temp? Proper check for graying out */
if (but->optype) {
wmOperatorType *ot = but->optype;
@@ -1877,7 +1871,6 @@ void UI_block_draw(const bContext *C, uiBlock *block)
{
uiStyle style = *UI_style_get_dpi(); /* XXX pass on as arg */
ARegion *region;
- uiBut *but;
rcti rect;
/* get menu region or area region */
@@ -1942,7 +1935,7 @@ void UI_block_draw(const bContext *C, uiBlock *block)
UI_widgetbase_draw_cache_begin();
/* widgets */
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (!(but->flag & (UI_HIDDEN | UI_SCROLLED))) {
ui_but_to_pixelrect(&rect, region, block, but);
@@ -2508,17 +2501,18 @@ int ui_but_string_get_max_length(uiBut *but)
uiBut *ui_but_drag_multi_edit_get(uiBut *but)
{
- uiBut *but_iter;
+ uiBut *return_but = NULL;
BLI_assert(but->flag & UI_BUT_DRAG_MULTI);
- for (but_iter = but->block->buttons.first; but_iter; but_iter = but_iter->next) {
+ LISTBASE_FOREACH (uiBut *, but_iter, &but->block->buttons) {
if (but_iter->editstr) {
+ return_but = but_iter;
break;
}
}
- return but_iter;
+ return return_but;
}
static double ui_get_but_scale_unit(uiBut *but, double value)
@@ -3378,11 +3372,7 @@ void UI_blocklist_free(const bContext *C, ListBase *lb)
void UI_blocklist_free_inactive(const bContext *C, ListBase *lb)
{
- uiBlock *block, *nextblock;
-
- for (block = lb->first; block; block = nextblock) {
- nextblock = block->next;
-
+ LISTBASE_FOREACH_MUTABLE (uiBlock *, block, lb) {
if (!block->handle) {
if (!block->active) {
BLI_remlink(lb, block);
@@ -5956,10 +5946,9 @@ uiBut *uiDefIconTextButO(uiBlock *block,
int UI_blocklist_min_y_get(ListBase *lb)
{
- uiBlock *block;
int min = 0;
- for (block = lb->first; block; block = block->next) {
+ LISTBASE_FOREACH (uiBlock *, block, lb) {
if (block == lb->first || block->rect.ymin < min) {
min = block->rect.ymin;
}
@@ -5976,7 +5965,6 @@ void UI_block_direction_set(uiBlock *block, char direction)
/* this call escapes if there's alignment flags */
void UI_block_order_flip(uiBlock *block)
{
- uiBut *but;
float centy, miny = 10000, maxy = -10000;
if (U.uiflag & USER_MENUFIXEDORDER) {
@@ -5986,7 +5974,7 @@ void UI_block_order_flip(uiBlock *block)
return;
}
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (but->drawflag & UI_BUT_ALIGN) {
return;
}
@@ -5999,7 +5987,7 @@ void UI_block_order_flip(uiBlock *block)
}
/* mirror trick */
centy = (miny + maxy) / 2.0f;
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
but->rect.ymin = centy - (but->rect.ymin - centy);
but->rect.ymax = centy - (but->rect.ymax - centy);
SWAP(float, but->rect.ymin, but->rect.ymax);
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c
index 4981ef111e0..e92adc8a2ec 100644
--- a/source/blender/editors/interface/interface_align.c
+++ b/source/blender/editors/interface/interface_align.c
@@ -24,6 +24,7 @@
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_rect.h"
@@ -385,7 +386,6 @@ static void ui_block_align_but_to_region(uiBut *but, const ARegion *region)
*/
void ui_block_align_calc(uiBlock *block, const ARegion *region)
{
- uiBut *but;
int num_buttons = 0;
const int sides_to_ui_but_align_flags[4] = SIDE_TO_UI_BUT_ALIGN;
@@ -398,7 +398,7 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region)
/* First loop: we count number of buttons belonging to an align group,
* and clear their align flag.
* Tabs get some special treatment here, they get aligned to region border. */
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
/* special case: tabs need to be aligned to a region border, drawflag tells which one */
if (but->type == UI_BTYPE_TAB) {
ui_block_align_but_to_region(but, region);
@@ -431,7 +431,8 @@ void ui_block_align_calc(uiBlock *block, const ARegion *regi
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list