Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewport: Fix tooltip scaling to match content scale factor #86556

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,8 @@ void Viewport::_gui_show_tooltip() {
panel->set_flag(Window::FLAG_NO_FOCUS, true);
panel->set_flag(Window::FLAG_POPUP, false);
panel->set_flag(Window::FLAG_MOUSE_PASSTHROUGH, true);
panel->set_flag(Window::FLAG_TRANSPARENT, true);
// A non-embedded tooltip window will only be transparent if per_pixel_transparency is allowed in the main Viewport.
panel->set_wrap_controls(true);
panel->add_child(base_tooltip);
panel->gui_parent = this;
Expand All @@ -1527,17 +1529,22 @@ void Viewport::_gui_show_tooltip() {

tooltip_owner->add_child(gui.tooltip_popup);

Window *window = gui.tooltip_popup->get_parent_visible_window();
float win_scale = window->content_scale_factor;
Point2 tooltip_offset = GLOBAL_GET("display/mouse_cursor/tooltip_position_offset");
if (!gui.tooltip_popup->is_embedded()) {
tooltip_offset = tooltip_offset * win_scale;
}
Rect2 r(gui.tooltip_pos + tooltip_offset, gui.tooltip_popup->get_contents_minimum_size());
r.size = r.size.min(panel->get_max_size());

Window *window = gui.tooltip_popup->get_parent_visible_window();
Rect2i vr;
if (gui.tooltip_popup->is_embedded()) {
vr = gui.tooltip_popup->get_embedder()->get_visible_rect();
} else {
panel->content_scale_factor = win_scale;
r.size = r.size * win_scale;
vr = window->get_usable_parent_rect();
}
r.size = r.size.min(panel->get_max_size());

if (r.size.x + r.position.x > vr.size.x + vr.position.x) {
// Place it in the opposite direction. If it fails, just hug the border.
Expand Down
Loading