UI: New button/widget type for Asset Browser like preview tiles
This button type shows a preview image above centered text, similar to the File Browser files in Thumbnail Display Mode or the default Asset Browser display. In fact we may want to port these over to use the new button type at some point. Will be used by the asset view UI template that will be added in a following commit. That is basically a mini version of the Asset Browser that can be displayed elsewhere in the UI.
This commit is contained in:
@@ -367,6 +367,9 @@ typedef enum {
|
||||
/** Buttons with value >= #UI_BTYPE_SEARCH_MENU don't get undo pushes. */
|
||||
UI_BTYPE_SEARCH_MENU = 41 << 9,
|
||||
UI_BTYPE_EXTRA = 42 << 9,
|
||||
/** A preview image (#PreviewImage), with text under it. Typically bigger than normal buttons and
|
||||
* laid out in a grid, e.g. like the File Browser in thumbnail display mode. */
|
||||
UI_BTYPE_PREVIEW_TILE = 43 << 9,
|
||||
UI_BTYPE_HOTKEY_EVENT = 46 << 9,
|
||||
/** Non-interactive image, used for splash screen */
|
||||
UI_BTYPE_IMAGE = 47 << 9,
|
||||
|
||||
@@ -7994,6 +7994,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
|
||||
case UI_BTYPE_IMAGE:
|
||||
case UI_BTYPE_PROGRESS_BAR:
|
||||
case UI_BTYPE_NODE_SOCKET:
|
||||
case UI_BTYPE_PREVIEW_TILE:
|
||||
retval = ui_do_but_EXIT(C, but, data, event);
|
||||
break;
|
||||
case UI_BTYPE_HISTOGRAM:
|
||||
|
||||
@@ -1055,8 +1055,18 @@ void ui_draw_menu_item(const struct uiFontStyle *fstyle,
|
||||
int state,
|
||||
uiMenuItemSeparatorType separator_type,
|
||||
int *r_xmax);
|
||||
void ui_draw_preview_item(
|
||||
const struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state);
|
||||
void ui_draw_preview_item(const struct uiFontStyle *fstyle,
|
||||
rcti *rect,
|
||||
const char *name,
|
||||
int iconid,
|
||||
int state,
|
||||
eFontStyle_Align text_align);
|
||||
void ui_draw_preview_item_stateless(const struct uiFontStyle *fstyle,
|
||||
rcti *rect,
|
||||
const char *name,
|
||||
int iconid,
|
||||
const uchar text_col[4],
|
||||
eFontStyle_Align text_align);
|
||||
|
||||
#define UI_TEXT_MARGIN_X 0.4f
|
||||
#define UI_POPUP_MARGIN (UI_DPI_FAC * 12)
|
||||
|
||||
@@ -599,8 +599,12 @@ static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *region)
|
||||
ui_searchbox_butrect(&rect, data, a);
|
||||
|
||||
/* widget itself */
|
||||
ui_draw_preview_item(
|
||||
&data->fstyle, &rect, data->items.names[a], data->items.icons[a], state);
|
||||
ui_draw_preview_item(&data->fstyle,
|
||||
&rect,
|
||||
data->items.names[a],
|
||||
data->items.icons[a],
|
||||
state,
|
||||
UI_STYLE_TEXT_LEFT);
|
||||
}
|
||||
|
||||
/* indicate more */
|
||||
|
||||
@@ -105,6 +105,7 @@ typedef enum {
|
||||
/* specials */
|
||||
UI_WTYPE_ICON,
|
||||
UI_WTYPE_ICON_LABEL,
|
||||
UI_WTYPE_PREVIEW_TILE,
|
||||
UI_WTYPE_SWATCH,
|
||||
UI_WTYPE_RGB_PICKER,
|
||||
UI_WTYPE_UNITVEC,
|
||||
@@ -4018,6 +4019,14 @@ static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roun
|
||||
widgetbase_draw(&wtb, wcol);
|
||||
}
|
||||
|
||||
static void widget_preview_tile(
|
||||
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
|
||||
{
|
||||
const uiStyle *style = UI_style_get();
|
||||
ui_draw_preview_item_stateless(
|
||||
&style->widget, rect, but->drawstr, but->icon, wcol->text, UI_STYLE_TEXT_CENTER);
|
||||
}
|
||||
|
||||
static void widget_menuiconbut(uiWidgetColors *wcol,
|
||||
rcti *rect,
|
||||
int UNUSED(state),
|
||||
@@ -4483,6 +4492,13 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
|
||||
wt.custom = widget_icon_has_anim;
|
||||
break;
|
||||
|
||||
case UI_WTYPE_PREVIEW_TILE:
|
||||
wt.draw = NULL;
|
||||
/* Drawn via the `custom` callback. */
|
||||
wt.text = NULL;
|
||||
wt.custom = widget_preview_tile;
|
||||
break;
|
||||
|
||||
case UI_WTYPE_SWATCH:
|
||||
wt.custom = widget_swatch;
|
||||
break;
|
||||
@@ -4778,6 +4794,10 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu
|
||||
wt = widget_type(UI_WTYPE_BOX);
|
||||
break;
|
||||
|
||||
case UI_BTYPE_PREVIEW_TILE:
|
||||
wt = widget_type(UI_WTYPE_PREVIEW_TILE);
|
||||
break;
|
||||
|
||||
case UI_BTYPE_EXTRA:
|
||||
widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
|
||||
break;
|
||||
@@ -4931,6 +4951,7 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu
|
||||
wt->draw(&wt->wcol, rect, state, roundboxalign);
|
||||
}
|
||||
|
||||
if (wt->text) {
|
||||
if (use_alpha_blend) {
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
}
|
||||
@@ -4939,6 +4960,7 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu
|
||||
if (use_alpha_blend) {
|
||||
GPU_blend(GPU_BLEND_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_draw_clip_tri(uiBlock *block, rcti *rect, uiWidgetType *wt)
|
||||
@@ -5459,17 +5481,20 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
|
||||
}
|
||||
}
|
||||
|
||||
void ui_draw_preview_item(
|
||||
const uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state)
|
||||
/**
|
||||
* Version of #ui_draw_preview_item() that does not draw the menu background and item text based on
|
||||
* state. It just draws the preview and text directly.
|
||||
*/
|
||||
void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
|
||||
rcti *rect,
|
||||
const char *name,
|
||||
int iconid,
|
||||
const uchar text_col[4],
|
||||
eFontStyle_Align text_align)
|
||||
{
|
||||
rcti trect = *rect;
|
||||
const float text_size = UI_UNIT_Y;
|
||||
float font_dims[2] = {0.0f, 0.0f};
|
||||
uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM);
|
||||
|
||||
/* drawing button background */
|
||||
wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED);
|
||||
wt->draw(&wt->wcol, rect, 0, 0);
|
||||
|
||||
/* draw icon in rect above the space reserved for the label */
|
||||
rect->ymin += text_size;
|
||||
@@ -5481,8 +5506,6 @@ void ui_draw_preview_item(
|
||||
fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
|
||||
|
||||
/* text rect */
|
||||
trect.xmin += 0;
|
||||
trect.xmax = trect.xmin + font_dims[0] + U.widget_unit / 2;
|
||||
trect.ymin += U.widget_unit / 2;
|
||||
trect.ymax = trect.ymin + font_dims[1];
|
||||
if (trect.xmax > rect->xmax - PREVIEW_PAD) {
|
||||
@@ -5501,11 +5524,27 @@ void ui_draw_preview_item(
|
||||
UI_fontstyle_draw(fstyle,
|
||||
&trect,
|
||||
drawstr,
|
||||
wt->wcol.text,
|
||||
text_col,
|
||||
&(struct uiFontStyleDraw_Params){
|
||||
.align = UI_STYLE_TEXT_CENTER,
|
||||
.align = text_align,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ui_draw_preview_item(const uiFontStyle *fstyle,
|
||||
rcti *rect,
|
||||
const char *name,
|
||||
int iconid,
|
||||
int state,
|
||||
eFontStyle_Align text_align)
|
||||
{
|
||||
uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM);
|
||||
|
||||
/* drawing button background */
|
||||
wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED);
|
||||
wt->draw(&wt->wcol, rect, 0, 0);
|
||||
|
||||
ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user