UI: Don't spawn asset shelf popup by hovering button

Papercut reported in #132293.

Allow explicitly disabling this behavior for a button, and do so for the
big preview asset shelf popup button. It gets more in the way than it's
useful in this case.
This commit is contained in:
Julian Eisel
2025-01-06 17:30:47 +01:00
parent c3d7cd0424
commit 11b006e01a
5 changed files with 18 additions and 0 deletions

View File

@@ -1830,6 +1830,13 @@ void UI_but_func_drawextra_set(uiBlock *block,
void UI_but_func_menu_step_set(uiBut *but, uiMenuStepFunc func);
/**
* When a button displays a menu, hovering another button that can display one will switch to that
* menu instead. In some cases that's unexpected, so the feature can be disabled here (as in, this
* button will not spawn its menu on hover and the previously spawned menu will remain open).
*/
void UI_but_menu_disable_hover_open(uiBut *but);
void UI_but_func_tooltip_set(uiBut *but, uiButToolTipFunc func, void *arg, uiFreeArgFunc free_arg);
/**
* Enable a custom quick tooltip label. That is, a short tooltip that appears faster than the full

View File

@@ -6196,6 +6196,11 @@ void UI_but_func_menu_step_set(uiBut *but, uiMenuStepFunc func)
but->menu_step_func = func;
}
void UI_but_menu_disable_hover_open(uiBut *but)
{
but->menu_no_hover_open = true;
}
void UI_but_func_tooltip_label_set(uiBut *but, std::function<std::string(const uiBut *but)> func)
{
but->tip_label_func = std::move(func);

View File

@@ -11965,6 +11965,7 @@ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void * /*us
ELEM(but->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU) &&
(but_other = ui_but_find_mouse_over(region, event)) && (but != but_other) &&
ELEM(but_other->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU) &&
!but_other->menu_no_hover_open &&
/* Hover-opening menu's doesn't work well for buttons over one another
* along the same axis the menu is opening on (see #71719). */
(((data->menu->direction & (UI_DIR_LEFT | UI_DIR_RIGHT)) &&

View File

@@ -269,6 +269,8 @@ struct uiBut {
uiMenuCreateFunc menu_create_func = nullptr;
uiMenuStepFunc menu_step_func = nullptr;
/** See #UI_but_menu_disable_hover_open(). */
bool menu_no_hover_open = false;
/* RNA data */
PointerRNA rnapoin = {};

View File

@@ -57,6 +57,9 @@ void template_asset_shelf_popover(uiLayout &layout,
uiBut *but = static_cast<uiBut *>(block->buttons.last);
if (use_preview_icon) {
ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
/* Avoid small annoyance where asset shelf popover gets spawned unintentionally on mouse hover,
* see #132293. */
UI_but_menu_disable_hover_open(but);
}
}