UI: UIList Hover Highlighting #104677

Closed
Harley Acheson wants to merge 1 commits from Harley:UIListHover into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 35 additions and 30 deletions

View File

@ -996,9 +996,9 @@ static bool ui_but_update_from_old_block(const bContext *C,
else {
int flag_copy = UI_BUT_DRAG_MULTI;
/* Stupid special case: The active button may be inside (as in, overlapped on top) a view-item
/* Stupid special case: The active button may be inside (as in, overlapped on top) a row
* button which we also want to keep highlighted then. */
if (but->type == UI_BTYPE_VIEW_ITEM) {
if (ELEM(but->type, UI_BTYPE_VIEW_ITEM, UI_BTYPE_LISTROW)) {
flag_copy |= UI_ACTIVE;
}

View File

@ -9651,31 +9651,29 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi
return retval;
}
static int ui_handle_view_items_hover(const wmEvent *event, const ARegion *region)
/* Handle mouse hover for Views and UiList rows. */
static int ui_handle_viewlist_items_hover(const wmEvent *event, const ARegion *region)
{
bool has_view_item = false;
bool has_item = false;
LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
/* Avoid unnecessary work: view item buttons are assumed to be inside views. */
if (BLI_listbase_is_empty(&block->views)) {
continue;
}
LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (but->type == UI_BTYPE_VIEW_ITEM) {
if (ELEM(but->type, UI_BTYPE_VIEW_ITEM,UI_BTYPE_LISTROW)) {
but->flag &= ~UI_ACTIVE;
has_view_item = true;
has_item = true;
}
}
}
if (!has_view_item) {
if (!has_item) {
/* Avoid unnecessary lookup. */
return WM_UI_HANDLER_CONTINUE;
}
/* Always highlight the hovered view item, even if the mouse hovers another button inside of it.
*/
/* Always highlight the hovered view item, even if the mouse hovers another button inside. */
uiBut *hovered_row_but = ui_view_item_find_mouse_over(region, event->xy);
if (!hovered_row_but) {
hovered_row_but = ui_list_row_find_mouse_over(region, event->xy);
}
if (hovered_row_but) {
hovered_row_but->flag |= UI_ACTIVE;
}
@ -11305,9 +11303,9 @@ static int ui_region_handler(bContext *C, const wmEvent *event, void * /*userdat
ui_blocks_set_tooltips(region, true);
}
/* Always do this, to reliably update view item highlighting, even if the mouse hovers a button
* nested in the item (it's an overlapping layout). */
ui_handle_view_items_hover(event, region);
/* Always do this, to reliably update view and uilist item highlighting, even if
* the mouse hovers a button nested in the item (it's an overlapping layout). */
ui_handle_viewlist_items_hover(event, region);
if (retval == WM_UI_HANDLER_CONTINUE) {
retval = ui_handle_view_item_event(C, event, but, region);
}

View File

@ -3958,18 +3958,6 @@ static void widget_textbut(uiWidgetColors *wcol,
widgetbase_draw(&wtb, wcol);
}
static void widget_preview_tile(uiBut *but,
uiWidgetColors *wcol,
rcti *rect,
const uiWidgetStateInfo * /*state*/,
int /*roundboxalign*/,
const float /*zoom*/)
{
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,
const uiWidgetStateInfo * /*state*/,
@ -4092,7 +4080,7 @@ static void widget_menu_radial_itembut(uiBut *but,
static void widget_list_itembut(uiWidgetColors *wcol,
rcti *rect,
const uiWidgetStateInfo * /*state*/,
const uiWidgetStateInfo *state,
int /*roundboxalign*/,
const float zoom)
{
@ -4104,9 +4092,27 @@ static void widget_list_itembut(uiWidgetColors *wcol,
const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
if (state->but_flag & UI_ACTIVE && !(state->but_flag & UI_SELECT)) {
copy_v3_v3_uchar(wcol->inner, wcol->text);
wcol->inner[3] = 20;
}
widgetbase_draw(&wtb, wcol);
}
static void widget_preview_tile(uiBut *but,
uiWidgetColors *wcol,
rcti *rect,
const uiWidgetStateInfo *state,
int roundboxalign,
const float zoom)
{
widget_list_itembut(wcol, rect, state, roundboxalign, zoom);
ui_draw_preview_item_stateless(
&UI_style_get()->widget, rect, but->drawstr, but->icon, wcol->text, UI_STYLE_TEXT_CENTER);
}
static void widget_optionbut(uiWidgetColors *wcol,
rcti *rect,
const uiWidgetStateInfo *state,
@ -4511,6 +4517,7 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
/* Drawn via the `custom` callback. */
wt.text = nullptr;
wt.custom = widget_preview_tile;
wt.wcol_theme = &btheme->tui.wcol_list_item;
break;
case UI_WTYPE_SWATCH: