Fix: Constrain Docking Hint to Window Bounds

While joining and docking areas there is hint shown near the mouse that
describes the potential operation. But it is cut off if your mouse is
at the extreme right or bottom edge of the window. This PR just clamps
the position so it is always visible.

Co-authored-by: Jonas Holzman <jonas@holzman.fr>
Pull Request: https://projects.blender.org/blender/blender/pulls/135211
This commit is contained in:
Harley Acheson
2025-02-28 19:04:22 +01:00
committed by Harley Acheson
parent 99a487a07c
commit ead7a881a5
3 changed files with 24 additions and 11 deletions
+15 -7
View File
@@ -308,7 +308,8 @@ void screen_draw_move_highlight(bScreen *screen, eScreenAxis dir_axis)
&rect, inner, nullptr, 1.0f, outline, 2.0f * U.pixelsize, 2.5f * U.pixelsize);
}
static void screen_draw_area_drag_tip(int x, int y, const ScrArea *source, const std::string &hint)
static void screen_draw_area_drag_tip(
const wmWindow *win, int x, int y, const ScrArea *source, const std::string &hint)
{
const char *area_name = IFACE_(ED_area_name(source).c_str());
const uiFontStyle *fstyle = UI_FSTYLE_TOOLTIP;
@@ -333,8 +334,9 @@ static void screen_draw_area_drag_tip(int x, int y, const ScrArea *source, const
const float height = margin + lheight + line_gap + lheight + margin;
/* Position of this hint relative to the mouse position. */
const int left = x + int(5.0f * UI_SCALE_FAC);
const int top = y - int(7.0f * UI_SCALE_FAC);
const int left = std::min(x + int(5.0f * UI_SCALE_FAC),
WM_window_native_pixel_x(win) - int(width));
const int top = std::max(y - int(7.0f * UI_SCALE_FAC), int(height));
rctf rect;
rect.xmin = left;
@@ -447,7 +449,7 @@ void screen_draw_join_highlight(const wmWindow *win, ScrArea *sa1, ScrArea *sa2,
UI_draw_roundbox_4fv_ex(&combined, inner, nullptr, 1.0f, outline, U.pixelsize, 6 * U.pixelsize);
screen_draw_area_drag_tip(
win->eventstate->xy[0], win->eventstate->xy[1], sa1, IFACE_("Join Areas"));
win, win->eventstate->xy[0], win->eventstate->xy[1], sa1, IFACE_("Join Areas"));
}
static void rounded_corners(rctf rect, float color[4], int corners)
@@ -517,8 +519,13 @@ static void rounded_corners(rctf rect, float color[4], int corners)
immUnbindProgram();
}
void screen_draw_dock_preview(
ScrArea *source, ScrArea *target, AreaDockTarget dock_target, float factor, int x, int y)
void screen_draw_dock_preview(const wmWindow *win,
ScrArea *source,
ScrArea *target,
AreaDockTarget dock_target,
float factor,
int x,
int y)
{
if (dock_target == AreaDockTarget::None) {
return;
@@ -584,7 +591,8 @@ void screen_draw_dock_preview(
UI_draw_roundbox_4fv(&dest, true, 0.0f, border);
}
screen_draw_area_drag_tip(x,
screen_draw_area_drag_tip(win,
x,
y,
source,
dock_target == AreaDockTarget::Center ? IFACE_("Replace this area") :
@@ -92,8 +92,13 @@ void region_toggle_hidden(bContext *C, ARegion *region, bool do_fade);
* \param sa2: Target area that will be replaced.
*/
void screen_draw_join_highlight(const wmWindow *win, ScrArea *sa1, ScrArea *sa2, eScreenDir dir);
void screen_draw_dock_preview(
ScrArea *source, ScrArea *target, AreaDockTarget dock_target, float factor, int x, int y);
void screen_draw_dock_preview(const wmWindow *win,
ScrArea *source,
ScrArea *target,
AreaDockTarget dock_target,
float factor,
int x,
int y);
void screen_draw_split_preview(ScrArea *area, eScreenAxis dir_axis, float factor);
void screen_draw_move_highlight(bScreen *screen, eScreenAxis dir_axis);
+2 -2
View File
@@ -3627,7 +3627,7 @@ static void area_join_draw_cb(const wmWindow *win, void *userdata)
}
}
static void area_join_dock_cb(const wmWindow * /*win*/, void *userdata)
static void area_join_dock_cb(const wmWindow *win, void *userdata)
{
const wmOperator *op = static_cast<wmOperator *>(userdata);
sAreaJoinData *jd = static_cast<sAreaJoinData *>(op->customdata);
@@ -3635,7 +3635,7 @@ static void area_join_dock_cb(const wmWindow * /*win*/, void *userdata)
return;
}
screen_draw_dock_preview(
jd->sa1, jd->sa2, jd->dock_target, jd->factor, jd->current_x, jd->current_y);
win, jd->sa1, jd->sa2, jd->dock_target, jd->factor, jd->current_x, jd->current_y);
}
static void area_join_dock_cb_window(sAreaJoinData *jd, wmOperator *op)