Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-09-05 06:52:19 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-09-05 06:52:19 +0300
commit6f1f7296f4cf69602f599dda92e0590593f4cc62 (patch)
tree2c9f1de02f5202099b22af099b60b14034529861 /source
parente1751415dc9a2c5287bda8116f501a6fb2d55a1a (diff)
UI: show a small label next to the tool
Instead of showing the full tip immediately when hovering over a tool, show only the (label, shortcut), without suppressing the regular tip.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/include/UI_interface.h6
-rw-r--r--source/blender/editors/interface/interface_handlers.c34
-rw-r--r--source/blender/editors/interface/interface_query.c2
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c36
-rw-r--r--source/blender/windowmanager/WM_api.h5
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c2
-rw-r--r--source/blender/windowmanager/intern/wm_tooltip.c19
7 files changed, 73 insertions, 31 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 51cff1c9440..eebbdad6a82 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -407,7 +407,7 @@ typedef bool (*uiMenuStepFunc)(struct bContext *C, int direction, void *arg1);
/* interface_query.c */
-bool UI_but_is_tooltip_no_overlap(const uiBut *but);
+bool UI_but_has_tooltip_label(const uiBut *but);
bool UI_but_is_tool(const uiBut *but);
#define UI_but_is_decorator(but) \
((but)->func == ui_but_anim_decorate_cb)
@@ -1276,14 +1276,12 @@ bool UI_butstore_register_update(uiBlock *block, uiBut *but_dst, const uiBut *bu
void UI_butstore_unregister(uiButStore *bs_handle, uiBut **but_p);
/* ui_interface_region_tooltip.c */
-struct ARegion *UI_tooltip_create_from_button(struct bContext *C, struct ARegion *butregion, uiBut *but);
+struct ARegion *UI_tooltip_create_from_button(struct bContext *C, struct ARegion *butregion, uiBut *but, bool is_label);
struct ARegion *UI_tooltip_create_from_gizmo(struct bContext *C, struct wmGizmo *gz);
void UI_tooltip_free(struct bContext *C, struct bScreen *sc, struct ARegion *ar);
/* How long before a tool-tip shows. */
#define UI_TOOLTIP_DELAY 0.5
-/* For cases when the tooltips don't overlap, use an 'instant' tip. */
-#define UI_TOOLTIP_DELAY_QUICK 0.05
/* Float precision helpers */
#define UI_PRECISION_FLOAT_MAX 6
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 4757a8b1e43..29ee6a72bb2 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -7046,16 +7046,28 @@ void UI_but_tooltip_timer_remove(bContext *C, uiBut *but)
}
}
-static ARegion *ui_but_tooltip_init(bContext *C, ARegion *ar, bool *r_exit_on_event)
+static ARegion *ui_but_tooltip_init_ex(
+ bContext *C, ARegion *ar, bool *r_exit_on_event,
+ bool is_label)
{
uiBut *but = UI_region_active_but_get(ar);
*r_exit_on_event = false;
if (but) {
- return UI_tooltip_create_from_button(C, ar, but);
+ return UI_tooltip_create_from_button(C, ar, but, is_label);
}
return NULL;
}
+static ARegion *ui_but_tooltip_init(bContext *C, ARegion *ar, bool *r_exit_on_event)
+{
+ return ui_but_tooltip_init_ex(C, ar, r_exit_on_event, false);
+}
+
+static ARegion *ui_but_tooltip_init_label(bContext *C, ARegion *ar, bool *r_exit_on_event)
+{
+ return ui_but_tooltip_init_ex(C, ar, r_exit_on_event, true);
+}
+
static void button_tooltip_timer_reset(bContext *C, uiBut *but)
{
wmWindowManager *wm = CTX_wm_manager(C);
@@ -7066,8 +7078,7 @@ 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) {
- bool quick = UI_but_is_tooltip_no_overlap(but);
- WM_tooltip_timer_init(C, data->window, data->region, ui_but_tooltip_init, quick);
+ WM_tooltip_timer_init(C, data->window, data->region, ui_but_tooltip_init);
}
}
}
@@ -7251,6 +7262,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
/* activate button */
but->flag |= UI_ACTIVE;
+
but->active = data;
/* we disable auto_open in the block after a threshold, because we still
@@ -7301,6 +7313,13 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
else if (but->type == UI_BTYPE_NUM) {
ui_numedit_set_active(but);
}
+
+ if (UI_but_has_tooltip_label(but)) {
+ /* Show a label for this button. */
+ WM_tooltip_immediate_init(
+ C, CTX_wm_window(C), ar,
+ ui_but_tooltip_init_label);
+ }
}
static void button_activate_exit(
@@ -7822,11 +7841,8 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
}
else if (event->x != event->prevx || event->y != event->prevy) {
/* re-enable tooltip on mouse move */
- if (!UI_but_is_tooltip_no_overlap(but)) {
- /* Since this may overlap, close on mouse-move. */
- ui_blocks_set_tooltips(ar, true);
- button_tooltip_timer_reset(C, but);
- }
+ ui_blocks_set_tooltips(ar, true);
+ button_tooltip_timer_reset(C, but);
}
break;
diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c
index ba4fdf43875..81c2872c1d6 100644
--- a/source/blender/editors/interface/interface_query.c
+++ b/source/blender/editors/interface/interface_query.c
@@ -96,7 +96,7 @@ bool UI_but_is_tool(const uiBut *but)
return false;
}
-bool UI_but_is_tooltip_no_overlap(const uiBut *but)
+bool UI_but_has_tooltip_label(const uiBut *but)
{
if (!ui_block_is_popover(but->block)) {
return UI_but_is_tool(but);
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index d2d8e2dae2c..0e0ddc410b7 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -368,7 +368,7 @@ static bool ui_tooltip_data_append_from_keymap(
/**
* Special tool-system exception.
*/
-static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but)
+static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is_label)
{
if (but->optype == NULL) {
return NULL;
@@ -395,6 +395,8 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but)
* doesn't have access to information about non-active tools.
*/
+ uiTooltipField *field_title = NULL;
+
/* Title (when icon-only). */
if (but->drawstr[0] == '\0') {
uiTooltipField *field = text_field_add(
@@ -404,10 +406,11 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but)
.is_pad = true,
});
field->text = BLI_strdup(tool_name);
+ field_title = field;
}
/* Tip. */
- {
+ if (is_label == false) {
const char *expr_imports[] = {"bpy", "bl_ui", NULL};
char expr[256];
SNPRINTF(
@@ -549,13 +552,20 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but)
}
if (shortcut != NULL) {
- uiTooltipField *field = text_field_add(
- data, &(uiTooltipFormat){
- .style = UI_TIP_STYLE_NORMAL,
- .color_id = UI_TIP_LC_VALUE,
- .is_pad = true,
- });
- field->text = BLI_sprintfN(TIP_("Shortcut: %s"), shortcut);
+ if (is_label && field_title) {
+ char *text_prev = field_title->text;
+ field_title->text = BLI_sprintfN(TIP_("%s, %s"), text_prev, shortcut);
+ MEM_freeN(text_prev);
+ }
+ else {
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_NORMAL,
+ .color_id = UI_TIP_LC_VALUE,
+ .is_pad = true,
+ });
+ field->text = BLI_sprintfN(TIP_("Shortcut: %s"), shortcut);
+ }
MEM_freeN(shortcut);
}
}
@@ -563,7 +573,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but)
/* Keymap */
/* This is too handy not to expose somehow, let's be sneaky for now. */
- if (CTX_wm_window(C)->eventstate->shift) {
+ if ((is_label == false) && CTX_wm_window(C)->eventstate->shift) {
const char *expr_imports[] = {"bpy", "bl_ui", NULL};
char expr[256];
SNPRINTF(
@@ -1204,7 +1214,7 @@ static ARegion *ui_tooltip_create_with_data(
* \{ */
-ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *but)
+ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *but, bool is_label)
{
wmWindow *win = CTX_wm_window(C);
/* aspect values that shrink text are likely unreadable */
@@ -1217,7 +1227,7 @@ ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *b
uiTooltipData *data = NULL;
if (data == NULL) {
- data = ui_tooltip_data_from_tool(C, but);
+ data = ui_tooltip_data_from_tool(C, but, is_label);
}
if (data == NULL) {
@@ -1228,7 +1238,7 @@ ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *b
return NULL;
}
- const bool is_no_overlap = UI_but_is_tooltip_no_overlap(but);
+ const bool is_no_overlap = is_label && UI_but_has_tooltip_label(but);
rcti init_rect;
if (is_no_overlap) {
rctf overlap_rect_fl;
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 36f030e4eac..62afc4ab710 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -626,9 +626,12 @@ bool WM_window_modal_keymap_status_draw(
/* wm_tooltip.c */
typedef struct ARegion *(*wmTooltipInitFn)(struct bContext *, struct ARegion *, bool *);
+void WM_tooltip_immediate_init(
+ struct bContext *C, struct wmWindow *win, struct ARegion *ar,
+ wmTooltipInitFn init);
void WM_tooltip_timer_init(
struct bContext *C, struct wmWindow *win, struct ARegion *ar,
- wmTooltipInitFn init, bool quick);
+ wmTooltipInitFn init);
void WM_tooltip_timer_clear(struct bContext *C, struct wmWindow *win);
void WM_tooltip_clear(struct bContext *C, struct wmWindow *win);
void WM_tooltip_init(struct bContext *C, struct wmWindow *win);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index f074c083b31..cd1357e85b1 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2422,7 +2422,7 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
int part;
gz = wm_gizmomap_highlight_find(gzmap, C, event, &part);
if (wm_gizmomap_highlight_set(gzmap, C, gz, part) && gz != NULL) {
- WM_tooltip_timer_init(C, CTX_wm_window(C), region, WM_gizmomap_tooltip_init, false);
+ WM_tooltip_timer_init(C, CTX_wm_window(C), region, WM_gizmomap_tooltip_init);
}
}
else {
diff --git a/source/blender/windowmanager/intern/wm_tooltip.c b/source/blender/windowmanager/intern/wm_tooltip.c
index 0953351de2b..58c657bf116 100644
--- a/source/blender/windowmanager/intern/wm_tooltip.c
+++ b/source/blender/windowmanager/intern/wm_tooltip.c
@@ -37,9 +37,24 @@
#include "WM_api.h"
#include "WM_types.h"
+void WM_tooltip_immediate_init(
+ bContext *C, wmWindow *win, ARegion *ar,
+ wmTooltipInitFn init)
+{
+ WM_tooltip_timer_clear(C, win);
+
+ bScreen *screen = WM_window_get_active_screen(win);
+ if (screen->tool_tip == NULL) {
+ screen->tool_tip = MEM_callocN(sizeof(*screen->tool_tip), __func__);
+ }
+ screen->tool_tip->region_from = ar;
+ screen->tool_tip->init = init;
+ WM_tooltip_init(C, win);
+}
+
void WM_tooltip_timer_init(
bContext *C, wmWindow *win, ARegion *ar,
- wmTooltipInitFn init, bool quick)
+ wmTooltipInitFn init)
{
WM_tooltip_timer_clear(C, win);
@@ -50,7 +65,7 @@ void WM_tooltip_timer_init(
}
screen->tool_tip->region_from = ar;
screen->tool_tip->timer = WM_event_add_timer(
- wm, win, TIMER, quick ? UI_TOOLTIP_DELAY_QUICK : UI_TOOLTIP_DELAY);
+ wm, win, TIMER, UI_TOOLTIP_DELAY);
screen->tool_tip->init = init;
}