Prevent hidden tab close buttons from intercepting input [4.0]

This commit is contained in:
ator-dev 2021-11-29 20:12:05 +00:00
parent 9d3875dde7
commit 8c2b7ea537
1 changed files with 8 additions and 8 deletions

View File

@ -164,7 +164,7 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
if (rb_hover != -1) { if (rb_hover != -1) {
// pressed // Right mouse button clicked.
emit_signal(SNAME("tab_rmb_clicked"), rb_hover); emit_signal(SNAME("tab_rmb_clicked"), rb_hover);
} }
@ -174,7 +174,7 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
if (cb_hover != -1) { if (cb_hover != -1) {
// pressed // Close button pressed.
emit_signal(SNAME("tab_close_pressed"), cb_hover); emit_signal(SNAME("tab_close_pressed"), cb_hover);
} }
@ -183,7 +183,7 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
} }
if (mb->is_pressed() && (mb->get_button_index() == MouseButton::LEFT || (select_with_rmb && mb->get_button_index() == MouseButton::RIGHT))) { if (mb->is_pressed() && (mb->get_button_index() == MouseButton::LEFT || (select_with_rmb && mb->get_button_index() == MouseButton::RIGHT))) {
// clicks // Clicks.
Point2 pos = mb->get_position(); Point2 pos = mb->get_position();
if (buttons_visible) { if (buttons_visible) {
@ -235,7 +235,7 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
return; return;
} }
if (tabs[i].cb_rect.has_point(pos)) { if (tabs[i].cb_rect.has_point(pos) && (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current))) {
cb_pressing = true; cb_pressing = true;
update(); update();
return; return;
@ -659,7 +659,7 @@ void TabBar::_update_hover() {
} }
const Point2 &pos = get_local_mouse_position(); const Point2 &pos = get_local_mouse_position();
// test hovering to display right or close button // test hovering to display right or close button.
int hover_now = -1; int hover_now = -1;
int hover_buttons = -1; int hover_buttons = -1;
for (int i = offset; i < tabs.size(); i++) { for (int i = offset; i < tabs.size(); i++) {
@ -684,7 +684,7 @@ void TabBar::_update_hover() {
emit_signal(SNAME("tab_hovered"), hover); emit_signal(SNAME("tab_hovered"), hover);
} }
if (hover_buttons == -1) { // no hover if (hover_buttons == -1) { // No hover.
rb_hover = hover_buttons; rb_hover = hover_buttons;
cb_hover = hover_buttons; cb_hover = hover_buttons;
} }
@ -860,7 +860,7 @@ bool TabBar::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
if (from_path == to_path) { if (from_path == to_path) {
return true; return true;
} else if (get_tabs_rearrange_group() != -1) { } else if (get_tabs_rearrange_group() != -1) {
// drag and drop between other TabBars // Drag and drop between other TabBars.
Node *from_node = get_node(from_path); Node *from_node = get_node(from_path);
TabBar *from_tabs = Object::cast_to<TabBar>(from_node); TabBar *from_tabs = Object::cast_to<TabBar>(from_node);
if (from_tabs && from_tabs->get_tabs_rearrange_group() == get_tabs_rearrange_group()) { if (from_tabs && from_tabs->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {
@ -895,7 +895,7 @@ void TabBar::drop_data(const Point2 &p_point, const Variant &p_data) {
emit_signal(SNAME("active_tab_rearranged"), hover_now); emit_signal(SNAME("active_tab_rearranged"), hover_now);
set_current_tab(hover_now); set_current_tab(hover_now);
} else if (get_tabs_rearrange_group() != -1) { } else if (get_tabs_rearrange_group() != -1) {
// drag and drop between Tabs // Drag and drop between Tabs.
Node *from_node = get_node(from_path); Node *from_node = get_node(from_path);
TabBar *from_tabs = Object::cast_to<TabBar>(from_node); TabBar *from_tabs = Object::cast_to<TabBar>(from_node);
if (from_tabs && from_tabs->get_tabs_rearrange_group() == get_tabs_rearrange_group()) { if (from_tabs && from_tabs->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {