Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: Inconsistent order of SpinBox value change and control pressing / item selection signals #79695

Open
dalexeev opened this issue Jul 20, 2023 · 3 comments

Comments

@dalexeev
Copy link
Member

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Kubuntu 23.04

Issue description

There is an inconsistency in the order of losing focus / applying a field value (LineEdit, TextEdit, SpinBox) and receiving focus / pressing a control (Button, Tree, ItemList).

In the case of Button, the order of signals is expected: first the field value is changed, then the button is pressed.

In the case of Tree and ItemList, the signal order is reversed, which is inconvenient and leads to bugs in applying changes to the current item instead of the previous one (see below). You can use deferred signals as a workaround, but in my opinion this is a hack that could cause other bugs.

_on_spin_box_value_changed 10
_on_button_pressed

_on_tree_cell_selected
_on_spin_box_value_changed 20
_on_tree_cell_selected_deferred

_on_item_list_item_selected 1
_on_spin_box_value_changed 30
_on_item_list_item_selected_deferred 1

See also:

Steps to reproduce

Change the value of the SpinBox field (without pressing Enter) and try clicking on the Button, on the Tree item and on the ItemList item.

Minimal reproduction project

focus_order_bug.zip

@dalexeev
Copy link
Member Author

Looks like this is a SpinBox issue (in the case of the Button it works correctly, since default action mode is on releasing the button). Are there any reasons why the SpinBox uses the deferred signal?

_on_spin_box_line_edit_focus_exited
_on_button_focus_entered
_on_spin_box_value_changed 10
_on_button_pressed

_on_spin_box_line_edit_focus_exited
_on_tree_focus_entered
_on_tree_cell_selected
_on_spin_box_value_changed 20
_on_tree_cell_selected_deferred

_on_spin_box_line_edit_focus_exited
_on_item_list_focus_entered
_on_item_list_item_selected 1
_on_spin_box_value_changed 30
_on_item_list_item_selected_deferred 1

line_edit->connect("text_submitted", callable_mp(this, &SpinBox::_text_submitted), CONNECT_DEFERRED);
line_edit->connect("focus_entered", callable_mp(this, &SpinBox::_line_edit_focus_enter), CONNECT_DEFERRED);
line_edit->connect("focus_exited", callable_mp(this, &SpinBox::_line_edit_focus_exit), CONNECT_DEFERRED);
line_edit->connect("gui_input", callable_mp(this, &SpinBox::_line_edit_input));

@dalexeev dalexeev changed the title GUI: Inconsistent order of field value change and control pressing / item selection signals GUI: Inconsistent order of SpinBox value change and control pressing / item selection signals Jul 20, 2023
@Rindbee
Copy link
Contributor

Rindbee commented Sep 16, 2023

I quite agree.

  • If it just delays the timing of showing/refreshing the UI, it has no side effects.
  • If this delay affects the timing of data changes, it will cause data synchronization problems.

If both the data and the UI are updated in the receiving method, we can just defer the UI update call in the receiving method.

@stoofin
Copy link
Contributor

stoofin commented Nov 1, 2023

I just ran into this. A SpinBox that's part of a Dialog will process losing focus after its ancestor Dialog's 'canceled' signal if you close that Dialog with the X button (in my case, even if that 'canceled' signal handler was itself deferred). So trying to reset the SpinBox's value in the 'canceled' handler won't work as it will get overwritten by its text. A dirty workaround I've found is to do something weird like spinbox->get_line_edit()->set_text("null"); spinbox->apply(); to get _update_text to run early and have the value change stick, but I don't like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants