UI Code Quality: Use derived struct for progessbar buttons
For the main rationale behind this design, see 03b122e2a18df. Further, this removes users of `uiBut.a1`, which is a very ugly design choice (hard to reason about). Part of T74432.
This commit is contained in:
parent
9f475db6c9
commit
076a93b855
|
@ -820,10 +820,10 @@ static bool ui_but_update_from_old_block(const bContext *C,
|
|||
oldbut->hardmax = but->hardmax;
|
||||
}
|
||||
|
||||
/* Selectively copy a1, a2 since their use differs across all button types
|
||||
* (and we'll probably split these out later) */
|
||||
if (ELEM(oldbut->type, UI_BTYPE_PROGRESS_BAR)) {
|
||||
oldbut->a1 = but->a1;
|
||||
if (oldbut->type == UI_BTYPE_PROGRESS_BAR) {
|
||||
uiButProgressbar *progress_oldbut = (uiButProgressbar *)oldbut;
|
||||
uiButProgressbar *progress_but = (uiButProgressbar *)but;
|
||||
progress_oldbut->progress = progress_but->progress;
|
||||
}
|
||||
|
||||
if (!BLI_listbase_is_empty(&block->butstore)) {
|
||||
|
@ -3789,6 +3789,10 @@ static void ui_but_alloc_info(const eButType type,
|
|||
alloc_size = sizeof(uiButSearch);
|
||||
alloc_str = "uiButSearch";
|
||||
break;
|
||||
case UI_BTYPE_PROGRESS_BAR:
|
||||
alloc_size = sizeof(uiButProgressbar);
|
||||
alloc_str = "uiButProgressbar";
|
||||
break;
|
||||
default:
|
||||
alloc_size = sizeof(uiBut);
|
||||
alloc_str = "uiBut";
|
||||
|
|
|
@ -177,7 +177,6 @@ struct uiBut {
|
|||
* - UI_BTYPE_LABEL: Use `(a1 == 1.0f)` to use a2 as a blending factor (imaginative!).
|
||||
* - UI_BTYPE_SCROLL: Use as scroll size.
|
||||
* - UI_BTYPE_SEARCH_MENU: Use as number or rows.
|
||||
* - UI_BTYPE_PROGRESS_BAR: Use to store progress (0..1).
|
||||
*/
|
||||
float a1;
|
||||
|
||||
|
@ -322,6 +321,13 @@ typedef struct uiButDecorator {
|
|||
int rnaindex;
|
||||
} uiButDecorator;
|
||||
|
||||
typedef struct uiButProgressbar {
|
||||
uiBut but;
|
||||
|
||||
/* 0..1 range */
|
||||
float progress;
|
||||
} uiButProgressbar;
|
||||
|
||||
/**
|
||||
* Additional, superimposed icon for a button, invoking an operator.
|
||||
*/
|
||||
|
|
|
@ -6791,22 +6791,24 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
|
|||
struct ProgressTooltip_Store *tip_arg = MEM_mallocN(sizeof(*tip_arg), __func__);
|
||||
tip_arg->wm = wm;
|
||||
tip_arg->owner = owner;
|
||||
uiBut *but_progress = uiDefIconTextBut(block,
|
||||
UI_BTYPE_PROGRESS_BAR,
|
||||
0,
|
||||
0,
|
||||
text,
|
||||
UI_UNIT_X,
|
||||
0,
|
||||
UI_UNIT_X * 6.0f,
|
||||
UI_UNIT_Y,
|
||||
NULL,
|
||||
0.0f,
|
||||
0.0f,
|
||||
progress,
|
||||
0,
|
||||
NULL);
|
||||
UI_but_func_tooltip_set(but_progress, progress_tooltip_func, tip_arg);
|
||||
uiButProgressbar *but_progress = (uiButProgressbar *)uiDefIconTextBut(block,
|
||||
UI_BTYPE_PROGRESS_BAR,
|
||||
0,
|
||||
0,
|
||||
text,
|
||||
UI_UNIT_X,
|
||||
0,
|
||||
UI_UNIT_X * 6.0f,
|
||||
UI_UNIT_Y,
|
||||
NULL,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0,
|
||||
NULL);
|
||||
|
||||
but_progress->progress = progress;
|
||||
UI_but_func_tooltip_set(&but_progress->but, progress_tooltip_func, tip_arg);
|
||||
}
|
||||
|
||||
if (!wm->is_interface_locked) {
|
||||
|
|
|
@ -3609,6 +3609,7 @@ static void widget_scroll(
|
|||
static void widget_progressbar(
|
||||
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
|
||||
{
|
||||
uiButProgressbar *but_progressbar = (uiButProgressbar *)but;
|
||||
uiWidgetBase wtb, wtb_bar;
|
||||
rcti rect_prog = *rect, rect_bar = *rect;
|
||||
|
||||
|
@ -3616,7 +3617,7 @@ static void widget_progressbar(
|
|||
widget_init(&wtb_bar);
|
||||
|
||||
/* round corners */
|
||||
float value = but->a1;
|
||||
float value = but_progressbar->progress;
|
||||
float offs = wcol->roundness * BLI_rcti_size_y(&rect_prog);
|
||||
float w = value * BLI_rcti_size_x(&rect_prog);
|
||||
|
||||
|
|
Loading…
Reference in New Issue