UI: rename Tooltip Label to Quick Tooltip

Change the mentions of "tooltip label" to "quick tooltip" to make this feature more
universally useful. The new name was suggested in #138583.

Pull Request: https://projects.blender.org/blender/blender/pulls/138639
This commit is contained in:
Jacques Lucke
2025-05-09 13:34:35 +02:00
parent f3275f5d12
commit 4acd6d46d4
10 changed files with 63 additions and 55 deletions

View File

@@ -332,10 +332,9 @@ enum {
/** Prevent the button to show any tool-tip. */
UI_BUT_NO_TOOLTIP = 1 << 4,
/**
* Show a quick tool-tip label, that is, a short tool-tip that appears faster than the full one
* and only shows the label. After a short delay the full tool-tip is shown if any.
* See #UI_but_func_quick_tooltip_set.
*/
UI_BUT_HAS_TOOLTIP_LABEL = 1 << 5,
UI_BUT_HAS_QUICK_TOOLTIP = 1 << 5,
/** Do not add the usual horizontal padding for text drawing. */
UI_BUT_NO_TEXT_PADDING = 1 << 6,
/** Do not add the usual padding around preview image drawing, use the size of the button. */
@@ -680,7 +679,7 @@ void UI_block_interaction_set(uiBlock *block, uiBlockInteraction_CallbackData *c
/* `interface_query.cc` */
bool UI_but_has_tooltip_label(const uiBut *but);
bool UI_but_has_quick_tooltip(const uiBut *but);
bool UI_but_is_tool(const uiBut *but);
/* file selectors are exempt from utf-8 checks */
bool UI_but_is_utf8(const uiBut *but);
@@ -1843,11 +1842,15 @@ 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
* one and only shows the label string returned by \a func. After a short delay the full tooltip is
* shown, including the same label.
* Enable a tooltip that appears faster than the usual tooltip. If the button has both a quick and
* a normal tooltip, the quick one is shown first, and expanded to the full one after the usual
* tooltip delay. Quick tooltips are useful in cases like:
* - A button doesn't show a label to save space but the label is still relevant. Show the label as
* quick tooltip in that case (like the name of tools in a compact, icon only tool-shelf).
* - The only purpose of a button is to display this tooltip (like a warning icon with the warning
* text in the tooltip).
*/
void UI_but_func_tooltip_label_set(uiBut *but, std::function<std::string(const uiBut *but)> func);
void UI_but_func_quick_tooltip_set(uiBut *but, std::function<std::string(const uiBut *but)> func);
enum uiTooltipStyle {
UI_TIP_STYLE_NORMAL = 0, /* Regular text. */
@@ -2912,12 +2915,14 @@ std::optional<std::string> UI_key_event_operator_string(const bContext *C,
/* ui_interface_region_tooltip.c */
/**
* \param is_label: When true, show a small tip that only shows the name, otherwise show the full
* tooltip.
* \param is_quick_tip: See #UI_but_func_quick_tooltip_set for what a quick tooltip is.
*/
ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *but, bool is_label);
ARegion *UI_tooltip_create_from_button(bContext *C,
ARegion *butregion,
uiBut *but,
bool is_quick_tip);
ARegion *UI_tooltip_create_from_button_or_extra_icon(
bContext *C, ARegion *butregion, uiBut *but, uiButExtraOpIcon *extra_icon, bool is_label);
bContext *C, ARegion *butregion, uiBut *but, uiButExtraOpIcon *extra_icon, bool is_quick_tip);
ARegion *UI_tooltip_create_from_gizmo(bContext *C, wmGizmo *gz);
void UI_tooltip_free(bContext *C, bScreen *screen, ARegion *region);
@@ -2935,7 +2940,7 @@ ARegion *UI_tooltip_create_from_search_item_generic(bContext *C,
/* How long before a tool-tip shows. */
#define UI_TOOLTIP_DELAY 0.5
#define UI_TOOLTIP_DELAY_LABEL 0.2
#define UI_TOOLTIP_DELAY_QUICK 0.2
/* Float precision helpers */

View File

@@ -936,7 +936,7 @@ static void ui_but_update_old_active_from_new(uiBut *oldbut, uiBut *but)
/* flags from the buttons we want to refresh, may want to add more here... */
const int flag_copy = UI_BUT_REDALERT | UI_HAS_ICON | UI_SELECT_DRAW;
const int drawflag_copy = UI_BUT_HAS_TOOLTIP_LABEL;
const int drawflag_copy = UI_BUT_HAS_QUICK_TOOLTIP;
/* still stuff needs to be copied */
oldbut->rect = but->rect;
@@ -958,7 +958,7 @@ static void ui_but_update_old_active_from_new(uiBut *oldbut, uiBut *but)
std::swap(oldbut->tip_func, but->tip_func);
std::swap(oldbut->tip_arg, but->tip_arg);
std::swap(oldbut->tip_arg_free, but->tip_arg_free);
std::swap(oldbut->tip_label_func, but->tip_label_func);
std::swap(oldbut->tip_quick_func, but->tip_quick_func);
oldbut->flag = (oldbut->flag & ~flag_copy) | (but->flag & flag_copy);
oldbut->drawflag = (oldbut->drawflag & ~drawflag_copy) | (but->drawflag & drawflag_copy);
@@ -5025,7 +5025,7 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block,
/* Enable quick tooltip label if this is a tool button without a label. */
if (str.is_empty() && !ui_block_is_popover(block) && UI_but_is_tool(but)) {
UI_but_drawflag_enable(but, UI_BUT_HAS_TOOLTIP_LABEL);
UI_but_drawflag_enable(but, UI_BUT_HAS_QUICK_TOOLTIP);
}
if (!ot) {
@@ -6259,10 +6259,10 @@ 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)
void UI_but_func_quick_tooltip_set(uiBut *but, std::function<std::string(const uiBut *but)> func)
{
but->tip_label_func = std::move(func);
UI_but_drawflag_enable(but, UI_BUT_HAS_TOOLTIP_LABEL);
but->tip_quick_func = std::move(func);
UI_but_drawflag_enable(but, UI_BUT_HAS_QUICK_TOOLTIP);
}
void UI_but_func_tooltip_set(uiBut *but, uiButToolTipFunc func, void *arg, uiFreeArgFunc free_arg)
@@ -6856,10 +6856,10 @@ std::string UI_but_context_menu_title_from_button(uiBut &but)
std::string UI_but_string_get_tooltip_label(const uiBut &but)
{
if (!but.tip_label_func) {
if (!but.tip_quick_func) {
return {};
}
return but.tip_label_func(&but);
return but.tip_quick_func(&but);
}
std::string UI_but_string_get_rna_label(uiBut &but)

View File

@@ -421,9 +421,9 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um)
drawstr = idname;
#endif
}
else if (but->tip_label_func) {
else if (but->tip_quick_func) {
/* The "quick tooltip" often contains a short string that can be used as a fallback. */
drawstr = but->tip_label_func(but);
drawstr = but->tip_quick_func(but);
}
}
ED_screen_user_menu_item_add_operator(

View File

@@ -8632,11 +8632,11 @@ void UI_but_tooltip_timer_remove(bContext *C, uiBut *but)
static ARegion *ui_but_tooltip_init(
bContext *C, ARegion *region, int *pass, double *r_pass_delay, bool *r_exit_on_event)
{
bool is_label = false;
bool is_quick_tip = false;
if (*pass == 1) {
is_label = true;
is_quick_tip = true;
(*pass)--;
(*r_pass_delay) = UI_TOOLTIP_DELAY - UI_TOOLTIP_DELAY_LABEL;
(*r_pass_delay) = UI_TOOLTIP_DELAY - UI_TOOLTIP_DELAY_QUICK;
}
uiBut *but = UI_region_active_but_get(region);
@@ -8646,7 +8646,7 @@ static ARegion *ui_but_tooltip_init(
uiButExtraOpIcon *extra_icon = ui_but_extra_operator_icon_mouse_over_get(
but, but->active ? but->active->region : region, win->eventstate);
return UI_tooltip_create_from_button_or_extra_icon(C, region, but, extra_icon, is_label);
return UI_tooltip_create_from_button_or_extra_icon(C, region, but, extra_icon, is_quick_tip);
}
return nullptr;
}
@@ -8661,11 +8661,11 @@ static void button_tooltip_timer_reset(bContext *C, uiBut *but)
if ((U.flag & USER_TOOLTIPS) || (data->tooltip_force)) {
if (!but->block->tooltipdisabled) {
if (!wm->drags.first) {
const bool is_label = UI_but_has_tooltip_label(but);
const double delay = is_label ? UI_TOOLTIP_DELAY_LABEL : UI_TOOLTIP_DELAY;
const bool is_quick_tip = UI_but_has_quick_tooltip(but);
const double delay = is_quick_tip ? UI_TOOLTIP_DELAY_QUICK : UI_TOOLTIP_DELAY;
WM_tooltip_timer_init_ex(
C, data->window, data->area, data->region, ui_but_tooltip_init, delay);
if (is_label) {
if (is_quick_tip) {
bScreen *screen = WM_window_get_active_screen(data->window);
if (screen->tool_tip) {
screen->tool_tip->pass = screen->tool_tip->region ? 0 : 1;
@@ -8984,7 +8984,7 @@ static void button_activate_init(bContext *C,
ui_numedit_set_active(but);
}
if (UI_but_has_tooltip_label(but)) {
if (UI_but_has_quick_tooltip(but)) {
/* Show a label for this button. */
bScreen *screen = WM_window_get_active_screen(data->window);
if ((BLI_time_now_seconds() - WM_tooltip_time_closed()) < 0.1) {

View File

@@ -239,7 +239,7 @@ struct uiBut {
void *tip_arg = nullptr;
uiFreeArgFunc tip_arg_free = nullptr;
/** Function to override the label to be displayed in the tooltip. */
std::function<std::string(const uiBut *)> tip_label_func;
std::function<std::string(const uiBut *)> tip_quick_func;
uiButToolTipCustomFunc tip_custom_func = nullptr;

View File

@@ -928,7 +928,7 @@ static void ui_item_enum_expand_tabs(uiLayout *layout,
uiBut *tab = block->buttons[i].get();
UI_but_drawflag_enable(tab, ui_but_align_opposite_to_area_align_get(CTX_wm_region(C)));
if (icon_only) {
UI_but_drawflag_enable(tab, UI_BUT_HAS_TOOLTIP_LABEL);
UI_but_drawflag_enable(tab, UI_BUT_HAS_QUICK_TOOLTIP);
}
}

View File

@@ -152,9 +152,9 @@ bool UI_but_is_tool(const uiBut *but)
return false;
}
bool UI_but_has_tooltip_label(const uiBut *but)
bool UI_but_has_quick_tooltip(const uiBut *but)
{
return (but->drawflag & UI_BUT_HAS_TOOLTIP_LABEL) != 0;
return (but->drawflag & UI_BUT_HAS_QUICK_TOOLTIP) != 0;
}
int ui_but_icon(const uiBut *but)

View File

@@ -467,7 +467,7 @@ static bool ui_tooltip_period_needed(blender::StringRef tip)
*/
static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_tool(bContext *C,
uiBut *but,
bool is_label)
bool is_quick_tip)
{
if (but->optype == nullptr) {
return nullptr;
@@ -573,7 +573,7 @@ static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_tool(bContext *C,
}
/* Tip. */
if (is_label == false) {
if (is_quick_tip == false) {
const char *expr_imports[] = {"bpy", "bl_ui", nullptr};
char expr[256];
SNPRINTF(expr,
@@ -615,7 +615,7 @@ static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_tool(bContext *C,
}
/* Shortcut. */
const bool show_shortcut = is_label == false &&
const bool show_shortcut = is_quick_tip == false &&
((but->block->flag & UI_BLOCK_SHOW_SHORTCUT_ALWAYS) == 0);
if (show_shortcut) {
@@ -756,7 +756,7 @@ static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_tool(bContext *C,
}
/* Python */
if ((is_label == false) && (U.flag & USER_TOOLTIPS_PYTHON)) {
if ((is_quick_tip == false) && (U.flag & USER_TOOLTIPS_PYTHON)) {
std::string str = ui_tooltip_text_python_from_op(C, but->optype, but->opptr);
UI_tooltip_text_field_add(*data,
fmt::format(fmt::runtime(TIP_("Python: {}")), str),
@@ -769,7 +769,7 @@ static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_tool(bContext *C,
/* Keymap */
/* This is too handy not to expose somehow, let's be sneaky for now. */
if ((is_label == false) && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) {
if ((is_quick_tip == false) && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) {
const char *expr_imports[] = {"bpy", "bl_ui", nullptr};
char expr[256];
SNPRINTF(expr,
@@ -838,7 +838,7 @@ static std::string ui_tooltip_color_string(const blender::float4 &color,
};
static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_button_or_extra_icon(
bContext *C, uiBut *but, uiButExtraOpIcon *extra_icon, const bool is_label)
bContext *C, uiBut *but, uiButExtraOpIcon *extra_icon, const bool is_quick_tip)
{
char buf[512];
@@ -862,7 +862,7 @@ static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_button_or_extra_icon(
std::string enum_tip;
if (extra_icon) {
if (is_label) {
if (is_quick_tip) {
but_label = UI_but_extra_icon_string_get_label(*extra_icon);
}
else {
@@ -875,7 +875,7 @@ static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_button_or_extra_icon(
}
else {
const std::optional<EnumPropertyItem> enum_item = UI_but_rna_enum_item_get(*C, *but);
if (is_label) {
if (is_quick_tip) {
but_tip_label = UI_but_string_get_tooltip_label(*but);
but_label = UI_but_string_get_label(*but);
enum_label = enum_item ? enum_item->name : "";
@@ -957,7 +957,7 @@ static std::unique_ptr<uiTooltipData> ui_tooltip_data_from_button_or_extra_icon(
}
/* Don't include further details if this is just a quick label tooltip. */
if (is_label) {
if (is_quick_tip) {
return data->fields.is_empty() ? nullptr : std::move(data);
}
@@ -1591,7 +1591,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
* \{ */
ARegion *UI_tooltip_create_from_button_or_extra_icon(
bContext *C, ARegion *butregion, uiBut *but, uiButExtraOpIcon *extra_icon, bool is_label)
bContext *C, ARegion *butregion, uiBut *but, uiButExtraOpIcon *extra_icon, bool is_quick_tip)
{
wmWindow *win = CTX_wm_window(C);
float init_position[2];
@@ -1601,27 +1601,27 @@ ARegion *UI_tooltip_create_from_button_or_extra_icon(
}
std::unique_ptr<uiTooltipData> data = nullptr;
if (!is_label && but->tip_custom_func) {
if (!is_quick_tip && but->tip_custom_func) {
data = ui_tooltip_data_from_custom_func(C, but);
}
if (data == nullptr) {
data = ui_tooltip_data_from_tool(C, but, is_label);
data = ui_tooltip_data_from_tool(C, but, is_quick_tip);
}
if (data == nullptr) {
data = ui_tooltip_data_from_button_or_extra_icon(C, but, extra_icon, is_label);
data = ui_tooltip_data_from_button_or_extra_icon(C, but, extra_icon, is_quick_tip);
}
if (data == nullptr) {
data = ui_tooltip_data_from_button_or_extra_icon(C, but, nullptr, is_label);
data = ui_tooltip_data_from_button_or_extra_icon(C, but, nullptr, is_quick_tip);
}
if (data == nullptr) {
return nullptr;
}
const bool is_no_overlap = UI_but_has_tooltip_label(but) || UI_but_is_tool(but);
const bool is_no_overlap = UI_but_has_quick_tooltip(but) || UI_but_is_tool(but);
rcti init_rect;
if (is_no_overlap) {
rctf overlap_rect_fl;
@@ -1656,9 +1656,12 @@ ARegion *UI_tooltip_create_from_button_or_extra_icon(
return region;
}
ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *but, bool is_label)
ARegion *UI_tooltip_create_from_button(bContext *C,
ARegion *butregion,
uiBut *but,
bool is_quick_tip)
{
return UI_tooltip_create_from_button_or_extra_icon(C, butregion, but, nullptr, is_label);
return UI_tooltip_create_from_button_or_extra_icon(C, butregion, but, nullptr, is_quick_tip);
}
ARegion *UI_tooltip_create_from_gizmo(bContext *C, wmGizmo *gz)

View File

@@ -486,7 +486,7 @@ void PreviewGridItem::build_grid_tile_button(uiLayout &layout,
const GridViewStyle &style = this->get_view().get_style();
uiBlock *block = uiLayoutGetBlock(&layout);
UI_but_func_tooltip_label_set(this->view_item_button(),
UI_but_func_quick_tooltip_set(this->view_item_button(),
[this](const uiBut * /*but*/) { return label; });
uiBut *but = uiDefBut(block,

View File

@@ -2753,7 +2753,7 @@ static void node_add_error_message_button(const TreeDrawContext &tree_draw_ctx,
0,
0,
nullptr);
UI_but_func_tooltip_label_set(
UI_but_func_quick_tooltip_set(
but, [warnings](const uiBut * /*but*/) { return node_errors_tooltip_fn(warnings); });
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
}
@@ -4969,7 +4969,7 @@ static void draw_link_errors(const bContext &C,
0,
0,
std::nullopt);
UI_but_func_tooltip_label_set(
UI_but_func_quick_tooltip_set(
but, [tooltip = std::move(error_tooltip)](const uiBut * /*but*/) { return tooltip; });
}