diff options
author | Julian Eisel <julian@blender.org> | 2021-01-27 00:06:45 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-01-27 00:17:17 +0300 |
commit | d096d9c4d686471b9de2a993b76f5bd9fef9cb78 (patch) | |
tree | f61623f7e2b75d5c59553ab9ed2d4004399701dd /source/blender/editors/interface/interface_region_tooltip.c | |
parent | 656f6ae6436ae10cae4820a5c957041a20d56995 (diff) |
UI: Tooltip for data-block selector menus, showing full name and library info
Long data-block names are clipped to fit into data-block selector menus. For
linked data-blocks, there's also a hint indicating the source library, which
takes further space and may get clipped too.
So this commit adds a tooltip to the menu items, which displays the full,
unclipped data-block name and the unclipped library name. Plus, the library
path is shown too, which is also useful info.
Adds helper functions for search menu item tooltips, so these are easier to add
to other search menus in future.
Part of T84188.
Diffstat (limited to 'source/blender/editors/interface/interface_region_tooltip.c')
-rw-r--r-- | source/blender/editors/interface/interface_region_tooltip.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 91e5b61a16d..050a14cf574 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -1477,6 +1477,74 @@ ARegion *UI_tooltip_create_from_gizmo(bContext *C, wmGizmo *gz) return ui_tooltip_create_with_data(C, data, init_position, NULL, aspect); } +static uiTooltipData *ui_tooltip_data_from_search_item_tooltip_data( + const uiSearchItemTooltipData *item_tooltip_data) +{ + uiTooltipData *data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData"); + + if (item_tooltip_data->description[0]) { + uiTooltipField *field = text_field_add(data, + &(uiTooltipFormat){ + .style = UI_TIP_STYLE_HEADER, + .color_id = UI_TIP_LC_NORMAL, + .is_pad = true, + }); + field->text = BLI_strdup(item_tooltip_data->description); + } + + if (item_tooltip_data->name && item_tooltip_data->name[0]) { + uiTooltipField *field = text_field_add(data, + &(uiTooltipFormat){ + .style = UI_TIP_STYLE_NORMAL, + .color_id = UI_TIP_LC_VALUE, + .is_pad = true, + }); + field->text = BLI_strdup(item_tooltip_data->name); + } + if (item_tooltip_data->hint[0]) { + uiTooltipField *field = text_field_add(data, + &(uiTooltipFormat){ + .style = UI_TIP_STYLE_NORMAL, + .color_id = UI_TIP_LC_NORMAL, + .is_pad = true, + }); + field->text = BLI_strdup(item_tooltip_data->hint); + } + + if (data->fields_len == 0) { + MEM_freeN(data); + return NULL; + } + return data; +} + +/** + * Create a tooltip from search-item tooltip data \a item_tooltip data. + * To be called from a callback set with #UI_but_func_search_set_tooltip(). + * + * \param item_rect: Rectangle of the search item in search region space (#ui_searchbox_butrect()) + * which is passed to the tooltip callback. + */ +ARegion *UI_tooltip_create_from_search_item_generic( + bContext *C, + const ARegion *searchbox_region, + const rcti *item_rect, + const uiSearchItemTooltipData *item_tooltip_data) +{ + uiTooltipData *data = ui_tooltip_data_from_search_item_tooltip_data(item_tooltip_data); + if (data == NULL) { + return NULL; + } + + const float aspect = 1.0f; + const wmWindow *win = CTX_wm_window(C); + float init_position[2]; + init_position[0] = win->eventstate->x; + init_position[1] = item_rect->ymin + searchbox_region->winrct.ymin - (UI_POPUP_MARGIN / 2); + + return ui_tooltip_create_with_data(C, data, init_position, NULL, aspect); +} + void UI_tooltip_free(bContext *C, bScreen *screen, ARegion *region) { ui_region_temp_remove(C, screen, region); |