UI: Input Placeholders #112104

Merged
Harley Acheson merged 32 commits from Harley/blender:placeholders into blender-v4.0-release 2023-10-11 00:47:20 +02:00
3 changed files with 57 additions and 0 deletions
Showing only changes of commit f0dcc3d544 - Show all commits

View File

@ -3477,6 +3477,10 @@ static void ui_but_free(const bContext *C, uiBut *but)
MEM_freeN(but->hold_argN);
}
if (but->placeholder) {
MEM_freeN(but->placeholder);
}
ui_but_free_type_specific(but);
if (but->active) {
@ -5906,6 +5910,17 @@ void UI_but_disable(uiBut *but, const char *disabled_hint)
but->disabled_info = disabled_hint;
}
void UI_but_placeholder(uiBut *but, const char *placeholder_text)
{
if (but->placeholder) {
MEM_SAFE_FREE(but->placeholder);
but->placeholder = nullptr;
}
if (placeholder_text && placeholder_text[0]) {
but->placeholder = BLI_strdup(placeholder_text);
}
}
void UI_but_type_set_menu_from_pulldown(uiBut *but)
{
BLI_assert(but->type == UI_BTYPE_PULLDOWN);

View File

@ -175,6 +175,8 @@ struct uiBut {
char strdata[UI_MAX_NAME_STR] = "";
char drawstr[UI_MAX_DRAW_STR] = "";
char *placeholder = nullptr;
rctf rect = {}; /* block relative coords */
char *poin = nullptr;

View File

@ -2187,6 +2187,46 @@ static void widget_draw_text(const uiFontStyle *fstyle,
}
}
if (strlen(drawstr) == 0 && !but->editstr &&
ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU))
{
/* Custom placeholder text here just while testing. */
const char *placeholder = (but->placeholder) ? but->placeholder : "Placeholder";
switch (but->icon) {
case ICON_VIEWZOOM:
placeholder = "Search";
break;
case ICON_SCENE_DATA:
placeholder = "Scene";
break;
case ICON_OBJECT_DATA:
placeholder = "Object";
break;
case ICON_SEQUENCE:
placeholder = "Movie Clip";
break;
}
uiFontStyleDraw_Params params{};
params.align = align;
uiFontStyle style = *fstyle;
style.italic = true;
uchar col[4];
copy_v4_v4_uchar(col, wcol->text);
col[3] *= 0.4f;
int font_xofs, font_yofs;
UI_fontstyle_draw_ex(&style,
rect,
placeholder,
strlen(placeholder),
col,
&params,
&font_xofs,
&font_yofs,
nullptr);
}
/* part text right aligned */
if (drawstr_right) {
uchar col[4];