UI: delay tool label tip display
Displaying the labels tip immediately feels too intrusive, make this work more like regular tooltips, displaying more quickly. Tooltips can now uses multiple passes, each pass with it's own delay for the next pass to show.
This commit is contained in:
@@ -1282,6 +1282,7 @@ 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
|
||||
#define UI_TOOLTIP_DELAY_LABEL 0.2
|
||||
|
||||
/* Float precision helpers */
|
||||
#define UI_PRECISION_FLOAT_MAX 6
|
||||
|
||||
@@ -7046,10 +7046,17 @@ void UI_but_tooltip_timer_remove(bContext *C, uiBut *but)
|
||||
}
|
||||
}
|
||||
|
||||
static ARegion *ui_but_tooltip_init_ex(
|
||||
bContext *C, ARegion *ar, bool *r_exit_on_event,
|
||||
bool is_label)
|
||||
static ARegion *ui_but_tooltip_init(
|
||||
bContext *C, ARegion *ar,
|
||||
int *pass, double *r_pass_delay, bool *r_exit_on_event)
|
||||
{
|
||||
bool is_label = false;
|
||||
if (*pass == 1) {
|
||||
is_label = true;
|
||||
(*pass)--;
|
||||
(*r_pass_delay) = UI_TOOLTIP_DELAY - UI_TOOLTIP_DELAY_LABEL;
|
||||
}
|
||||
|
||||
uiBut *but = UI_region_active_but_get(ar);
|
||||
*r_exit_on_event = false;
|
||||
if (but) {
|
||||
@@ -7058,16 +7065,6 @@ static ARegion *ui_but_tooltip_init_ex(
|
||||
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);
|
||||
@@ -7078,7 +7075,15 @@ 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) {
|
||||
WM_tooltip_timer_init(C, data->window, data->region, ui_but_tooltip_init);
|
||||
bool is_label = UI_but_has_tooltip_label(but);
|
||||
double delay = is_label ? UI_TOOLTIP_DELAY_LABEL : UI_TOOLTIP_DELAY;
|
||||
WM_tooltip_timer_init_ex(C, data->window, data->region, ui_but_tooltip_init, delay);
|
||||
if (is_label) {
|
||||
bScreen *sc = WM_window_get_active_screen(data->window);
|
||||
if (sc->tool_tip) {
|
||||
sc->tool_tip->pass = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7314,12 +7319,14 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
|
||||
ui_numedit_set_active(but);
|
||||
}
|
||||
|
||||
#if 0
|
||||
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);
|
||||
ui_but_tooltip_init);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void button_activate_exit(
|
||||
|
||||
@@ -624,11 +624,16 @@ bool WM_window_modal_keymap_status_draw(
|
||||
struct uiLayout *layout);
|
||||
|
||||
/* wm_tooltip.c */
|
||||
typedef struct ARegion *(*wmTooltipInitFn)(struct bContext *, struct ARegion *, bool *);
|
||||
typedef struct ARegion *(*wmTooltipInitFn)(
|
||||
struct bContext *C, struct ARegion *ar,
|
||||
int *pass, double *r_pass_delay, bool *r_exit_on_event);
|
||||
|
||||
void WM_tooltip_immediate_init(
|
||||
struct bContext *C, struct wmWindow *win, struct ARegion *ar,
|
||||
wmTooltipInitFn init);
|
||||
void WM_tooltip_timer_init_ex(
|
||||
struct bContext *C, struct wmWindow *win, struct ARegion *ar,
|
||||
wmTooltipInitFn init, double delay);
|
||||
void WM_tooltip_timer_init(
|
||||
struct bContext *C, struct wmWindow *win, struct ARegion *ar,
|
||||
wmTooltipInitFn init);
|
||||
|
||||
@@ -718,9 +718,13 @@ typedef struct wmTooltipState {
|
||||
/** The tooltip region. */
|
||||
struct ARegion *region;
|
||||
/** Create the tooltip region (assign to 'region'). */
|
||||
struct ARegion *(*init)(struct bContext *, struct ARegion *, bool *r_exit_on_event);
|
||||
struct ARegion *(*init)(
|
||||
struct bContext *C, struct ARegion *ar,
|
||||
int *pass, double *pass_delay, bool *r_exit_on_event);
|
||||
/** Exit on any event, not needed for buttons since their highlight state is used. */
|
||||
bool exit_on_event;
|
||||
/** Pass, use when we want multiple tips, count down to zero. */
|
||||
int pass;
|
||||
} wmTooltipState;
|
||||
|
||||
/* *************** migrated stuff, clean later? ************** */
|
||||
|
||||
@@ -267,7 +267,7 @@ bool WM_gizmomap_minmax(
|
||||
float r_min[3], float r_max[3]);
|
||||
|
||||
struct ARegion *WM_gizmomap_tooltip_init(
|
||||
struct bContext *C, struct ARegion *ar, bool *r_exit_on_event);
|
||||
struct bContext *C, struct ARegion *ar, int *pass, double *pass_delay, bool *r_exit_on_event);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* wmGizmoMapType */
|
||||
|
||||
@@ -1056,7 +1056,7 @@ void WM_gizmomap_message_subscribe(
|
||||
* \{ */
|
||||
|
||||
struct ARegion *WM_gizmomap_tooltip_init(
|
||||
struct bContext *C, struct ARegion *ar, bool *r_exit_on_event)
|
||||
struct bContext *C, struct ARegion *ar, int *UNUSED(r_pass), double *UNUSED(pass_delay), bool *r_exit_on_event)
|
||||
{
|
||||
wmGizmoMap *gzmap = ar->gizmo_map;
|
||||
*r_exit_on_event = true;
|
||||
|
||||
@@ -52,9 +52,9 @@ void WM_tooltip_immediate_init(
|
||||
WM_tooltip_init(C, win);
|
||||
}
|
||||
|
||||
void WM_tooltip_timer_init(
|
||||
void WM_tooltip_timer_init_ex(
|
||||
bContext *C, wmWindow *win, ARegion *ar,
|
||||
wmTooltipInitFn init)
|
||||
wmTooltipInitFn init, double delay)
|
||||
{
|
||||
WM_tooltip_timer_clear(C, win);
|
||||
|
||||
@@ -64,11 +64,17 @@ void WM_tooltip_timer_init(
|
||||
screen->tool_tip = MEM_callocN(sizeof(*screen->tool_tip), __func__);
|
||||
}
|
||||
screen->tool_tip->region_from = ar;
|
||||
screen->tool_tip->timer = WM_event_add_timer(
|
||||
wm, win, TIMER, UI_TOOLTIP_DELAY);
|
||||
screen->tool_tip->timer = WM_event_add_timer(wm, win, TIMER, delay);
|
||||
screen->tool_tip->init = init;
|
||||
}
|
||||
|
||||
void WM_tooltip_timer_init(
|
||||
bContext *C, wmWindow *win, ARegion *ar,
|
||||
wmTooltipInitFn init)
|
||||
{
|
||||
WM_tooltip_timer_init_ex(C, win, ar, init, UI_TOOLTIP_DELAY);
|
||||
}
|
||||
|
||||
void WM_tooltip_timer_clear(bContext *C, wmWindow *win)
|
||||
{
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
@@ -103,8 +109,16 @@ void WM_tooltip_init(bContext *C, wmWindow *win)
|
||||
UI_tooltip_free(C, screen, screen->tool_tip->region);
|
||||
screen->tool_tip->region = NULL;
|
||||
}
|
||||
const int pass_prev = screen->tool_tip->pass;
|
||||
double pass_delay = 0.0;
|
||||
screen->tool_tip->region = screen->tool_tip->init(
|
||||
C, screen->tool_tip->region_from, &screen->tool_tip->exit_on_event);
|
||||
C, screen->tool_tip->region_from,
|
||||
&screen->tool_tip->pass, &pass_delay, &screen->tool_tip->exit_on_event);
|
||||
if (pass_prev != screen->tool_tip->pass) {
|
||||
/* The pass changed, add timer for next pass. */
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
screen->tool_tip->timer = WM_event_add_timer(wm, win, TIMER, pass_delay);
|
||||
}
|
||||
if (screen->tool_tip->region == NULL) {
|
||||
WM_tooltip_clear(C, win);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user