You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-03 16:55:53 +00:00
Fix UI focus being shown when it shouldn't
This commit is contained in:
@@ -515,7 +515,7 @@ void GroupsEditor::_confirm_add() {
|
|||||||
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
|
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
|
||||||
|
|
||||||
undo_redo->commit_action();
|
undo_redo->commit_action();
|
||||||
tree->grab_focus();
|
tree->grab_focus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupsEditor::_confirm_rename() {
|
void GroupsEditor::_confirm_rename() {
|
||||||
@@ -566,7 +566,7 @@ void GroupsEditor::_confirm_rename() {
|
|||||||
|
|
||||||
undo_redo->commit_action();
|
undo_redo->commit_action();
|
||||||
|
|
||||||
tree->grab_focus();
|
tree->grab_focus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupsEditor::_confirm_delete() {
|
void GroupsEditor::_confirm_delete() {
|
||||||
@@ -606,7 +606,7 @@ void GroupsEditor::_confirm_delete() {
|
|||||||
undo_redo->add_undo_method(this, "_update_tree");
|
undo_redo->add_undo_method(this, "_update_tree");
|
||||||
|
|
||||||
undo_redo->commit_action();
|
undo_redo->commit_action();
|
||||||
tree->grab_focus();
|
tree->grab_focus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupsEditor::_show_add_group_dialog() {
|
void GroupsEditor::_show_add_group_dialog() {
|
||||||
|
|||||||
@@ -277,6 +277,7 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
case Key::ESCAPE: {
|
case Key::ESCAPE: {
|
||||||
value_input_closed_frame = Engine::get_singleton()->get_frames_drawn();
|
value_input_closed_frame = Engine::get_singleton()->get_frames_drawn();
|
||||||
if (value_input_popup) {
|
if (value_input_popup) {
|
||||||
|
value_input_focus_visible = value_input->has_focus(true);
|
||||||
value_input_popup->hide();
|
value_input_popup->hide();
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@@ -612,6 +613,7 @@ void EditorSpinSlider::_evaluate_input_text() {
|
|||||||
void EditorSpinSlider::_value_input_submitted(const String &p_text) {
|
void EditorSpinSlider::_value_input_submitted(const String &p_text) {
|
||||||
value_input_closed_frame = Engine::get_singleton()->get_frames_drawn();
|
value_input_closed_frame = Engine::get_singleton()->get_frames_drawn();
|
||||||
if (value_input_popup) {
|
if (value_input_popup) {
|
||||||
|
value_input_focus_visible = value_input->has_focus(true);
|
||||||
value_input_popup->hide();
|
value_input_popup->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -646,9 +648,10 @@ void EditorSpinSlider::_value_focus_exited() {
|
|||||||
value_input_popup->hide();
|
value_input_popup->hide();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Enter or Esc was pressed.
|
// Enter or Esc was pressed. Keep showing the focus if already present.
|
||||||
grab_focus();
|
grab_focus(!value_input_focus_visible);
|
||||||
}
|
}
|
||||||
|
value_input_focus_visible = false;
|
||||||
|
|
||||||
emit_signal("value_focus_exited");
|
emit_signal("value_focus_exited");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class EditorSpinSlider : public Range {
|
|||||||
LineEdit *value_input = nullptr;
|
LineEdit *value_input = nullptr;
|
||||||
uint64_t value_input_closed_frame = 0;
|
uint64_t value_input_closed_frame = 0;
|
||||||
bool value_input_dirty = false;
|
bool value_input_dirty = false;
|
||||||
|
bool value_input_focus_visible = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ControlState {
|
enum ControlState {
|
||||||
|
|||||||
@@ -435,6 +435,13 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
|
|||||||
actions_cache = p_action_infos;
|
actions_cache = p_action_infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pair<String, int> selected_item;
|
||||||
|
TreeItem *ti = action_tree->get_selected();
|
||||||
|
if (ti) {
|
||||||
|
selected_item.first = ti->get_text(0);
|
||||||
|
selected_item.second = action_tree->get_selected_column();
|
||||||
|
}
|
||||||
|
|
||||||
HashSet<String> collapsed_actions;
|
HashSet<String> collapsed_actions;
|
||||||
TreeItem *root = action_tree->get_root();
|
TreeItem *root = action_tree->get_root();
|
||||||
if (root) {
|
if (root) {
|
||||||
@@ -496,6 +503,10 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
|
|||||||
action_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
action_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
||||||
action_item->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
action_item->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
||||||
|
|
||||||
|
if (selected_item.first == action_info.name) {
|
||||||
|
action_item->select(selected_item.second);
|
||||||
|
}
|
||||||
|
|
||||||
for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) {
|
for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) {
|
||||||
Ref<InputEvent> event = events[evnt_idx];
|
Ref<InputEvent> event = events[evnt_idx];
|
||||||
if (event.is_null()) {
|
if (event.is_null()) {
|
||||||
@@ -544,6 +555,10 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
|
|||||||
event_item->add_button(2, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTRC("Remove Event"), TTRC("Remove Event"));
|
event_item->add_button(2, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTRC("Remove Event"), TTRC("Remove Event"));
|
||||||
event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
|
event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
|
||||||
event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
|
event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
|
||||||
|
|
||||||
|
if (selected_item.first == event_item->get_text(0)) {
|
||||||
|
event_item->select(selected_item.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3285,9 +3285,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
|
|||||||
click_handled = true;
|
click_handled = true;
|
||||||
popup_pressing_edited_item = p_item;
|
popup_pressing_edited_item = p_item;
|
||||||
popup_pressing_edited_item_column = col;
|
popup_pressing_edited_item_column = col;
|
||||||
|
|
||||||
pressing_item_rect = Rect2(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - theme_cache.offset, Size2(col_width, item_h));
|
|
||||||
pressing_for_editor_text = editor_text;
|
|
||||||
pressing_for_editor = true;
|
pressing_for_editor = true;
|
||||||
|
|
||||||
return -1; // Select.
|
return -1; // Select.
|
||||||
@@ -3361,14 +3358,15 @@ void Tree::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
if (p_event->is_action_pressed("ui_text_newline_blank", true)) {
|
if (p_event->is_action_pressed("ui_text_newline_blank", true)) {
|
||||||
accept_event();
|
accept_event();
|
||||||
} else if (p_event->is_action_pressed("ui_text_newline")) {
|
} else if (p_event->is_action_pressed("ui_text_newline")) {
|
||||||
|
bool hide_focus = !text_editor->has_focus(true);
|
||||||
popup_edit_committed = true; // End edit popup processing.
|
popup_edit_committed = true; // End edit popup processing.
|
||||||
popup_editor->hide();
|
popup_editor->hide();
|
||||||
_apply_multiline_edit();
|
_apply_multiline_edit(hide_focus);
|
||||||
accept_event();
|
accept_event();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tree::_apply_multiline_edit() {
|
void Tree::_apply_multiline_edit(bool p_hide_focus) {
|
||||||
if (!popup_edited_item) {
|
if (!popup_edited_item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3387,6 +3385,7 @@ void Tree::_apply_multiline_edit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grab_focus(p_hide_focus);
|
||||||
item_edited(popup_edited_item_col, popup_edited_item);
|
item_edited(popup_edited_item_col, popup_edited_item);
|
||||||
queue_redraw();
|
queue_redraw();
|
||||||
}
|
}
|
||||||
@@ -3400,6 +3399,8 @@ void Tree::_line_editor_submit(String p_text) {
|
|||||||
return; // ESC pressed, app focus lost, or forced close from code.
|
return; // ESC pressed, app focus lost, or forced close from code.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hide_focus = !line_editor->has_focus(true);
|
||||||
|
|
||||||
popup_edit_committed = true; // End edit popup processing.
|
popup_edit_committed = true; // End edit popup processing.
|
||||||
popup_editor->hide();
|
popup_editor->hide();
|
||||||
|
|
||||||
@@ -3432,6 +3433,7 @@ void Tree::_line_editor_submit(String p_text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grab_focus(hide_focus);
|
||||||
item_edited(popup_edited_item_col, popup_edited_item);
|
item_edited(popup_edited_item_col, popup_edited_item);
|
||||||
queue_redraw();
|
queue_redraw();
|
||||||
}
|
}
|
||||||
@@ -4404,6 +4406,8 @@ bool Tree::edit_selected(bool p_force_edit) {
|
|||||||
}
|
}
|
||||||
popup_rect.position += get_screen_position();
|
popup_rect.position += get_screen_position();
|
||||||
|
|
||||||
|
bool hide_focus = !has_focus(true);
|
||||||
|
|
||||||
line_editor->clear();
|
line_editor->clear();
|
||||||
line_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step)));
|
line_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step)));
|
||||||
line_editor->select_all();
|
line_editor->select_all();
|
||||||
@@ -4420,10 +4424,12 @@ bool Tree::edit_selected(bool p_force_edit) {
|
|||||||
popup_editor->popup();
|
popup_editor->popup();
|
||||||
popup_editor->child_controls_changed();
|
popup_editor->child_controls_changed();
|
||||||
|
|
||||||
line_editor->grab_focus();
|
line_editor->grab_focus(hide_focus);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (c.mode == TreeItem::CELL_MODE_STRING && c.edit_multiline) {
|
} else if (c.mode == TreeItem::CELL_MODE_STRING && c.edit_multiline) {
|
||||||
|
bool hide_focus = !has_focus(true);
|
||||||
|
|
||||||
line_editor->hide();
|
line_editor->hide();
|
||||||
|
|
||||||
text_editor->clear();
|
text_editor->clear();
|
||||||
@@ -4440,7 +4446,7 @@ bool Tree::edit_selected(bool p_force_edit) {
|
|||||||
popup_editor->popup();
|
popup_editor->popup();
|
||||||
popup_editor->child_controls_changed();
|
popup_editor->child_controls_changed();
|
||||||
|
|
||||||
text_editor->grab_focus();
|
text_editor->grab_focus(hide_focus);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -480,9 +480,7 @@ private:
|
|||||||
|
|
||||||
int pressed_button = -1;
|
int pressed_button = -1;
|
||||||
bool pressing_for_editor = false;
|
bool pressing_for_editor = false;
|
||||||
String pressing_for_editor_text;
|
|
||||||
Vector2 pressing_pos;
|
Vector2 pressing_pos;
|
||||||
Rect2 pressing_item_rect;
|
|
||||||
|
|
||||||
Vector2 hovered_pos;
|
Vector2 hovered_pos;
|
||||||
bool is_mouse_hovering = false;
|
bool is_mouse_hovering = false;
|
||||||
@@ -562,7 +560,7 @@ private:
|
|||||||
void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = nullptr, bool *r_in_range = nullptr, bool p_force_deselect = false);
|
void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = nullptr, bool *r_in_range = nullptr, bool p_force_deselect = false);
|
||||||
int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int x_limit, bool p_double_click, TreeItem *p_item, MouseButton p_button, const Ref<InputEventWithModifiers> &p_mod);
|
int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int x_limit, bool p_double_click, TreeItem *p_item, MouseButton p_button, const Ref<InputEventWithModifiers> &p_mod);
|
||||||
void _line_editor_submit(String p_text);
|
void _line_editor_submit(String p_text);
|
||||||
void _apply_multiline_edit();
|
void _apply_multiline_edit(bool p_hide_focus = false);
|
||||||
void _text_editor_popup_modal_close();
|
void _text_editor_popup_modal_close();
|
||||||
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
|
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
|
||||||
void value_editor_changed(double p_value);
|
void value_editor_changed(double p_value);
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ bool Viewport::_can_hide_focus_state() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Viewport::_on_settings_changed() {
|
void Viewport::_on_settings_changed() {
|
||||||
if (!gui.hide_focus && _can_hide_focus_state()) {
|
if (!gui.hide_focus || _can_hide_focus_state()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user