diff options
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r-- | scene/gui/tree.cpp | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 8c544dcacf..9a2ba23ce8 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2195,9 +2195,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if ((select_mode == SELECT_ROW && selected_item == p_item) || p_item->cells[i].selected || !p_item->has_meta("__focus_rect")) { Rect2i r = cell_rect; - p_item->set_meta("__focus_rect", Rect2(r.position, r.size)); - if (select_mode != SELECT_ROW) { + p_item->set_meta("__focus_rect", Rect2(r.position, r.size)); if (rtl) { r.position.x = get_size().width - r.position.x - r.size.x; } @@ -2208,6 +2207,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 theme_cache.selected->draw(ci, r); } } + } else { + p_item->set_meta("__focus_col_" + itos(i), Rect2(r.position, r.size)); } } @@ -2458,7 +2459,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (rtl) { button_ofs.x = get_size().width - button_ofs.x - button_texture->get_width(); } - p_item->cells.write[i].buttons.write[j].rect = Rect2i(button_ofs, button_size); button_texture->draw(ci, button_ofs, p_item->cells[i].buttons[j].disabled ? Color(1, 1, 1, 0.5) : p_item->cells[i].buttons[j].color); item_width_with_buttons -= button_size.width + theme_cache.button_margin; } @@ -2693,7 +2693,6 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c if (p_selected == p_current && (!c.selected || allow_reselect)) { c.selected = true; selected_item = p_selected; - selected_col = 0; if (!emitted_row) { emit_signal(SNAME("item_selected")); emitted_row = true; @@ -2704,6 +2703,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c c.selected = false; } } + if (&selected_cell == &c) { + selected_col = i; + } } else if (select_mode == SELECT_SINGLE || select_mode == SELECT_MULTI) { if (!r_in_range && &selected_cell == &c) { if (!selected_cell.selected || allow_reselect) { @@ -3778,7 +3780,12 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); warp_mouse(range_drag_capture_pos); } else { - Rect2 rect = get_selected()->get_meta("__focus_rect"); + Rect2 rect; + if (select_mode == SELECT_ROW) { + rect = get_selected()->get_meta("__focus_col_" + itos(selected_col)); + } else { + rect = get_selected()->get_meta("__focus_rect"); + } Point2 mpos = mb->get_position(); int icon_size_x = 0; Ref<Texture2D> icon = get_selected()->get_icon(selected_col); @@ -3987,7 +3994,14 @@ bool Tree::edit_selected(bool p_force_edit) { return false; } - Rect2 rect = s->get_meta("__focus_rect"); + float popup_scale = popup_editor->is_embedded() ? 1.0 : popup_editor->get_parent_visible_window()->get_content_scale_factor(); + Rect2 rect; + if (select_mode == SELECT_ROW) { + rect = s->get_meta("__focus_col_" + itos(selected_col)); + } else { + rect = s->get_meta("__focus_rect"); + } + rect.position *= popup_scale; popup_edited_item = s; popup_edited_item_col = col; @@ -4030,7 +4044,7 @@ bool Tree::edit_selected(bool p_force_edit) { popup_rect.size = rect.size; // Account for icon. - Size2 icon_size = _get_cell_icon_size(c); + Size2 icon_size = _get_cell_icon_size(c) * popup_scale; popup_rect.position.x += icon_size.x; popup_rect.size.x -= icon_size.x; @@ -4057,7 +4071,10 @@ bool Tree::edit_selected(bool p_force_edit) { } popup_editor->set_position(popup_rect.position); - popup_editor->set_size(popup_rect.size); + popup_editor->set_size(popup_rect.size * popup_scale); + if (!popup_editor->is_embedded()) { + popup_editor->set_content_scale_factor(popup_scale); + } popup_editor->popup(); popup_editor->child_controls_changed(); @@ -4073,7 +4090,10 @@ bool Tree::edit_selected(bool p_force_edit) { text_editor->show(); popup_editor->set_position(get_screen_position() + rect.position); - popup_editor->set_size(rect.size); + popup_editor->set_size(rect.size * popup_scale); + if (!popup_editor->is_embedded()) { + popup_editor->set_content_scale_factor(popup_scale); + } popup_editor->popup(); popup_editor->child_controls_changed(); @@ -5387,7 +5407,6 @@ String Tree::get_tooltip(const Point2 &p_pos) const { return Control::get_tooltip(p_pos); } - Point2 button_pos = pos; if (h_scroll->is_visible_in_tree()) { pos.x += h_scroll->get_value(); } @@ -5400,13 +5419,22 @@ String Tree::get_tooltip(const Point2 &p_pos) const { if (it) { const TreeItem::Cell &c = it->cells[col]; + int col_width = get_column_width(col); + + for (int i = 0; i < col; i++) { + pos.x -= get_column_width(i); + } + for (int j = c.buttons.size() - 1; j >= 0; j--) { - if (c.buttons[j].rect.has_point(button_pos)) { + Ref<Texture2D> b = c.buttons[j].texture; + Size2 size = b->get_size() + theme_cache.button_pressed->get_minimum_size(); + if (pos.x > col_width - size.width) { String tooltip = c.buttons[j].tooltip; if (!tooltip.is_empty()) { return tooltip; } } + col_width -= size.width; } String ret; if (it->get_tooltip_text(col) == "") { @@ -5593,8 +5621,8 @@ void Tree::_bind_methods() { ADD_SIGNAL(MethodInfo("item_selected")); ADD_SIGNAL(MethodInfo("cell_selected")); ADD_SIGNAL(MethodInfo("multi_selected", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem"), PropertyInfo(Variant::INT, "column"), PropertyInfo(Variant::BOOL, "selected"))); - ADD_SIGNAL(MethodInfo("item_mouse_selected", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::INT, "mouse_button_index"))); - ADD_SIGNAL(MethodInfo("empty_clicked", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::INT, "mouse_button_index"))); + ADD_SIGNAL(MethodInfo("item_mouse_selected", PropertyInfo(Variant::VECTOR2, "mouse_position"), PropertyInfo(Variant::INT, "mouse_button_index"))); + ADD_SIGNAL(MethodInfo("empty_clicked", PropertyInfo(Variant::VECTOR2, "click_position"), PropertyInfo(Variant::INT, "mouse_button_index"))); ADD_SIGNAL(MethodInfo("item_edited")); ADD_SIGNAL(MethodInfo("custom_item_clicked", PropertyInfo(Variant::INT, "mouse_button_index"))); ADD_SIGNAL(MethodInfo("item_icon_double_clicked")); |