Merge pull request #75703 from m4gr3d/fix_tab_close_button_main

Fix UI responsiveness to touch taps
This commit is contained in:
Fredia Huya-Kouadio 2023-04-23 18:24:50 -07:00 committed by GitHub
commit f178cad04a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 47 deletions

View file

@ -871,21 +871,16 @@ String EditorPropertyLayersGrid::get_tooltip(const Point2 &p_pos) const {
return String(); return String();
} }
void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) { void EditorPropertyLayersGrid::_update_hovered(const Vector2 &p_position) {
if (read_only) {
return;
}
const Ref<InputEventMouseMotion> mm = p_ev;
if (mm.is_valid()) {
bool expand_was_hovered = expand_hovered; bool expand_was_hovered = expand_hovered;
expand_hovered = expand_rect.has_point(mm->get_position()); expand_hovered = expand_rect.has_point(p_position);
if (expand_hovered != expand_was_hovered) { if (expand_hovered != expand_was_hovered) {
queue_redraw(); queue_redraw();
} }
if (!expand_hovered) { if (!expand_hovered) {
for (int i = 0; i < flag_rects.size(); i++) { for (int i = 0; i < flag_rects.size(); i++) {
if (flag_rects[i].has_point(mm->get_position())) { if (flag_rects[i].has_point(p_position)) {
// Used to highlight the hovered flag in the layers grid. // Used to highlight the hovered flag in the layers grid.
hovered_index = i; hovered_index = i;
queue_redraw(); queue_redraw();
@ -899,12 +894,20 @@ void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) {
hovered_index = -1; hovered_index = -1;
queue_redraw(); queue_redraw();
} }
}
return; void EditorPropertyLayersGrid::_on_hover_exit() {
if (expand_hovered) {
expand_hovered = false;
queue_redraw();
} }
if (hovered_index != -1) {
hovered_index = -1;
queue_redraw();
}
}
const Ref<InputEventMouseButton> mb = p_ev; void EditorPropertyLayersGrid::_update_flag() {
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
if (hovered_index >= 0) { if (hovered_index >= 0) {
// Toggle the flag. // Toggle the flag.
// We base our choice on the hovered flag, so that it always matches the hovered flag. // We base our choice on the hovered flag, so that it always matches the hovered flag.
@ -921,6 +924,22 @@ void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) {
update_minimum_size(); update_minimum_size();
queue_redraw(); queue_redraw();
} }
}
void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) {
if (read_only) {
return;
}
const Ref<InputEventMouseMotion> mm = p_ev;
if (mm.is_valid()) {
_update_hovered(mm->get_position());
return;
}
const Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
_update_hovered(mb->get_position());
_update_flag();
} }
if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) { if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
if (hovered_index >= 0) { if (hovered_index >= 0) {
@ -1055,14 +1074,7 @@ void EditorPropertyLayersGrid::_notification(int p_what) {
} break; } break;
case NOTIFICATION_MOUSE_EXIT: { case NOTIFICATION_MOUSE_EXIT: {
if (expand_hovered) { _on_hover_exit();
expand_hovered = false;
queue_redraw();
}
if (hovered_index != -1) {
hovered_index = -1;
queue_redraw();
}
} break; } break;
} }
} }

View file

@ -273,6 +273,9 @@ private:
void _rename_pressed(int p_menu); void _rename_pressed(int p_menu);
void _rename_operation_confirm(); void _rename_operation_confirm();
void _update_hovered(const Vector2 &p_position);
void _on_hover_exit();
void _update_flag();
Size2 get_grid_size() const; Size2 get_grid_size() const;
protected: protected:

View file

@ -255,12 +255,14 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
if (tabs[i].rb_rect.has_point(pos)) { if (tabs[i].rb_rect.has_point(pos)) {
rb_pressing = true; rb_pressing = true;
_update_hover();
queue_redraw(); queue_redraw();
return; return;
} }
if (tabs[i].cb_rect.has_point(pos) && (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current))) { 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_hover();
queue_redraw(); queue_redraw();
return; return;
} }