UI Code Quality: Use derived struct for number buttons

For the man rationale behind this design, see 49f088e2d0. Further,
this removes users of uiBut.a1/uiBut.a2, which is a very ugly design
choice (hard to reason about).

Note that I had to do rather ugly, specific exceptions for the number
buttons in `ui_def_but_rna()`. But once all users of a1/a2 are removed,
this special handling shouldn't be needed anymore.
I also had to move a sanity check out of the button definition. It's now
moved into a new debug only sanity checking function executed when
finishing the layout definition (block end).
This commit is contained in:
2020-09-04 21:18:45 +02:00
parent 47881791be
commit e6f0b60c2e
12 changed files with 788 additions and 604 deletions

View File

@@ -196,9 +196,10 @@ static void draw_modifier__generator(uiLayout *layout,
&data->poly_order, &data->poly_order,
1, 1,
100, 100,
1, 0,
0, 0,
TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)")); TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)"));
UI_but_number_step_size_set(but, 1);
UI_but_func_set(but, validate_fmodifier_cb, fcm, fcurve_owner_id); UI_but_func_set(but, validate_fmodifier_cb, fcm, fcurve_owner_id);
/* calculate maximum width of label for "x^n" labels */ /* calculate maximum width of label for "x^n" labels */
@@ -256,7 +257,7 @@ static void draw_modifier__generator(uiLayout *layout,
} }
/* coefficient */ /* coefficient */
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_FMODIFIER_REDRAW, B_FMODIFIER_REDRAW,
"", "",
@@ -267,9 +268,11 @@ static void draw_modifier__generator(uiLayout *layout,
cp, cp,
-UI_FLT_MAX, -UI_FLT_MAX,
UI_FLT_MAX, UI_FLT_MAX,
10, 0,
3, 0,
TIP_("Coefficient for polynomial")); TIP_("Coefficient for polynomial"));
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, 3);
/* 'x' param (and '+' if necessary) */ /* 'x' param (and '+' if necessary) */
if (i == 0) { if (i == 0) {
@@ -334,10 +337,11 @@ static void draw_modifier__generator(uiLayout *layout,
&data->poly_order, &data->poly_order,
1, 1,
100, 100,
1, 0,
0, 0,
TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)")); TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)"));
UI_but_func_set(but, validate_fmodifier_cb, fcm, fcurve_owner_id); UI_but_func_set(but, validate_fmodifier_cb, fcm, fcurve_owner_id);
UI_but_number_step_size_set(but, 1);
/* draw controls for each pair of coefficients */ /* draw controls for each pair of coefficients */
row = uiLayoutRow(layout, true); row = uiLayoutRow(layout, true);
@@ -386,7 +390,7 @@ static void draw_modifier__generator(uiLayout *layout,
block, UI_BTYPE_LABEL, 1, "(", 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); block, UI_BTYPE_LABEL, 1, "(", 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
/* coefficients */ /* coefficients */
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_FMODIFIER_REDRAW, B_FMODIFIER_REDRAW,
"", "",
@@ -397,9 +401,11 @@ static void draw_modifier__generator(uiLayout *layout,
cp, cp,
-UI_FLT_MAX, -UI_FLT_MAX,
UI_FLT_MAX, UI_FLT_MAX,
10, 0,
3, 0,
TIP_("Coefficient of x")); TIP_("Coefficient of x"));
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, 3);
uiDefBut(block, uiDefBut(block,
UI_BTYPE_LABEL, UI_BTYPE_LABEL,
@@ -416,7 +422,7 @@ static void draw_modifier__generator(uiLayout *layout,
0, 0,
""); "");
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_FMODIFIER_REDRAW, B_FMODIFIER_REDRAW,
"", "",
@@ -427,9 +433,11 @@ static void draw_modifier__generator(uiLayout *layout,
cp + 1, cp + 1,
-UI_FLT_MAX, -UI_FLT_MAX,
UI_FLT_MAX, UI_FLT_MAX,
10, 0,
3, 0,
TIP_("Second coefficient")); TIP_("Second coefficient"));
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, 3);
/* closing bracket and multiplication sign */ /* closing bracket and multiplication sign */
if ((i != (data->poly_order - 1)) || ((i == 0) && data->poly_order == 2)) { if ((i != (data->poly_order - 1)) || ((i == 0) && data->poly_order == 2)) {
@@ -724,7 +732,7 @@ static void draw_modifier__envelope(uiLayout *layout,
block = uiLayoutGetBlock(row); block = uiLayoutGetBlock(row);
UI_block_align_begin(block); UI_block_align_begin(block);
uiDefButR(block, but = uiDefButR(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_FMODIFIER_REDRAW, B_FMODIFIER_REDRAW,
IFACE_("Fra:"), IFACE_("Fra:"),
@@ -737,10 +745,12 @@ static void draw_modifier__envelope(uiLayout *layout,
-1, -1,
-MAXFRAMEF, -MAXFRAMEF,
MAXFRAMEF, MAXFRAMEF,
10, 0,
1, 0,
NULL); NULL);
uiDefButR(block, UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, 1);
but = uiDefButR(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_FMODIFIER_REDRAW, B_FMODIFIER_REDRAW,
IFACE_("Min:"), IFACE_("Min:"),
@@ -753,10 +763,12 @@ static void draw_modifier__envelope(uiLayout *layout,
-1, -1,
-UI_FLT_MAX, -UI_FLT_MAX,
UI_FLT_MAX, UI_FLT_MAX,
10, 0,
2, 0,
NULL); NULL);
uiDefButR(block, UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, 2);
but = uiDefButR(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_FMODIFIER_REDRAW, B_FMODIFIER_REDRAW,
IFACE_("Max:"), IFACE_("Max:"),
@@ -769,9 +781,11 @@ static void draw_modifier__envelope(uiLayout *layout,
-1, -1,
-UI_FLT_MAX, -UI_FLT_MAX,
UI_FLT_MAX, UI_FLT_MAX,
10, 0,
2, 0,
NULL); NULL);
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, 2);
but = uiDefIconBut(block, but = uiDefIconBut(block,
UI_BTYPE_BUT, UI_BTYPE_BUT,

View File

@@ -1602,6 +1602,9 @@ int UI_search_items_find_index(uiSearchItems *items, const char *name);
void UI_but_node_link_set(uiBut *but, struct bNodeSocket *socket, const float draw_color[4]); void UI_but_node_link_set(uiBut *but, struct bNodeSocket *socket, const float draw_color[4]);
void UI_but_number_step_size_set(uiBut *but, float step_size);
void UI_but_number_precision_set(uiBut *but, float precision);
void UI_block_func_handle_set(uiBlock *block, uiBlockHandleFunc func, void *arg); void UI_block_func_handle_set(uiBlock *block, uiBlockHandleFunc func, void *arg);
void UI_block_func_butmenu_set(uiBlock *block, uiMenuHandleFunc func, void *arg); void UI_block_func_butmenu_set(uiBlock *block, uiMenuHandleFunc func, void *arg);
void UI_block_func_set(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2); void UI_block_func_set(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2);

View File

@@ -622,9 +622,18 @@ void UI_block_bounds_set_explicit(uiBlock *block, int minx, int miny, int maxx,
block->bounds_type = UI_BLOCK_BOUNDS_NONE; block->bounds_type = UI_BLOCK_BOUNDS_NONE;
} }
static float ui_but_get_float_precision(uiBut *but)
{
if (but->type == UI_BTYPE_NUM) {
return ((uiButNumber *)but)->precision;
}
return but->a2;
}
static int ui_but_calc_float_precision(uiBut *but, double value) static int ui_but_calc_float_precision(uiBut *but, double value)
{ {
int prec = (int)but->a2; int prec = (int)ui_but_get_float_precision(but);
/* first check for various special cases: /* first check for various special cases:
* * If button is radians, we want additional precision (see T39861). * * If button is radians, we want additional precision (see T39861).
@@ -1737,6 +1746,24 @@ void UI_block_update_from_old(const bContext *C, uiBlock *block)
block->oldblock = NULL; block->oldblock = NULL;
} }
#ifndef NDEBUG
/**
* Extra sanity checks for invariants (debug builds only).
*/
static void ui_but_validate(const uiBut *but)
{
/* Number buttons must have a click-step,
* assert instead of correcting the value to ensure the caller knows what they're doing. */
if (but->type == UI_BTYPE_NUM) {
uiButNumber *number_but = (uiButNumber *)but;
if (ELEM(but->pointype, UI_BUT_POIN_CHAR, UI_BUT_POIN_SHORT, UI_BUT_POIN_INT)) {
BLI_assert((int)number_but->step_size > 0);
}
}
}
#endif
void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_xy[2]) void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_xy[2])
{ {
wmWindow *window = CTX_wm_window(C); wmWindow *window = CTX_wm_window(C);
@@ -1778,6 +1805,10 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x
ui_but_anim_decorate_update_from_flag((uiButDecorator *)but); ui_but_anim_decorate_update_from_flag((uiButDecorator *)but);
} }
ui_but_predefined_extra_operator_icons_add(but); ui_but_predefined_extra_operator_icons_add(but);
#ifndef NDEBUG
ui_but_validate(but);
#endif
} }
/* handle pending stuff */ /* handle pending stuff */
@@ -2562,7 +2593,7 @@ static void ui_get_but_string_unit(
/* Use precision override? */ /* Use precision override? */
if (float_precision == -1) { if (float_precision == -1) {
/* Sanity checks */ /* Sanity checks */
precision = (int)but->a2; precision = (int)ui_but_get_float_precision(but);
if (precision > UI_PRECISION_FLOAT_MAX) { if (precision > UI_PRECISION_FLOAT_MAX) {
precision = UI_PRECISION_FLOAT_MAX; precision = UI_PRECISION_FLOAT_MAX;
} }
@@ -3768,6 +3799,10 @@ static void ui_but_alloc_info(const eButType type,
bool has_custom_type = true; bool has_custom_type = true;
switch (type) { switch (type) {
case UI_BTYPE_NUM:
alloc_size = sizeof(uiButNumber);
alloc_str = "uiButNumber";
break;
case UI_BTYPE_COLOR: case UI_BTYPE_COLOR:
alloc_size = sizeof(uiButColor); alloc_size = sizeof(uiButColor);
alloc_str = "uiButColor"; alloc_str = "uiButColor";
@@ -3914,14 +3949,6 @@ static uiBut *ui_def_but(uiBlock *block,
(a1 != 0.0f && a1 != 1.0f)) == false); (a1 != 0.0f && a1 != 1.0f)) == false);
} }
/* Number buttons must have a click-step,
* assert instead of correcting the value to ensure the caller knows what they're doing. */
if ((type & BUTTYPE) == UI_BTYPE_NUM) {
if (ELEM((type & UI_BUT_POIN_TYPES), UI_BUT_POIN_CHAR, UI_BUT_POIN_SHORT, UI_BUT_POIN_INT)) {
BLI_assert((int)a1 > 0);
}
}
if (type & UI_BUT_POIN_TYPES) { /* a pointer is required */ if (type & UI_BUT_POIN_TYPES) { /* a pointer is required */
if (poin == NULL) { if (poin == NULL) {
BLI_assert(0); BLI_assert(0);
@@ -4360,6 +4387,7 @@ static uiBut *ui_def_but_rna(uiBlock *block,
uiBut *but; uiBut *but;
int icon = 0; int icon = 0;
uiMenuCreateFunc func = NULL; uiMenuCreateFunc func = NULL;
const bool always_set_a1_a2 = ELEM(type, UI_BTYPE_NUM);
if (ELEM(type, UI_BTYPE_COLOR, UI_BTYPE_HSVCIRCLE, UI_BTYPE_HSVCUBE)) { if (ELEM(type, UI_BTYPE_COLOR, UI_BTYPE_HSVCIRCLE, UI_BTYPE_HSVCUBE)) {
BLI_assert(index == -1); BLI_assert(index == -1);
@@ -4424,7 +4452,7 @@ static uiBut *ui_def_but_rna(uiBlock *block,
tip = RNA_property_ui_description(prop); tip = RNA_property_ui_description(prop);
} }
if (min == max || a1 == -1 || a2 == -1) { if (min == max || a1 == -1 || a2 == -1 || always_set_a1_a2) {
if (proptype == PROP_INT) { if (proptype == PROP_INT) {
int hardmin, hardmax, softmin, softmax, step; int hardmin, hardmax, softmin, softmax, step;
@@ -4435,10 +4463,10 @@ static uiBut *ui_def_but_rna(uiBlock *block,
min = hardmin; min = hardmin;
max = hardmax; max = hardmax;
} }
if (a1 == -1) { if (a1 == -1 || always_set_a1_a2) {
a1 = step; a1 = step;
} }
if (a2 == -1) { if (a2 == -1 || always_set_a1_a2) {
a2 = 0; a2 = 0;
} }
} }
@@ -4452,10 +4480,10 @@ static uiBut *ui_def_but_rna(uiBlock *block,
min = hardmin; min = hardmin;
max = hardmax; max = hardmax;
} }
if (a1 == -1) { if (a1 == -1 || always_set_a1_a2) {
a1 = step; a1 = step;
} }
if (a2 == -1) { if (a2 == -1 || always_set_a1_a2) {
a2 = precision; a2 = precision;
} }
} }
@@ -4469,6 +4497,12 @@ static uiBut *ui_def_but_rna(uiBlock *block,
/* now create button */ /* now create button */
but = ui_def_but(block, type, retval, str, x, y, width, height, NULL, min, max, a1, a2, tip); but = ui_def_but(block, type, retval, str, x, y, width, height, NULL, min, max, a1, a2, tip);
if (but->type == UI_BTYPE_NUM) {
/* Set default values, can be overriden later. */
UI_but_number_step_size_set(but, a1);
UI_but_number_precision_set(but, a2);
}
but->rnapoin = *ptr; but->rnapoin = *ptr;
but->rnaprop = prop; but->rnaprop = prop;
@@ -4506,8 +4540,14 @@ static uiBut *ui_def_but_rna(uiBlock *block,
/* If this button uses units, calculate the step from this */ /* If this button uses units, calculate the step from this */
if ((proptype == PROP_FLOAT) && ui_but_is_unit(but)) { if ((proptype == PROP_FLOAT) && ui_but_is_unit(but)) {
if (type == UI_BTYPE_NUM) {
uiButNumber *number_but = (uiButNumber *)but;
number_but->step_size = ui_get_but_step_unit(but, number_but->step_size);
}
else {
but->a1 = ui_get_but_step_unit(but, but->a1); but->a1 = ui_get_but_step_unit(but, but->a1);
} }
}
if (func) { if (func) {
but->menu_create_func = func; but->menu_create_func = func;
@@ -6707,6 +6747,24 @@ void UI_but_node_link_set(uiBut *but, bNodeSocket *socket, const float draw_colo
rgba_float_to_uchar(but->col, draw_color); rgba_float_to_uchar(but->col, draw_color);
} }
void UI_but_number_step_size_set(uiBut *but, float step_size)
{
uiButNumber *but_number = (uiButNumber *)but;
BLI_assert(but->type == UI_BTYPE_NUM);
but_number->step_size = step_size;
BLI_assert(step_size > 0);
}
void UI_but_number_precision_set(uiBut *but, float precision)
{
uiButNumber *but_number = (uiButNumber *)but;
BLI_assert(but->type == UI_BTYPE_NUM);
but_number->precision = precision;
BLI_assert(precision > -1);
}
/** /**
* push a new event onto event queue to activate the given button * push a new event onto event queue to activate the given button
* (usually a text-field) upon entering a popup * (usually a text-field) upon entering a popup

View File

@@ -3896,12 +3896,14 @@ static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data)
softrange = softmax - softmin; softrange = softmax - softmin;
if ((but->type == UI_BTYPE_NUM) && (ui_but_is_cursor_warp(but) == false)) { if ((but->type == UI_BTYPE_NUM) && (ui_but_is_cursor_warp(but) == false)) {
uiButNumber *number_but = (uiButNumber *)but;
/* Use a minimum so we have a predictable range, /* Use a minimum so we have a predictable range,
* otherwise some float buttons get a large range. */ * otherwise some float buttons get a large range. */
const float value_step_float_min = 0.1f; const float value_step_float_min = 0.1f;
const bool is_float = ui_but_is_float(but); const bool is_float = ui_but_is_float(but);
const double value_step = is_float ? (double)(but->a1 * UI_PRECISION_FLOAT_SCALE) : const double value_step = is_float ?
(int)but->a1; (double)(number_but->step_size * UI_PRECISION_FLOAT_SCALE) :
(int)number_but->step_size;
const float drag_map_softrange_max = UI_DRAG_MAP_SOFT_RANGE_PIXEL_MAX * UI_DPI_FAC; const float drag_map_softrange_max = UI_DRAG_MAP_SOFT_RANGE_PIXEL_MAX * UI_DPI_FAC;
const float softrange_max = min_ff( const float softrange_max = min_ff(
softrange, softrange,
@@ -4699,13 +4701,14 @@ static float ui_numedit_apply_snap(int temp,
return temp; return temp;
} }
static bool ui_numedit_but_NUM(uiBut *but, static bool ui_numedit_but_NUM(uiButNumber *number_but,
uiHandleButtonData *data, uiHandleButtonData *data,
int mx, int mx,
const bool is_motion, const bool is_motion,
const enum eSnapType snap, const enum eSnapType snap,
float fac) float fac)
{ {
uiBut *but = &number_but->but;
float deler, tempf; float deler, tempf;
int lvalue, temp; int lvalue, temp;
bool changed = false; bool changed = false;
@@ -4724,7 +4727,7 @@ static bool ui_numedit_but_NUM(uiBut *but,
/* Mouse location isn't screen clamped to the screen so use a linear mapping /* Mouse location isn't screen clamped to the screen so use a linear mapping
* 2px == 1-int, or 1px == 1-ClickStep */ * 2px == 1-int, or 1px == 1-ClickStep */
if (is_float) { if (is_float) {
fac *= 0.01f * but->a1; fac *= 0.01f * number_but->step_size;
tempf = (float)data->startvalue + ((float)(mx - data->dragstartx) * fac); tempf = (float)data->startvalue + ((float)(mx - data->dragstartx) * fac);
tempf = ui_numedit_apply_snapf(but, tempf, softmin, softmax, snap); tempf = ui_numedit_apply_snapf(but, tempf, softmin, softmax, snap);
@@ -4927,6 +4930,7 @@ static void ui_numedit_set_active(uiBut *but)
static int ui_do_but_NUM( static int ui_do_but_NUM(
bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
{ {
uiButNumber *number_but = (uiButNumber *)but;
int click = 0; int click = 0;
int retval = WM_UI_HANDLER_CONTINUE; int retval = WM_UI_HANDLER_CONTINUE;
@@ -4936,6 +4940,8 @@ static int ui_do_but_NUM(
/* mouse location kept at screen pixel coords */ /* mouse location kept at screen pixel coords */
const int screen_mx = event->x; const int screen_mx = event->x;
BLI_assert(but->type == UI_BTYPE_NUM);
ui_window_to_block(data->region, block, &mx, &my); ui_window_to_block(data->region, block, &mx, &my);
ui_numedit_set_active(but); ui_numedit_set_active(but);
@@ -5028,8 +5034,12 @@ static int ui_do_but_NUM(
fac /= 10.0f; fac /= 10.0f;
} }
if (ui_numedit_but_NUM( if (ui_numedit_but_NUM(number_but,
but, data, (ui_but_is_cursor_warp(but) ? screen_mx : mx), is_motion, snap, fac)) { data,
(ui_but_is_cursor_warp(but) ? screen_mx : mx),
is_motion,
snap,
fac)) {
ui_numedit_apply(C, block, but, data); ui_numedit_apply(C, block, but, data);
} }
#ifdef USE_DRAG_MULTINUM #ifdef USE_DRAG_MULTINUM
@@ -5060,7 +5070,7 @@ static int ui_do_but_NUM(
if (but->drawflag & (UI_BUT_ACTIVE_LEFT | UI_BUT_ACTIVE_RIGHT)) { if (but->drawflag & (UI_BUT_ACTIVE_LEFT | UI_BUT_ACTIVE_RIGHT)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
const int value_step = (int)but->a1; const int value_step = (int)number_but->step_size;
BLI_assert(value_step > 0); BLI_assert(value_step > 0);
const int softmin = round_fl_to_int_clamp(but->softmin); const int softmin = round_fl_to_int_clamp(but->softmin);
const int softmax = round_fl_to_int_clamp(but->softmax); const int softmax = round_fl_to_int_clamp(but->softmax);
@@ -5084,7 +5094,7 @@ static int ui_do_but_NUM(
if (but->drawflag & (UI_BUT_ACTIVE_LEFT | UI_BUT_ACTIVE_RIGHT)) { if (but->drawflag & (UI_BUT_ACTIVE_LEFT | UI_BUT_ACTIVE_RIGHT)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
const double value_step = (double)but->a1 * UI_PRECISION_FLOAT_SCALE; const double value_step = (double)number_but->step_size * UI_PRECISION_FLOAT_SCALE;
BLI_assert(value_step > 0.0f); BLI_assert(value_step > 0.0f);
const double value_test = (but->drawflag & UI_BUT_ACTIVE_LEFT) ? const double value_test = (but->drawflag & UI_BUT_ACTIVE_LEFT) ?
(double)max_ff(but->softmin, (double)max_ff(but->softmin,

View File

@@ -174,7 +174,6 @@ struct uiBut {
/** /**
* For #uiBut.type: * For #uiBut.type:
* - UI_BTYPE_NUM: Use to store RNA 'step' value, for dragging and click-step.
* - UI_BTYPE_LABEL: Use `(a1 == 1.0f)` to use a2 as a blending factor (imaginative!). * - UI_BTYPE_LABEL: Use `(a1 == 1.0f)` to use a2 as a blending factor (imaginative!).
* - UI_BTYPE_SCROLL: Use as scroll size. * - UI_BTYPE_SCROLL: Use as scroll size.
* - UI_BTYPE_SEARCH_MENU: Use as number or rows. * - UI_BTYPE_SEARCH_MENU: Use as number or rows.
@@ -184,7 +183,6 @@ struct uiBut {
/** /**
* For #uiBut.type: * For #uiBut.type:
* - UI_BTYPE_HSVCIRCLE: Use to store the luminosity. * - UI_BTYPE_HSVCIRCLE: Use to store the luminosity.
* - UI_BTYPE_NUM: Use to store RNA 'precision' value, for dragging and click-step.
* - UI_BTYPE_LABEL: If `(a1 == 1.0f)` use a2 as a blending factor. * - UI_BTYPE_LABEL: If `(a1 == 1.0f)` use a2 as a blending factor.
* - UI_BTYPE_SEARCH_MENU: Use as number or columns. * - UI_BTYPE_SEARCH_MENU: Use as number or columns.
*/ */
@@ -276,6 +274,14 @@ struct uiBut {
uiBlock *block; uiBlock *block;
}; };
/** Derived struct for #UI_BTYPE_NUM */
typedef struct uiButNumber {
uiBut but;
float step_size;
float precision;
} uiButNumber;
/** Derived struct for #UI_BTYPE_COLOR */ /** Derived struct for #UI_BTYPE_COLOR */
typedef struct uiButColor { typedef struct uiButColor {
uiBut but; uiBut but;

View File

@@ -629,7 +629,10 @@ static void ui_item_array(uiLayout *layout,
w, w,
UI_UNIT_Y); UI_UNIT_Y);
if (slider && but->type == UI_BTYPE_NUM) { if (slider && but->type == UI_BTYPE_NUM) {
but->type = UI_BTYPE_NUM_SLIDER; uiButNumber *number_but = (uiButNumber *)but;
but->a1 = number_but->step_size;
ui_but_change_type(but, UI_BTYPE_NUM_SLIDER);
} }
} }
} }
@@ -697,7 +700,10 @@ static void ui_item_array(uiLayout *layout,
but = uiDefAutoButR(block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y); but = uiDefAutoButR(block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y);
if (slider && but->type == UI_BTYPE_NUM) { if (slider && but->type == UI_BTYPE_NUM) {
but->type = UI_BTYPE_NUM_SLIDER; uiButNumber *number_but = (uiButNumber *)but;
but->a1 = number_but->step_size;
ui_but_change_type(but, UI_BTYPE_NUM_SLIDER);
} }
if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) { if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) {
but->type = UI_BTYPE_TOGGLE; but->type = UI_BTYPE_TOGGLE;
@@ -2290,7 +2296,10 @@ void uiItemFullR(uiLayout *layout,
but = uiDefAutoButR(block, ptr, prop, index, name, icon, 0, 0, w, h); but = uiDefAutoButR(block, ptr, prop, index, name, icon, 0, 0, w, h);
if (slider && but->type == UI_BTYPE_NUM) { if (slider && but->type == UI_BTYPE_NUM) {
but->type = UI_BTYPE_NUM_SLIDER; uiButNumber *num_but = (uiButNumber *)but;
but->a1 = num_but->step_size;
ui_but_change_type(but, UI_BTYPE_NUM_SLIDER);
} }
if (flag & UI_ITEM_R_CHECKBOX_INVERT) { if (flag & UI_ITEM_R_CHECKBOX_INVERT) {

View File

@@ -3319,7 +3319,7 @@ static void colorband_buttons_layout(uiLayout *layout,
split = uiLayoutSplit(layout, 0.3f, false); split = uiLayoutSplit(layout, 0.3f, false);
row = uiLayoutRow(split, false); row = uiLayoutRow(split, false);
uiDefButS(block, bt = uiDefButS(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
"", "",
@@ -3330,9 +3330,11 @@ static void colorband_buttons_layout(uiLayout *layout,
&coba->cur, &coba->cur,
0.0, 0.0,
(float)(MAX2(0, coba->tot - 1)), (float)(MAX2(0, coba->tot - 1)),
1, 0,
0, 0,
TIP_("Choose active color stop")); TIP_("Choose active color stop"));
UI_but_number_step_size_set(bt, 1);
row = uiLayoutRow(split, false); row = uiLayoutRow(split, false);
uiItemR(row, &ptr, "position", 0, IFACE_("Pos"), ICON_NONE); uiItemR(row, &ptr, "position", 0, IFACE_("Pos"), ICON_NONE);
bt = block->buttons.last; bt = block->buttons.last;
@@ -3349,7 +3351,7 @@ static void colorband_buttons_layout(uiLayout *layout,
subsplit = uiLayoutSplit(split, 0.35f, false); subsplit = uiLayoutSplit(split, 0.35f, false);
row = uiLayoutRow(subsplit, false); row = uiLayoutRow(subsplit, false);
uiDefButS(block, bt = uiDefButS(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
"", "",
@@ -3360,9 +3362,11 @@ static void colorband_buttons_layout(uiLayout *layout,
&coba->cur, &coba->cur,
0.0, 0.0,
(float)(MAX2(0, coba->tot - 1)), (float)(MAX2(0, coba->tot - 1)),
1, 0,
0, 0,
TIP_("Choose active color stop")); TIP_("Choose active color stop"));
UI_but_number_step_size_set(bt, 1);
row = uiLayoutRow(subsplit, false); row = uiLayoutRow(subsplit, false);
uiItemR(row, &ptr, "position", UI_ITEM_R_SLIDER, IFACE_("Pos"), ICON_NONE); uiItemR(row, &ptr, "position", UI_ITEM_R_SLIDER, IFACE_("Pos"), ICON_NONE);
bt = block->buttons.last; bt = block->buttons.last;
@@ -3915,7 +3919,7 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap
UI_but_func_set(bt, curvemap_buttons_setclip, cumap, NULL); UI_but_func_set(bt, curvemap_buttons_setclip, cumap, NULL);
UI_block_align_begin(block); UI_block_align_begin(block);
uiDefButF(block, bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
IFACE_("Min X:"), IFACE_("Min X:"),
@@ -3926,10 +3930,12 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap
&cumap->clipr.xmin, &cumap->clipr.xmin,
-100.0, -100.0,
cumap->clipr.xmax, cumap->clipr.xmax,
10, 0,
2, 0,
""); "");
uiDefButF(block, UI_but_number_step_size_set(bt, 10);
UI_but_number_precision_set(bt, 2);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
IFACE_("Min Y:"), IFACE_("Min Y:"),
@@ -3940,10 +3946,12 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap
&cumap->clipr.ymin, &cumap->clipr.ymin,
-100.0, -100.0,
cumap->clipr.ymax, cumap->clipr.ymax,
10, 0,
2, 0,
""); "");
uiDefButF(block, UI_but_number_step_size_set(bt, 10);
UI_but_number_precision_set(bt, 2);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
IFACE_("Max X:"), IFACE_("Max X:"),
@@ -3954,10 +3962,12 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap
&cumap->clipr.xmax, &cumap->clipr.xmax,
cumap->clipr.xmin, cumap->clipr.xmin,
100.0, 100.0,
10, 0,
2, 0,
""); "");
uiDefButF(block, UI_but_number_step_size_set(bt, 10);
UI_but_number_precision_set(bt, 2);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
IFACE_("Max Y:"), IFACE_("Max Y:"),
@@ -3968,9 +3978,11 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap
&cumap->clipr.ymax, &cumap->clipr.ymax,
cumap->clipr.ymin, cumap->clipr.ymin,
100.0, 100.0,
10, 0,
2, 0,
""); "");
UI_but_number_step_size_set(bt, 10);
UI_but_number_precision_set(bt, 2);
UI_block_bounds_set_normal(block, 0.3f * U.widget_unit); UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
UI_block_direction_set(block, UI_DIR_DOWN); UI_block_direction_set(block, UI_DIR_DOWN);
@@ -4464,7 +4476,7 @@ static void curvemap_buttons_layout(uiLayout *layout,
uiLayoutRow(layout, true); uiLayoutRow(layout, true);
UI_block_funcN_set(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap); UI_block_funcN_set(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap);
uiDefButF(block, bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
"X", "X",
@@ -4475,10 +4487,12 @@ static void curvemap_buttons_layout(uiLayout *layout,
&cmp->x, &cmp->x,
bounds.xmin, bounds.xmin,
bounds.xmax, bounds.xmax,
1, 0,
5, 0,
""); "");
uiDefButF(block, UI_but_number_step_size_set(bt, 1);
UI_but_number_precision_set(bt, 5);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
"Y", "Y",
@@ -4489,9 +4503,11 @@ static void curvemap_buttons_layout(uiLayout *layout,
&cmp->y, &cmp->y,
bounds.ymin, bounds.ymin,
bounds.ymax, bounds.ymax,
1, 0,
5, 0,
""); "");
UI_but_number_step_size_set(bt, 1);
UI_but_number_precision_set(bt, 5);
} }
/* black/white levels */ /* black/white levels */
@@ -5075,9 +5091,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
selection_x, selection_x,
bounds.xmin, bounds.xmin,
bounds.xmax, bounds.xmax,
1, 0,
5, 0,
""); "");
UI_but_number_step_size_set(bt, 1);
UI_but_number_precision_set(bt, 5);
UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile); UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile);
if (point_last_or_first) { if (point_last_or_first) {
UI_but_flag_enable(bt, UI_BUT_DISABLED); UI_but_flag_enable(bt, UI_BUT_DISABLED);
@@ -5093,9 +5111,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
selection_y, selection_y,
bounds.ymin, bounds.ymin,
bounds.ymax, bounds.ymax,
1, 0,
5, 0,
""); "");
UI_but_number_step_size_set(bt, 1);
UI_but_number_precision_set(bt, 5);
UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile); UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile);
if (point_last_or_first) { if (point_last_or_first) {
UI_but_flag_enable(bt, UI_BUT_DISABLED); UI_but_flag_enable(bt, UI_BUT_DISABLED);

View File

@@ -164,7 +164,7 @@ uiBut *uiDefAutoButR(uiBlock *block,
} }
else { else {
but = uiDefButR_prop( but = uiDefButR_prop(
block, UI_BTYPE_NUM, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); block, UI_BTYPE_NUM, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, 0, 0, NULL);
} }
if (RNA_property_flag(prop) & PROP_TEXTEDIT_UPDATE) { if (RNA_property_flag(prop) & PROP_TEXTEDIT_UPDATE) {

View File

@@ -585,7 +585,7 @@ void uiTemplateMarker(uiLayout *layout,
0, 0,
0, 0,
""); "");
uiDefButF(block, bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_POS, B_MARKER_POS,
IFACE_("X:"), IFACE_("X:"),
@@ -596,10 +596,12 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_pos[0], &cb->marker_pos[0],
-10 * width, -10 * width,
10.0 * width, 10.0 * width,
step, 0,
digits, 0,
TIP_("X-position of marker at frame in screen coordinates")); TIP_("X-position of marker at frame in screen coordinates"));
uiDefButF(block, UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_POS, B_MARKER_POS,
IFACE_("Y:"), IFACE_("Y:"),
@@ -610,9 +612,11 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_pos[1], &cb->marker_pos[1],
-10 * height, -10 * height,
10.0 * height, 10.0 * height,
step, 0,
digits, 0,
TIP_("Y-position of marker at frame in screen coordinates")); TIP_("Y-position of marker at frame in screen coordinates"));
UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
uiDefBut(block, uiDefBut(block,
UI_BTYPE_LABEL, UI_BTYPE_LABEL,
@@ -628,7 +632,7 @@ void uiTemplateMarker(uiLayout *layout,
0, 0,
0, 0,
""); "");
uiDefButF(block, bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_OFFSET, B_MARKER_OFFSET,
IFACE_("X:"), IFACE_("X:"),
@@ -639,10 +643,12 @@ void uiTemplateMarker(uiLayout *layout,
&cb->track_offset[0], &cb->track_offset[0],
-10 * width, -10 * width,
10.0 * width, 10.0 * width,
step, 0,
digits, 0,
TIP_("X-offset to parenting point")); TIP_("X-offset to parenting point"));
uiDefButF(block, UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_OFFSET, B_MARKER_OFFSET,
IFACE_("Y:"), IFACE_("Y:"),
@@ -653,9 +659,11 @@ void uiTemplateMarker(uiLayout *layout,
&cb->track_offset[1], &cb->track_offset[1],
-10 * height, -10 * height,
10.0 * height, 10.0 * height,
step, 0,
digits, 0,
TIP_("Y-offset to parenting point")); TIP_("Y-offset to parenting point"));
UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
uiDefBut(block, uiDefBut(block,
UI_BTYPE_LABEL, UI_BTYPE_LABEL,
@@ -671,7 +679,7 @@ void uiTemplateMarker(uiLayout *layout,
0, 0,
0, 0,
""); "");
uiDefButF(block, bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_PAT_DIM, B_MARKER_PAT_DIM,
IFACE_("Width:"), IFACE_("Width:"),
@@ -682,10 +690,12 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_pat[0], &cb->marker_pat[0],
3.0f, 3.0f,
10.0 * width, 10.0 * width,
step, 0,
digits, 0,
TIP_("Width of marker's pattern in screen coordinates")); TIP_("Width of marker's pattern in screen coordinates"));
uiDefButF(block, UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_PAT_DIM, B_MARKER_PAT_DIM,
IFACE_("Height:"), IFACE_("Height:"),
@@ -696,9 +706,11 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_pat[1], &cb->marker_pat[1],
3.0f, 3.0f,
10.0 * height, 10.0 * height,
step, 0,
digits, 0,
TIP_("Height of marker's pattern in screen coordinates")); TIP_("Height of marker's pattern in screen coordinates"));
UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
uiDefBut(block, uiDefBut(block,
UI_BTYPE_LABEL, UI_BTYPE_LABEL,
@@ -714,7 +726,7 @@ void uiTemplateMarker(uiLayout *layout,
0, 0,
0, 0,
""); "");
uiDefButF(block, bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_SEARCH_POS, B_MARKER_SEARCH_POS,
IFACE_("X:"), IFACE_("X:"),
@@ -725,10 +737,12 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_search_pos[0], &cb->marker_search_pos[0],
-width, -width,
width, width,
step, 0,
digits, 0,
TIP_("X-position of search at frame relative to marker's position")); TIP_("X-position of search at frame relative to marker's position"));
uiDefButF(block, UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_SEARCH_POS, B_MARKER_SEARCH_POS,
IFACE_("Y:"), IFACE_("Y:"),
@@ -739,10 +753,12 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_search_pos[1], &cb->marker_search_pos[1],
-height, -height,
height, height,
step, 0,
digits, 0,
TIP_("Y-position of search at frame relative to marker's position")); TIP_("Y-position of search at frame relative to marker's position"));
uiDefButF(block, UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_SEARCH_DIM, B_MARKER_SEARCH_DIM,
IFACE_("Width:"), IFACE_("Width:"),
@@ -753,10 +769,12 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_search[0], &cb->marker_search[0],
3.0f, 3.0f,
10.0 * width, 10.0 * width,
step, 0,
digits, 0,
TIP_("Width of marker's search in screen coordinates")); TIP_("Width of marker's search in screen coordinates"));
uiDefButF(block, UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
bt = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_MARKER_SEARCH_DIM, B_MARKER_SEARCH_DIM,
IFACE_("Height:"), IFACE_("Height:"),
@@ -767,9 +785,11 @@ void uiTemplateMarker(uiLayout *layout,
&cb->marker_search[1], &cb->marker_search[1],
3.0f, 3.0f,
10.0 * height, 10.0 * height,
step, 0,
digits, 0,
TIP_("Height of marker's search in screen coordinates")); TIP_("Height of marker's search in screen coordinates"));
UI_but_number_step_size_set(bt, step);
UI_but_number_precision_set(bt, digits);
UI_block_align_end(block); UI_block_align_end(block);
} }

View File

@@ -437,8 +437,8 @@ static void graph_panel_key_properties(const bContext *C, Panel *panel)
0, 0,
0, 0,
0, 0,
-1, 0,
-1, 0,
NULL); NULL);
uiItemL_respect_property_split(col, IFACE_("Value"), ICON_NONE); uiItemL_respect_property_split(col, IFACE_("Value"), ICON_NONE);
@@ -455,8 +455,8 @@ static void graph_panel_key_properties(const bContext *C, Panel *panel)
1, 1,
0, 0,
0, 0,
-1, 0,
-1, 0,
NULL); NULL);
UI_but_func_set(but, graphedit_activekey_update_cb, fcu, bezt); UI_but_func_set(but, graphedit_activekey_update_cb, fcu, bezt);
UI_but_unit_type_set(but, unit); UI_but_unit_type_set(but, unit);
@@ -501,8 +501,8 @@ static void graph_panel_key_properties(const bContext *C, Panel *panel)
0, 0,
0, 0,
0, 0,
-1, 0,
-1, 0,
NULL); NULL);
UI_but_func_set(but, graphedit_activekey_left_handle_coord_cb, fcu, bezt); UI_but_func_set(but, graphedit_activekey_left_handle_coord_cb, fcu, bezt);
@@ -520,8 +520,8 @@ static void graph_panel_key_properties(const bContext *C, Panel *panel)
1, 1,
0, 0,
0, 0,
-1, 0,
-1, 0,
NULL); NULL);
UI_but_func_set(but, graphedit_activekey_left_handle_coord_cb, fcu, bezt); UI_but_func_set(but, graphedit_activekey_left_handle_coord_cb, fcu, bezt);
UI_but_unit_type_set(but, unit); UI_but_unit_type_set(but, unit);
@@ -565,8 +565,8 @@ static void graph_panel_key_properties(const bContext *C, Panel *panel)
0, 0,
0, 0,
0, 0,
-1, 0,
-1, 0,
NULL); NULL);
UI_but_func_set(but, graphedit_activekey_right_handle_coord_cb, fcu, bezt); UI_but_func_set(but, graphedit_activekey_right_handle_coord_cb, fcu, bezt);
@@ -584,8 +584,8 @@ static void graph_panel_key_properties(const bContext *C, Panel *panel)
1, 1,
0, 0,
0, 0,
-1, 0,
-1, 0,
NULL); NULL);
UI_but_func_set(but, graphedit_activekey_right_handle_coord_cb, fcu, bezt); UI_but_func_set(but, graphedit_activekey_right_handle_coord_cb, fcu, bezt);
UI_but_unit_type_set(but, unit); UI_but_unit_type_set(but, unit);

View File

@@ -472,9 +472,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&tfp->ve_median.generic.location[0], &tfp->ve_median.generic.location[0],
-lim, -lim,
lim, lim,
10, 0,
RNA_TRANSLATION_PREC_DEFAULT, 0,
""); "");
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, RNA_TRANSLATION_PREC_DEFAULT);
UI_but_unit_type_set(but, PROP_UNIT_LENGTH); UI_but_unit_type_set(but, PROP_UNIT_LENGTH);
but = uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
@@ -487,9 +489,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&tfp->ve_median.generic.location[1], &tfp->ve_median.generic.location[1],
-lim, -lim,
lim, lim,
10, 0,
RNA_TRANSLATION_PREC_DEFAULT, 0,
""); "");
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, RNA_TRANSLATION_PREC_DEFAULT);
UI_but_unit_type_set(but, PROP_UNIT_LENGTH); UI_but_unit_type_set(but, PROP_UNIT_LENGTH);
but = uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
@@ -502,13 +506,15 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&tfp->ve_median.generic.location[2], &tfp->ve_median.generic.location[2],
-lim, -lim,
lim, lim,
10, 0,
RNA_TRANSLATION_PREC_DEFAULT, 0,
""); "");
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, RNA_TRANSLATION_PREC_DEFAULT);
UI_but_unit_type_set(but, PROP_UNIT_LENGTH); UI_but_unit_type_set(but, PROP_UNIT_LENGTH);
if (totcurvebweight == tot) { if (totcurvebweight == tot) {
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
IFACE_("W:"), IFACE_("W:"),
@@ -519,9 +525,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&(tfp->ve_median.curve.b_weight), &(tfp->ve_median.curve.b_weight),
0.01, 0.01,
100.0, 100.0,
1, 0,
3, 0,
""); "");
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
} }
UI_block_align_begin(block); UI_block_align_begin(block);
@@ -576,7 +584,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
0, 0,
""); "");
/* customdata layer added on demand */ /* customdata layer added on demand */
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
tot == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"), tot == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"),
@@ -587,13 +595,15 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->bv_weight, &ve_median->bv_weight,
0.0, 0.0,
1.0, 1.0,
1, 0,
2, 0,
TIP_("Vertex weight used by Bevel modifier")); TIP_("Vertex weight used by Bevel modifier"));
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 2);
} }
if (has_skinradius) { if (has_skinradius) {
UI_block_align_begin(block); UI_block_align_begin(block);
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
tot == 1 ? IFACE_("Radius X:") : IFACE_("Mean Radius X:"), tot == 1 ? IFACE_("Radius X:") : IFACE_("Mean Radius X:"),
@@ -604,10 +614,12 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->skin[0], &ve_median->skin[0],
0.0, 0.0,
100.0, 100.0,
1, 0,
3, 0,
TIP_("X radius used by Skin modifier")); TIP_("X radius used by Skin modifier"));
uiDefButF(block, UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
tot == 1 ? IFACE_("Radius Y:") : IFACE_("Mean Radius Y:"), tot == 1 ? IFACE_("Radius Y:") : IFACE_("Mean Radius Y:"),
@@ -618,9 +630,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->skin[1], &ve_median->skin[1],
0.0, 0.0,
100.0, 100.0,
1, 0,
3, 0,
TIP_("Y radius used by Skin modifier")); TIP_("Y radius used by Skin modifier"));
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
UI_block_align_end(block); UI_block_align_end(block);
} }
if (totedgedata) { if (totedgedata) {
@@ -639,7 +653,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
0, 0,
""); "");
/* customdata layer added on demand */ /* customdata layer added on demand */
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
totedgedata == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"), totedgedata == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"),
@@ -650,11 +664,13 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->be_weight, &ve_median->be_weight,
0.0, 0.0,
1.0, 1.0,
1, 0,
2, 0,
TIP_("Edge weight used by Bevel modifier")); TIP_("Edge weight used by Bevel modifier"));
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 2);
/* customdata layer added on demand */ /* customdata layer added on demand */
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
totedgedata == 1 ? IFACE_("Crease:") : IFACE_("Mean Crease:"), totedgedata == 1 ? IFACE_("Crease:") : IFACE_("Mean Crease:"),
@@ -665,16 +681,18 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->crease, &ve_median->crease,
0.0, 0.0,
1.0, 1.0,
1, 0,
2, 0,
TIP_("Weight used by the Subdivision Surface modifier")); TIP_("Weight used by the Subdivision Surface modifier"));
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 2);
} }
} }
/* Curve... */ /* Curve... */
else if (totcurvedata) { else if (totcurvedata) {
TransformMedian_Curve *ve_median = &tfp->ve_median.curve; TransformMedian_Curve *ve_median = &tfp->ve_median.curve;
if (totcurvedata == 1) { if (totcurvedata == 1) {
uiDefButR(block, but = uiDefButR(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
IFACE_("Weight:"), IFACE_("Weight:"),
@@ -687,10 +705,12 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
0, 0,
0.0, 0.0,
1.0, 1.0,
1, 0,
3, 0,
NULL); NULL);
uiDefButR(block, UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
but = uiDefButR(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
IFACE_("Radius:"), IFACE_("Radius:"),
@@ -703,10 +723,12 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
0, 0,
0.0, 0.0,
100.0, 100.0,
1, 0,
3, 0,
NULL); NULL);
uiDefButR(block, UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
but = uiDefButR(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
0, 0,
IFACE_("Tilt:"), IFACE_("Tilt:"),
@@ -719,12 +741,14 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
0, 0,
-tilt_limit, -tilt_limit,
tilt_limit, tilt_limit,
1, 0,
3, 0,
NULL); NULL);
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
} }
else if (totcurvedata > 1) { else if (totcurvedata > 1) {
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
IFACE_("Mean Weight:"), IFACE_("Mean Weight:"),
@@ -735,10 +759,12 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->weight, &ve_median->weight,
0.0, 0.0,
1.0, 1.0,
1, 0,
3, 0,
TIP_("Weight used for Soft Body Goal")); TIP_("Weight used for Soft Body Goal"));
uiDefButF(block, UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
IFACE_("Mean Radius:"), IFACE_("Mean Radius:"),
@@ -749,9 +775,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->radius, &ve_median->radius,
0.0, 0.0,
100.0, 100.0,
1, 0,
3, 0,
TIP_("Radius of curve control points")); TIP_("Radius of curve control points"));
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
but = uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
@@ -763,9 +791,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->tilt, &ve_median->tilt,
-tilt_limit, -tilt_limit,
tilt_limit, tilt_limit,
1, 0,
3, 0,
TIP_("Tilt of curve control points")); TIP_("Tilt of curve control points"));
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
UI_but_unit_type_set(but, PROP_UNIT_ROTATION); UI_but_unit_type_set(but, PROP_UNIT_ROTATION);
} }
} }
@@ -786,12 +816,14 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
0, 0,
0.0, 0.0,
1.0, 1.0,
1, 0,
3, 0,
NULL); NULL);
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
} }
else if (totlattdata > 1) { else if (totlattdata > 1) {
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_TRANSFORM_PANEL_MEDIAN, B_TRANSFORM_PANEL_MEDIAN,
IFACE_("Mean Weight:"), IFACE_("Mean Weight:"),
@@ -802,9 +834,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
&ve_median->weight, &ve_median->weight,
0.0, 0.0,
1.0, 1.0,
1, 0,
3, 0,
TIP_("Weight used for Soft Body Goal")); TIP_("Weight used for Soft Body Goal"));
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
} }
} }
@@ -1083,9 +1117,11 @@ static void v3d_object_dimension_buts(bContext *C, uiLayout *layout, View3D *v3d
&(tfp->ob_dims[i]), &(tfp->ob_dims[i]),
0.0f, 0.0f,
lim, lim,
10, 0,
3, 0,
""); "");
UI_but_number_step_size_set(but, 10);
UI_but_number_precision_set(but, 3);
UI_but_unit_type_set(but, PROP_UNIT_LENGTH); UI_but_unit_type_set(but, PROP_UNIT_LENGTH);
} }
UI_block_align_end(block); UI_block_align_end(block);
@@ -1225,9 +1261,11 @@ static void view3d_panel_vgroup(const bContext *C, Panel *panel)
&dw->weight, &dw->weight,
0.0, 0.0,
1.0, 1.0,
1, 0,
3, 0,
""); "");
UI_but_number_step_size_set(but, 1);
UI_but_number_precision_set(but, 3);
UI_but_drawflag_enable(but, UI_BUT_TEXT_LEFT); UI_but_drawflag_enable(but, UI_BUT_TEXT_LEFT);
if (locked) { if (locked) {
lock_count++; lock_count++;

View File

@@ -175,8 +175,10 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block)
digits = 2; digits = 2;
} }
uiBut *but;
UI_block_align_begin(block); UI_block_align_begin(block);
uiDefButF(block, but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_UVEDIT_VERTEX, B_UVEDIT_VERTEX,
IFACE_("X:"), IFACE_("X:"),
@@ -186,10 +188,12 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block)
UI_UNIT_Y, UI_UNIT_Y,
&uvedit_old_center[0], &uvedit_old_center[0],
UNPACK2(range_xy[0]), UNPACK2(range_xy[0]),
step, 0,
digits, 0,
""); "");
uiDefButF(block, UI_but_number_step_size_set(but, step);
UI_but_number_precision_set(but, digits);
but = uiDefButF(block,
UI_BTYPE_NUM, UI_BTYPE_NUM,
B_UVEDIT_VERTEX, B_UVEDIT_VERTEX,
IFACE_("Y:"), IFACE_("Y:"),
@@ -199,9 +203,11 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block)
UI_UNIT_Y, UI_UNIT_Y,
&uvedit_old_center[1], &uvedit_old_center[1],
UNPACK2(range_xy[1]), UNPACK2(range_xy[1]),
step, 0,
digits, 0,
""); "");
UI_but_number_step_size_set(but, step);
UI_but_number_precision_set(but, digits);
UI_block_align_end(block); UI_block_align_end(block);
} }