Skip to content

Tree and TreeItem folding helpers and improvements#36926

Closed
FeatherAntennae wants to merge 1 commit into
godotengine:masterfrom
FeatherAntennae:gui-tree-folding-logic
Closed

Tree and TreeItem folding helpers and improvements#36926
FeatherAntennae wants to merge 1 commit into
godotengine:masterfrom
FeatherAntennae:gui-tree-folding-logic

Conversation

@FeatherAntennae
Copy link
Copy Markdown

@FeatherAntennae FeatherAntennae commented Mar 8, 2020

A few small changes to the Tree and TreeItem classes.

The goal is to reduce clutter in many classes that each have their own (different) implementation of the same logic, while giving new and old behaviors of the UI trees better consistency across the editor.

For the discussion and details, see #33984.

This was separated from the #33984 PR, as the refactor is pretty big and is going to take a while to complete, but I think I pretty much nailed down the global changes needed to make everything compatible and consistent. I think some of these changes would help some other propositions and PR too. #33984 will be kept just to keep track of the refactor, but separating this will allow each part of the refactor to be it's own PR.

I completed the Tree and TreeItem documentation, and opened this PR for the changes to the Tree and TreeItem, including doc for the new methods. It already makes the click, alt-click and folding consistent to all trees by default.

@FeatherAntennae
Copy link
Copy Markdown
Author

FeatherAntennae commented Mar 10, 2020

First step in fixing #35529
Simplifies #31815

Copy link
Copy Markdown
Contributor

@HaSa1002 HaSa1002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few I thinks I saw

Comment thread doc/classes/TreeItem.xml Outdated
Comment thread doc/classes/TreeItem.xml Outdated
Comment thread scene/gui/tree.cpp Outdated
Comment thread scene/gui/tree.cpp Outdated
Comment thread scene/gui/tree.cpp Outdated
Comment thread scene/gui/tree.cpp Outdated
@HaSa1002
Copy link
Copy Markdown
Contributor

You should squash the last commit. But maybe even meld all of them into one, since they are all used to implement "Add Tree and TreeItem folding helpers" and add the details in the message body

@akien-mga
Copy link
Copy Markdown
Member

Sorry for the long delay reviewing this. This would likely need to rebased / retested on latest master to confirm that it still does what it should.

Would be good to get some input from @godotengine/gui-nodes folks familiar with the Tree API.

The goal is to reduce clutter in many classes that each have their own (different) implementation of the same logic, while giving new and old behaviors of the UI trees better consistency across the editor.

In this PR I don't see a reduction of said clutter, I assume this was meant to be PR'ed as a follow-up once agreed upon? It would be interesting to see how much these new methods help reduce clutter to be able to assess whether adding them is a good idea or not.

@akien-mga
Copy link
Copy Markdown
Member

As a matter of fact, I just came to this PR while triaging the least recently updated ones, but we just got a new PR today that seems to address some of the same ideas: #62666. Would be good to have a cross-review @AThousandShips.

@FeatherAntennae
Copy link
Copy Markdown
Author

In this PR I don't see a reduction of said clutter, I assume this was meant to be PR'ed as a follow-up once agreed upon? It would be interesting to see how much these new methods help reduce clutter to be able to assess whether adding them is a good idea or not.

The main PR #33984 has more details. This one was split following discussion, to make it easier to review the changes to the Tree and TreeItem classes. I was a beginner in C++ back then and needed to know if I was breaking anything. In the other PR's description, there are a few of the areas that would have been changed once this one was approved. I would need to go through the codebase again to see where it would be needed now.

As a matter of fact, I just came to this PR while triaging the least recently updated ones, but we just got a new PR today that seems to address some of the same ideas: #62666. Would be good to have a cross-review @AThousandShips.

From what I can see, the idea is very similar. The main two differences are :

  • I used ALT + <click on folding arrow> instead of SHIFT + <click on folding arrow>.
    I went with ALT, as at the time I found more software using ALT instead of SHIFT for this ALTernative functionality. ;)
  • I also added the concept of "currently active" branch/hierarchy.
    It allowed collapsing all nodes recursively, EXCEPT for the one that is currently "active" (and its parents).
    (The difference between active and selected was meant to be that a right click on a different node would select the new node for operations like copy, cut, delete, etc., but would keep the previously selected node as "active" for other functionalities, like for showing properties in a different panel, showing bounding boxes in the scene view, etc.. The other PR Tree item folding improvements #33984 has a gif for a more visual example.

In any cases, if there's interest in this, I will have some free time this week that I could put on updating this and to look at a few of the other elements mentioned before in both PRs. I've been doing Engine code and C++ professionally for a year and a half now, so it'll be much faster. :)

@AThousandShips
Copy link
Copy Markdown
Member

I went for shift as that was how Scene Tree does it, my original idea was to use right click before I realized it was already a feature

@AThousandShips
Copy link
Copy Markdown
Member

My code should be ready to go and is in line with what Scene Tree does but since I missed this PR I'll let you see and leave it up to reviewers to decide which way to go

@FeatherAntennae
Copy link
Copy Markdown
Author

FeatherAntennae commented Jul 4, 2022

No worries, if anything, it just shows that there's still interest in this. In fact, it seems a lot of love was put into making engine developers' life easier through various refactors recently, that's great! :)

I went for shift as that was how Scene Tree does it, my original idea was to use right click before I realized it was already a feature

Shift and alt were both hard-coded in various places, which is part of why I was going for this refactor.

Most of the discussion for this was spread through old issues, PRs and a bit on the old IRC, so I don't know if the editor settled more toward one or the other since.

I'll go through the source code later today to see.

@AThousandShips
Copy link
Copy Markdown
Member

I couldn't even find any other instances of this folding behavior in the editor, I missed the one in Scene Tree when I originally made my proposal for this, failing to find this PR, the need arose from working on expanding the Help Search where I realized how helpful it would be to have recursive folding

Tree class:
- Added "set_collapsed_all(...)" method to allow collapsing or expanding
  the entire tree recursively. (Helper method to ensure it is done the
  same way by everyone, making use of the new recursive methods.)

TreeItem class:
- Added "has_expanded_child()" method to detect if at least one child of
  the TreeItem isn't collapsed(and has at least one child of it's own).

- Added "is_in_active_branch()" method to detect if the TreeItem or at
  least one of its descendent is selected.

- Added "set_collapsed_recursive(...)" method to collapse a TreeItem and
  its children recursively with possibility to ignore self and/or skip
  active items.

Tree behaviour:
- ALT + Click on a TreeItem's folding icon will call the TreeItem's
  method "toggle_collapsed_recursive()".

Refactor:
- Removed Scene Tree Dock custom recursive folding logic. It is now
  handled by the Tree directly.

- Replaced Visual Shader Editor collapse / expand all logic with the one
  now included in TreeItem.

- Replaced Script Editor Error Tree collapse / expand all logic with the
  one now included in TreeItem.

Documentation:
- Updated documentation with all new functions.

- Added documentation for "uncollapse_tree()" function.
@FeatherAntennae FeatherAntennae force-pushed the gui-tree-folding-logic branch from eccae75 to ab61ff9 Compare July 5, 2022 01:36
@FeatherAntennae FeatherAntennae requested a review from a team July 5, 2022 01:36
@FeatherAntennae FeatherAntennae requested review from a team as code owners July 5, 2022 01:36
@FeatherAntennae
Copy link
Copy Markdown
Author

FeatherAntennae commented Jul 5, 2022

Sorry for the long delay reviewing this. This would likely need to rebased / retested on latest master to confirm that it still does what it should.

Alright, I redid all of this PR from scratch, much easier than trying to rebase after two years. Also did a quick refactor of a few places in the editor that were using these functions. All trees now supports them by default too.

I did not replace the "collapse / expand all" in the Filesystem Dock yet, because it's scary spaghetti that I can't handle today. :P

ALT + Click has the following behaviour:

  • If the TreeItem is already collapsed, expands it and all of its children recursively.
  • Else, if the TreeItem is expanded and has at least one expanded child, collapses all children recursively without collapsing the current TreeItem.
  • Else, it means the TreeItem is expanded and all its children are collapsed, so this will collapse the TreeItem.

(Essentially, it loops between the 3 states)

godot windows tools 64_e13LYVYW3F

It also works everywhere else with a tree:
godot windows tools 64_qsFO0c2A4D
godot windows tools 64_EQKsFl8MTp

@KoBeWi
Copy link
Copy Markdown
Member

KoBeWi commented Sep 21, 2022

Needs rebase after #62666, if some changes are still relevant.

@FeatherAntennae
Copy link
Copy Markdown
Author

Needs rebase after #62666, if some changes are still relevant.

I do not mind rebasing again to contribute the differences between this and #62666, but the main part of what this was doing is done in that other PR, and it's already the second time this got done and forgotten while waiting for review.

#62666 was a new, completely separate and very similar implementation that poped up, bringing attention to this here again. I rewrote everything since it was too old, except for the filesystem dock as it was more work and we were waiting for feedback on the approach, but the other implementation got merged before this one got the review it was waiting for.

Most of what this does seems to have been implemented by #62666, except for two things that were decided based on discussion in the various issues, proposal, and other merge requests related to this one. I assumed the decision to merge the other PR meant that these differences were not wanted.

What was different about my approach:

If these are wanted I can comme back to this, but I'd prefer this to be closed if it's going to be forgotten again because the differences are too small or because we're in the middle of the 4.0 beta.

@KoBeWi
Copy link
Copy Markdown
Member

KoBeWi commented Oct 27, 2022

If that's the case then I think this can be closed. Moving the folding to Tree unified and removed duplicate code, so it was a straightforward change. The 2 extras you mentioned might warrant a proposal (and a new PR), because they change behavior.

Thanks for your contribution nonetheless and sorry about the outcome .-.

@KoBeWi KoBeWi closed this Oct 27, 2022
@AThousandShips AThousandShips removed this from the 4.0 milestone Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants