Merge pull request #23196 from Paulb23/scene_tab_errors_issue_22890

Scene tabs closing and thumbnail errors, issue 22890
This commit is contained in:
Rémi Verschelde 2018-10-21 18:08:31 +02:00 committed by GitHub
commit 81c2ed61f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 35 deletions

View File

@ -3892,9 +3892,11 @@ void EditorNode::_scene_tab_hover(int p_tab) {
tab_preview_panel->hide(); tab_preview_panel->hide();
} else { } else {
String path = editor_data.get_scene_path(p_tab); String path = editor_data.get_scene_path(p_tab);
if (path != String()) {
EditorResourcePreview::get_singleton()->queue_resource_preview(path, this, "_thumbnail_done", p_tab); EditorResourcePreview::get_singleton()->queue_resource_preview(path, this, "_thumbnail_done", p_tab);
} }
} }
}
void EditorNode::_scene_tab_exit() { void EditorNode::_scene_tab_exit() {
tab_preview_panel->hide(); tab_preview_panel->hide();

View File

@ -106,41 +106,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
} }
} }
// test hovering to display right or close button _update_hover();
int hover_now = -1;
int hover_buttons = -1;
for (int i = 0; i < tabs.size(); i++) {
if (i < offset)
continue;
Rect2 rect = get_tab_rect(i);
if (rect.has_point(pos)) {
hover_now = i;
}
if (tabs[i].rb_rect.has_point(pos)) {
rb_hover = i;
cb_hover = -1;
hover_buttons = i;
break;
} else if (!tabs[i].disabled && tabs[i].cb_rect.has_point(pos)) {
cb_hover = i;
rb_hover = -1;
hover_buttons = i;
break;
}
}
if (hover != hover_now) {
hover = hover_now;
emit_signal("tab_hover", hover);
}
if (hover_buttons == -1) { // no hover
rb_hover = hover_buttons;
cb_hover = hover_buttons;
}
update(); update();
return; return;
} }
@ -522,6 +489,48 @@ Ref<Texture> Tabs::get_tab_right_button(int p_tab) const {
return tabs[p_tab].right_button; return tabs[p_tab].right_button;
} }
void Tabs::_update_hover() {
if (!is_inside_tree()) {
return;
}
const Point2 &pos = get_local_mouse_position();
// test hovering to display right or close button
int hover_now = -1;
int hover_buttons = -1;
for (int i = 0; i < tabs.size(); i++) {
if (i < offset)
continue;
Rect2 rect = get_tab_rect(i);
if (rect.has_point(pos)) {
hover_now = i;
}
if (tabs[i].rb_rect.has_point(pos)) {
rb_hover = i;
cb_hover = -1;
hover_buttons = i;
break;
} else if (!tabs[i].disabled && tabs[i].cb_rect.has_point(pos)) {
cb_hover = i;
rb_hover = -1;
hover_buttons = i;
break;
}
}
if (hover != hover_now) {
hover = hover_now;
emit_signal("tab_hover", hover);
}
if (hover_buttons == -1) { // no hover
rb_hover = hover_buttons;
cb_hover = hover_buttons;
}
}
void Tabs::_update_cache() { void Tabs::_update_cache() {
Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
@ -597,6 +606,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture> &p_icon) {
tabs.push_back(t); tabs.push_back(t);
_update_cache(); _update_cache();
call_deferred("_update_hover");
update(); update();
minimum_size_changed(); minimum_size_changed();
} }
@ -604,6 +614,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture> &p_icon) {
void Tabs::clear_tabs() { void Tabs::clear_tabs() {
tabs.clear(); tabs.clear();
current = 0; current = 0;
call_deferred("_update_hover");
update(); update();
} }
@ -614,6 +625,7 @@ void Tabs::remove_tab(int p_idx) {
if (current >= p_idx) if (current >= p_idx)
current--; current--;
_update_cache(); _update_cache();
call_deferred("_update_hover");
update(); update();
minimum_size_changed(); minimum_size_changed();
@ -931,6 +943,7 @@ bool Tabs::get_select_with_rmb() const {
void Tabs::_bind_methods() { void Tabs::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &Tabs::_gui_input); ClassDB::bind_method(D_METHOD("_gui_input"), &Tabs::_gui_input);
ClassDB::bind_method(D_METHOD("_update_hover"), &Tabs::_update_hover);
ClassDB::bind_method(D_METHOD("get_tab_count"), &Tabs::get_tab_count); ClassDB::bind_method(D_METHOD("get_tab_count"), &Tabs::get_tab_count);
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &Tabs::set_current_tab); ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &Tabs::set_current_tab);
ClassDB::bind_method(D_METHOD("get_current_tab"), &Tabs::get_current_tab); ClassDB::bind_method(D_METHOD("get_current_tab"), &Tabs::get_current_tab);

View File

@ -97,6 +97,8 @@ private:
int get_tab_width(int p_idx) const; int get_tab_width(int p_idx) const;
void _ensure_no_over_offset(); void _ensure_no_over_offset();
void _update_hover();
void _update_cache(); void _update_cache();
protected: protected: