-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add the button pressed to some signals in Tree #47665
Add the button pressed to some signals in Tree #47665
Conversation
15aa3f4
to
235d622
Compare
As we discussed in a PR review meeting, the proposed changes here make sense. We just need to make sure that we harmonize the API to be similar between Tree and ItemList, the latter being changed in #59720 (so you're welcome to also participate in reviewing #59720 to make sure that the signal names we implement make sense for Tree too). |
b676172
to
441de7b
Compare
441de7b
to
0719e85
Compare
We decided to remove the mouse part, so it should be
This name is awkward. Something like EDIT: |
} | ||
|
||
if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) { | ||
// make sure in case of wrong reference after reconstructing whole TreeItems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// make sure in case of wrong reference after reconstructing whole TreeItems | |
// Make sure in case of wrong reference after reconstructing whole TreeItems. |
(also the sentence is a bit unclear. Make sure what?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block was moved and that comment was already there. I can change it as you suggested if you want.
scene/gui/tree.cpp
Outdated
if (p_lmb) { | ||
if (p_mouse_index == MouseButton::NONE) { | ||
emit_signal(SNAME("item_edited")); | ||
} else { | ||
emit_signal(SNAME("item_rmb_edited")); | ||
emit_signal(SNAME("item_edit_mouse_clicked"), p_mouse_index); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the old code it seems like both signals were for mouse clicks, p_lmb
was just for the left click. It's ok to divide it like that, but the method doesn't properly get the mouse buttons (e.g. clicking a checkable item doesn't emit the mouse clicked signal, because it calls item_edited()
without the last argument).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with item_edited
is that it's not always called from a mouse event, but may come from a keyboard event or even an event that was fired outside Tree (for both, Tree::_text_editor_submit
is an example). Maybe I can propagate the mouse button when it's known, but it won't be really consistent or predictable (because it depends on how the user use the Tree).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I mean e.g. here:
if (force_edit_checkbox_only_on_checkbox) {
if (x < cache.checked->get_width()) {
p_item->set_checked(col, !c.checked);
item_edited(col, p_item);
}
} else {
p_item->set_checked(col, !c.checked);
item_edited(col, p_item);
}
This is done in response to mouse click, but you aren't passing the mouse button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick pass where item_edited
is used and added the mouse button where possible.
I checked the changes and they are an improvement, but tbh the Tree API is so bad that it would need much bigger rework. This could be good to merge as a start though. |
0719e85
to
265f6ec
Compare
Done, but now there is overlaps between |
265f6ec
to
f09560f
Compare
f09560f
to
307427a
Compare
Sorry, but I was actually wrong about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, the changes look good now.
Tree actually needs much more work. We should look into all signals and methods and evaluate what should be changed/removed, as the class just tries to do too many things at once. I'm going to make a proposal about it.
Thanks! |
Supersedes #46588
Based on this comment
This PR replaces most
rmb
(some can't be changed easily due to dependencies with key events) signals with amouse_button_index
parameter.Changes:
button_pressed(TreeItem item, int column, int id)
->button_clicked(int mouse_button_index, TreeItem item, int column, int id)
empty_rmb(Vector2 position)
->empty_clicked(Vector2 position, int mouse_button_index)
empty_tree_rmb_selected(Vector2 position)
->void
item_rmb_edited()
->custom_item_clicked(int mouse_button_index)
item_rmb_selected(Vector2 position)
->item_mouse_selected(Vector2 position, int mouse_button_index)
Note: I prefer to wait a review on the signal changes before changing the affected editor code (and fix docs).EDIT: The signals names were adapted as requested (to be consistent with #59720 changes), and the
empty_tree_rmb_selected
signal was removed, as discussed here.