UI: uiBut Indeterminate State #108210
|
@ -317,6 +317,9 @@ enum {
|
|||
|
||||
/* Draw the checkbox buttons inverted. */
|
||||
UI_BUT_CHECKBOX_INVERT = 1 << 25,
|
||||
|
||||
/* Drawn in a way that indicates that the state/value is unknown. */
|
||||
UI_BUT_INDETERMINATE = 1 << 26,
|
||||
Harley marked this conversation as resolved
Outdated
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -3861,7 +3861,9 @@ static void ui_but_update_ex(uiBut *but, const bool validate)
|
|||
}
|
||||
}
|
||||
}
|
||||
STRNCPY(but->drawstr, but->str);
|
||||
if (!(but->drawflag & UI_BUT_INDETERMINATE)) {
|
||||
STRNCPY(but->drawstr, but->str);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -3871,7 +3873,10 @@ static void ui_but_update_ex(uiBut *but, const bool validate)
|
|||
break;
|
||||
}
|
||||
Harley marked this conversation as resolved
Outdated
Julian Eisel
commented
Same here, not sure if we should permanently modify the drawing flags here. Can be done just before drawing. Actually, let's not even override the draw-string here, and just do that in Same here, not sure if we should permanently modify the drawing flags here. Can be done just before drawing.
Actually, let's not even override the draw-string here, and just do that in `widget_draw_text()` by setting `drawstr` to `UI_VALUE_INDETERMINATE_CHAR` for specific button types.
|
||||
UI_GET_BUT_VALUE_INIT(but, value);
|
||||
if (ui_but_is_float(but)) {
|
||||
if (but->drawflag & UI_BUT_INDETERMINATE) {
|
||||
/* Pass. */
|
||||
}
|
||||
else if (ui_but_is_float(but)) {
|
||||
ui_but_build_drawstr_float(but, value);
|
||||
}
|
||||
else {
|
||||
|
@ -3893,7 +3898,7 @@ static void ui_but_update_ex(uiBut *but, const bool validate)
|
|||
|
||||
case UI_BTYPE_TEXT:
|
||||
case UI_BTYPE_SEARCH_MENU:
|
||||
if (!but->editstr) {
|
||||
if (!but->editstr && !(but->drawflag & UI_BUT_INDETERMINATE)) {
|
||||
char str[UI_MAX_DRAW_STR];
|
||||
|
||||
ui_but_string_get(but, str, UI_MAX_DRAW_STR);
|
||||
|
|
|
@ -3716,7 +3716,7 @@ static void widget_numslider(uiBut *but,
|
|||
widgetbase_draw(&wtb, wcol);
|
||||
|
||||
/* Draw slider part only when not in text editing. */
|
||||
if (!state->is_text_input) {
|
||||
if (!state->is_text_input && !(but->drawflag & UI_BUT_INDETERMINATE)) {
|
||||
int roundboxalign_slider = roundboxalign;
|
||||
|
||||
uchar outline[3];
|
||||
|
@ -4151,16 +4151,46 @@ static void widget_optionbut(uiWidgetColors *wcol,
|
|||
/* Keep one edge in place. */
|
||||
BLI_rcti_translate(&recttemp, text_before_widget ? delta : -delta, 0);
|
||||
|
||||
if (state->but_drawflag & UI_BUT_INDETERMINATE) {
|
||||
/* The same muted background color regardless of state. */
|
||||
wcol->inner[0] = wcol->inner_sel[0];
|
||||
wcol->inner[1] = wcol->inner_sel[1];
|
||||
wcol->inner[2] = wcol->inner_sel[2];
|
||||
wcol->inner[3] = 96;
|
||||
}
|
||||
|
||||
const float rad = widget_radius_from_rcti(&recttemp, wcol);
|
||||
round_box_edges(&wtb, UI_CNR_ALL, &recttemp, rad);
|
||||
|
||||
/* decoration */
|
||||
if (state->but_flag & UI_SELECT) {
|
||||
if (state->but_flag & UI_SELECT && !(state->but_drawflag & UI_BUT_INDETERMINATE)) {
|
||||
shape_preset_trias_from_rect_checkmark(&wtb.tria1, &recttemp);
|
||||
}
|
||||
|
||||
widgetbase_draw(&wtb, wcol);
|
||||
|
||||
if (state->but_drawflag & UI_BUT_INDETERMINATE) {
|
||||
|
||||
/* Flush the widget cache so we can draw on top. */
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
UI_widgetbase_draw_cache_flush();
|
||||
|
||||
/* Draw a horizontal line instead of checkmark. */
|
||||
const uint pos = GPU_vertformat_attr_add(
|
||||
immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
Harley marked this conversation as resolved
Outdated
Julian Eisel
commented
We should avoid flushing the widget cache, this can introduce slowdowns (there were significant slowdowns in widget drawing in early 2.8, before adding the cache). It should be trivial to draw a line in the widget shader, without immediate mode drawing. E.g. see We should avoid flushing the widget cache, this can introduce slowdowns (there were significant slowdowns in widget drawing in early 2.8, before adding the cache). It should be trivial to draw a line in the widget shader, without immediate mode drawing. E.g. see `shape_preset_init_number_arrows()`.
|
||||
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
immUniformColor3ubvAlpha(wcol->text, 192);
|
||||
|
||||
float extent = (recttemp.ymax - recttemp.ymin);
|
||||
float w = extent * 0.6f;
|
||||
float h = MAX2(w / 6.0f, U.pixelsize);
|
||||
float x = recttemp.xmin + (extent * 0.2f);
|
||||
float y = recttemp.ymin + (extent * 0.5f) - (h * 0.5f);
|
||||
immRectf(pos, x, y, x + w, y + h);
|
||||
immUnbindProgram();
|
||||
GPU_blend(GPU_BLEND_NONE);
|
||||
}
|
||||
|
||||
/* Text space - factor is really just eyeballed. */
|
||||
const float offset = delta * 0.9;
|
||||
if (text_before_widget) {
|
||||
|
|
Loading…
Reference in New Issue
Not sure if indeterminate is the right word. For example for the checkbox in the asset catalog selector the state is known (it's unchecked, we just want to indicate that it has checked children). Maybe
UI_BUT_INDICATE_MUTLIVALUE
?