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,20 +257,22 @@ 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,
"", "",
0, 0,
0, 0,
bwidth / 2, bwidth / 2,
UI_UNIT_Y, UI_UNIT_Y,
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,20 +390,22 @@ 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,
"", "",
0, 0,
0, 0,
5 * UI_UNIT_X, 5 * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
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,20 +422,22 @@ 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,
"", "",
0, 0,
0, 0,
5 * UI_UNIT_X, 5 * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
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,54 +732,60 @@ 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:"),
0, 0,
0, 0,
4.5 * UI_UNIT_X, 4.5 * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
&ctrl_ptr, &ctrl_ptr,
"frame", "frame",
-1, -1,
-MAXFRAMEF, -MAXFRAMEF,
MAXFRAMEF, MAXFRAMEF,
10, 0,
1, 0,
NULL); NULL);
uiDefButR(block, UI_but_number_step_size_set(but, 10);
UI_BTYPE_NUM, UI_but_number_precision_set(but, 1);
B_FMODIFIER_REDRAW, but = uiDefButR(block,
IFACE_("Min:"), UI_BTYPE_NUM,
0, B_FMODIFIER_REDRAW,
0, IFACE_("Min:"),
5 * UI_UNIT_X, 0,
UI_UNIT_Y, 0,
&ctrl_ptr, 5 * UI_UNIT_X,
"min", UI_UNIT_Y,
-1, &ctrl_ptr,
-UI_FLT_MAX, "min",
UI_FLT_MAX, -1,
10, -UI_FLT_MAX,
2, UI_FLT_MAX,
NULL); 0,
uiDefButR(block, 0,
UI_BTYPE_NUM, NULL);
B_FMODIFIER_REDRAW, UI_but_number_step_size_set(but, 10);
IFACE_("Max:"), UI_but_number_precision_set(but, 2);
0, but = uiDefButR(block,
0, UI_BTYPE_NUM,
5 * UI_UNIT_X, B_FMODIFIER_REDRAW,
UI_UNIT_Y, IFACE_("Max:"),
&ctrl_ptr, 0,
"max", 0,
-1, 5 * UI_UNIT_X,
-UI_FLT_MAX, UI_UNIT_Y,
UI_FLT_MAX, &ctrl_ptr,
10, "max",
2, -1,
NULL); -UI_FLT_MAX,
UI_FLT_MAX,
0,
0,
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,7 +4540,13 @@ 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)) {
but->a1 = ui_get_but_step_unit(but, but->a1); 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);
}
} }
if (func) { if (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,20 +3319,22 @@ 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,
"", "",
0, 0,
0, 0,
5.0f * UI_UNIT_X, 5.0f * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
&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,20 +3351,22 @@ 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,
"", "",
0, 0,
0, 0,
5.0f * UI_UNIT_X, 5.0f * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
&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,62 +3919,70 @@ 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:"),
0, 0,
4 * UI_UNIT_Y, 4 * UI_UNIT_Y,
width, width,
UI_UNIT_Y, UI_UNIT_Y,
&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_BTYPE_NUM, UI_but_number_precision_set(bt, 2);
0, bt = uiDefButF(block,
IFACE_("Min Y:"), UI_BTYPE_NUM,
0, 0,
3 * UI_UNIT_Y, IFACE_("Min Y:"),
width, 0,
UI_UNIT_Y, 3 * UI_UNIT_Y,
&cumap->clipr.ymin, width,
-100.0, UI_UNIT_Y,
cumap->clipr.ymax, &cumap->clipr.ymin,
10, -100.0,
2, cumap->clipr.ymax,
""); 0,
uiDefButF(block, 0,
UI_BTYPE_NUM, "");
0, UI_but_number_step_size_set(bt, 10);
IFACE_("Max X:"), UI_but_number_precision_set(bt, 2);
0, bt = uiDefButF(block,
2 * UI_UNIT_Y, UI_BTYPE_NUM,
width, 0,
UI_UNIT_Y, IFACE_("Max X:"),
&cumap->clipr.xmax, 0,
cumap->clipr.xmin, 2 * UI_UNIT_Y,
100.0, width,
10, UI_UNIT_Y,
2, &cumap->clipr.xmax,
""); cumap->clipr.xmin,
uiDefButF(block, 100.0,
UI_BTYPE_NUM, 0,
0, 0,
IFACE_("Max Y:"), "");
0, UI_but_number_step_size_set(bt, 10);
UI_UNIT_Y, UI_but_number_precision_set(bt, 2);
width, bt = uiDefButF(block,
UI_UNIT_Y, UI_BTYPE_NUM,
&cumap->clipr.ymax, 0,
cumap->clipr.ymin, IFACE_("Max Y:"),
100.0, 0,
10, UI_UNIT_Y,
2, width,
""); UI_UNIT_Y,
&cumap->clipr.ymax,
cumap->clipr.ymin,
100.0,
0,
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,34 +4476,38 @@ 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",
0, 0,
2 * UI_UNIT_Y, 2 * UI_UNIT_Y,
UI_UNIT_X * 10, UI_UNIT_X * 10,
UI_UNIT_Y, UI_UNIT_Y,
&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_BTYPE_NUM, UI_but_number_precision_set(bt, 5);
0, bt = uiDefButF(block,
"Y", UI_BTYPE_NUM,
0, 0,
1 * UI_UNIT_Y, "Y",
UI_UNIT_X * 10, 0,
UI_UNIT_Y, 1 * UI_UNIT_Y,
&cmp->y, UI_UNIT_X * 10,
bounds.ymin, UI_UNIT_Y,
bounds.ymax, &cmp->y,
1, bounds.ymin,
5, bounds.ymax,
""); 0,
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,34 +585,38 @@ 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:"),
0.5 * UI_UNIT_X, 0.5 * UI_UNIT_X,
9 * UI_UNIT_Y, 9 * UI_UNIT_Y,
7.25 * UI_UNIT_X, 7.25 * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
&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_BTYPE_NUM, UI_but_number_precision_set(bt, digits);
B_MARKER_POS, bt = uiDefButF(block,
IFACE_("Y:"), UI_BTYPE_NUM,
8.25 * UI_UNIT_X, B_MARKER_POS,
9 * UI_UNIT_Y, IFACE_("Y:"),
7.25 * UI_UNIT_X, 8.25 * UI_UNIT_X,
UI_UNIT_Y, 9 * UI_UNIT_Y,
&cb->marker_pos[1], 7.25 * UI_UNIT_X,
-10 * height, UI_UNIT_Y,
10.0 * height, &cb->marker_pos[1],
step, -10 * height,
digits, 10.0 * height,
TIP_("Y-position of marker at frame in screen coordinates")); 0,
0,
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,34 +632,38 @@ 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:"),
0.5 * UI_UNIT_X, 0.5 * UI_UNIT_X,
7 * UI_UNIT_Y, 7 * UI_UNIT_Y,
7.25 * UI_UNIT_X, 7.25 * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
&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_BTYPE_NUM, UI_but_number_precision_set(bt, digits);
B_MARKER_OFFSET, bt = uiDefButF(block,
IFACE_("Y:"), UI_BTYPE_NUM,
8.25 * UI_UNIT_X, B_MARKER_OFFSET,
7 * UI_UNIT_Y, IFACE_("Y:"),
7.25 * UI_UNIT_X, 8.25 * UI_UNIT_X,
UI_UNIT_Y, 7 * UI_UNIT_Y,
&cb->track_offset[1], 7.25 * UI_UNIT_X,
-10 * height, UI_UNIT_Y,
10.0 * height, &cb->track_offset[1],
step, -10 * height,
digits, 10.0 * height,
TIP_("Y-offset to parenting point")); 0,
0,
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,34 +679,38 @@ 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:"),
0.5 * UI_UNIT_X, 0.5 * UI_UNIT_X,
5 * UI_UNIT_Y, 5 * UI_UNIT_Y,
15 * UI_UNIT_X, 15 * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
&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_BTYPE_NUM, UI_but_number_precision_set(bt, digits);
B_MARKER_PAT_DIM, bt = uiDefButF(block,
IFACE_("Height:"), UI_BTYPE_NUM,
0.5 * UI_UNIT_X, B_MARKER_PAT_DIM,
4 * UI_UNIT_Y, IFACE_("Height:"),
15 * UI_UNIT_X, 0.5 * UI_UNIT_X,
UI_UNIT_Y, 4 * UI_UNIT_Y,
&cb->marker_pat[1], 15 * UI_UNIT_X,
3.0f, UI_UNIT_Y,
10.0 * height, &cb->marker_pat[1],
step, 3.0f,
digits, 10.0 * height,
TIP_("Height of marker's pattern in screen coordinates")); 0,
0,
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,62 +726,70 @@ 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:"),
0.5 * UI_UNIT_X, 0.5 * UI_UNIT_X,
2 * UI_UNIT_Y, 2 * UI_UNIT_Y,
7.25 * UI_UNIT_X, 7.25 * UI_UNIT_X,
UI_UNIT_Y, UI_UNIT_Y,
&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_BTYPE_NUM, UI_but_number_precision_set(bt, digits);
B_MARKER_SEARCH_POS, bt = uiDefButF(block,
IFACE_("Y:"), UI_BTYPE_NUM,
8.25 * UI_UNIT_X, B_MARKER_SEARCH_POS,
2 * UI_UNIT_Y, IFACE_("Y:"),
7.25 * UI_UNIT_X, 8.25 * UI_UNIT_X,
UI_UNIT_Y, 2 * UI_UNIT_Y,
&cb->marker_search_pos[1], 7.25 * UI_UNIT_X,
-height, UI_UNIT_Y,
height, &cb->marker_search_pos[1],
step, -height,
digits, height,
TIP_("Y-position of search at frame relative to marker's position")); 0,
uiDefButF(block, 0,
UI_BTYPE_NUM, TIP_("Y-position of search at frame relative to marker's position"));
B_MARKER_SEARCH_DIM, UI_but_number_step_size_set(bt, step);
IFACE_("Width:"), UI_but_number_precision_set(bt, digits);
0.5 * UI_UNIT_X, bt = uiDefButF(block,
1 * UI_UNIT_Y, UI_BTYPE_NUM,
15 * UI_UNIT_X, B_MARKER_SEARCH_DIM,
UI_UNIT_Y, IFACE_("Width:"),
&cb->marker_search[0], 0.5 * UI_UNIT_X,
3.0f, 1 * UI_UNIT_Y,
10.0 * width, 15 * UI_UNIT_X,
step, UI_UNIT_Y,
digits, &cb->marker_search[0],
TIP_("Width of marker's search in screen coordinates")); 3.0f,
uiDefButF(block, 10.0 * width,
UI_BTYPE_NUM, 0,
B_MARKER_SEARCH_DIM, 0,
IFACE_("Height:"), TIP_("Width of marker's search in screen coordinates"));
0.5 * UI_UNIT_X, UI_but_number_step_size_set(bt, step);
0 * UI_UNIT_Y, UI_but_number_precision_set(bt, digits);
15 * UI_UNIT_X, bt = uiDefButF(block,
UI_UNIT_Y, UI_BTYPE_NUM,
&cb->marker_search[1], B_MARKER_SEARCH_DIM,
3.0f, IFACE_("Height:"),
10.0 * height, 0.5 * UI_UNIT_X,
step, 0 * UI_UNIT_Y,
digits, 15 * UI_UNIT_X,
TIP_("Height of marker's search in screen coordinates")); UI_UNIT_Y,
&cb->marker_search[1],
3.0f,
10.0 * height,
0,
0,
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,26 +506,30 @@ 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:"),
0, 0,
yi -= buth, yi -= buth,
butw, butw,
buth, buth,
&(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,51 +584,57 @@ 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:"),
0, 0,
yi -= buth + but_margin, yi -= buth + but_margin,
butw, butw,
buth, buth,
&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:"),
0, 0,
yi -= buth + but_margin, yi -= buth + but_margin,
butw, butw,
buth, buth,
&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_BTYPE_NUM, UI_but_number_precision_set(but, 3);
B_TRANSFORM_PANEL_MEDIAN, but = uiDefButF(block,
tot == 1 ? IFACE_("Radius Y:") : IFACE_("Mean Radius Y:"), UI_BTYPE_NUM,
0, B_TRANSFORM_PANEL_MEDIAN,
yi -= buth + but_margin, tot == 1 ? IFACE_("Radius Y:") : IFACE_("Mean Radius Y:"),
butw, 0,
buth, yi -= buth + but_margin,
&ve_median->skin[1], butw,
0.0, buth,
100.0, &ve_median->skin[1],
1, 0.0,
3, 100.0,
TIP_("Y radius used by Skin modifier")); 0,
0,
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,119 +653,133 @@ 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:"),
0, 0,
yi -= buth + but_margin, yi -= buth + but_margin,
butw, butw,
buth, buth,
&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:"),
0, 0,
yi -= buth + but_margin, yi -= buth + but_margin,
butw, butw,
buth, buth,
&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:"),
0, 0,
yi -= buth + but_margin, yi -= buth + but_margin,
butw, butw,
buth, buth,
&data_ptr, &data_ptr,
"weight_softbody", "weight_softbody",
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_BTYPE_NUM, UI_but_number_precision_set(but, 3);
0, but = uiDefButR(block,
IFACE_("Radius:"), UI_BTYPE_NUM,
0, 0,
yi -= buth + but_margin, IFACE_("Radius:"),
butw, 0,
buth, yi -= buth + but_margin,
&data_ptr, butw,
"radius", buth,
0, &data_ptr,
0.0, "radius",
100.0, 0,
1, 0.0,
3, 100.0,
NULL); 0,
uiDefButR(block, 0,
UI_BTYPE_NUM, NULL);
0, UI_but_number_step_size_set(but, 1);
IFACE_("Tilt:"), UI_but_number_precision_set(but, 3);
0, but = uiDefButR(block,
yi -= buth + but_margin, UI_BTYPE_NUM,
butw, 0,
buth, IFACE_("Tilt:"),
&data_ptr, 0,
"tilt", yi -= buth + but_margin,
0, butw,
-tilt_limit, buth,
tilt_limit, &data_ptr,
1, "tilt",
3, 0,
NULL); -tilt_limit,
tilt_limit,
0,
0,
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:"),
0, 0,
yi -= buth + but_margin, yi -= buth + but_margin,
butw, butw,
buth, buth,
&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_BTYPE_NUM, UI_but_number_precision_set(but, 3);
B_TRANSFORM_PANEL_MEDIAN, but = uiDefButF(block,
IFACE_("Mean Radius:"), UI_BTYPE_NUM,
0, B_TRANSFORM_PANEL_MEDIAN,
yi -= buth + but_margin, IFACE_("Mean Radius:"),
butw, 0,
buth, yi -= buth + but_margin,
&ve_median->radius, butw,
0.0, buth,
100.0, &ve_median->radius,
1, 0.0,
3, 100.0,
TIP_("Radius of curve control points")); 0,
0,
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,25 +816,29 @@ 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:"),
0, 0,
yi -= buth + but_margin, yi -= buth + but_margin,
butw, butw,
buth, buth,
&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,33 +175,39 @@ 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:"),
0, 0,
0, 0,
width, width,
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_BTYPE_NUM, UI_but_number_precision_set(but, digits);
B_UVEDIT_VERTEX, but = uiDefButF(block,
IFACE_("Y:"), UI_BTYPE_NUM,
width, B_UVEDIT_VERTEX,
0, IFACE_("Y:"),
width, width,
UI_UNIT_Y, 0,
&uvedit_old_center[1], width,
UNPACK2(range_xy[1]), UI_UNIT_Y,
step, &uvedit_old_center[1],
digits, UNPACK2(range_xy[1]),
""); 0,
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);
} }