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

🎋 Fix #11: Id clash when using multiple Trees #12

Closed

Conversation

tosti007
Copy link
Contributor

@tosti007 tosti007 commented Jul 24, 2023

Based on #13 (will update and rebase once that's in), to have the egui/serde dependency enabled.

This PR is an implementation to solve issue #11.

This is achieved by storing an egui::Id for each tree. In order to get the TiledId::egui_id the Tree's id is passed. The value of the Tree's id is determined by a user passed value, thus this is a breaking change.

I opted to allow serde to serialize and deserialize the passed value, as adding a id_source kind of function, which needs to be called after deserialization felt bad. I also opted to have the user pass an Into<egui::Id> rather than obtaining it from the egui::Ui passed in the Tree::ui function, as that will cause the TileIds to break when the user draws the same Tree within a different Ui context.

@tosti007 tosti007 marked this pull request as draft July 24, 2023 12:36
@tosti007 tosti007 force-pushed the fix-multi-tree-id-clash branch from e91f5a3 to f5662bf Compare July 24, 2023 12:55
@tosti007 tosti007 marked this pull request as ready for review July 31, 2023 09:13
@abey79 abey79 added the enhancement New feature or request label Aug 1, 2023
@mkrueger
Copy link
Contributor

mkrueger commented Sep 2, 2023

Ran into this issue today - I've pulled that PR in my fork - works. Thanks :)

@tosti007
Copy link
Contributor Author

tosti007 commented Sep 28, 2023

I'll rebase this once #13 lands, unless someone needs this sooner, if so let me know!

tosti007 added a commit to Traverse-Research/egui_tiles that referenced this pull request Sep 28, 2023
@tosti007 tosti007 force-pushed the fix-multi-tree-id-clash branch from f5662bf to ed81533 Compare November 2, 2023 14:53
tosti007 added a commit to Traverse-Research/egui_tiles that referenced this pull request Nov 2, 2023
emilk pushed a commit that referenced this pull request Nov 2, 2023
This PR marks `serde` as an option dependency and only derives the
various `Serialize` and `Deserialize` traits when this feature is
enabled.

Regardless of not forcing the user to have the `serde` dependency,
having the `serde` feature of `egui` (optionally) enabled is a
requirement for #12.
@tosti007 tosti007 force-pushed the fix-multi-tree-id-clash branch from ed81533 to 67b4cff Compare November 3, 2023 08:55
tosti007 added a commit to Traverse-Research/egui_tiles that referenced this pull request Nov 3, 2023
Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Good catch!

We should to add some docs to Tree though to explain the purpose of this Id. There is also a few doc-examples that need updating (hence the failing CI)

@emilk
Copy link
Member

emilk commented Nov 21, 2023

I'm finishing this up in #32

@emilk emilk closed this Nov 21, 2023
Comment on lines +175 to +176
self.id = ui.id();

Copy link
Member

Choose a reason for hiding this comment

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

This looks like a mistake

Copy link
Contributor Author

@tosti007 tosti007 Nov 21, 2023

Choose a reason for hiding this comment

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

I looked at this wrongly you're right!

@tosti007
Copy link
Contributor Author

Sorry, this slipped my mind! I thought I enabled you to push to this branch, but fixing it in #32 is fine!

emilk added a commit that referenced this pull request Nov 21, 2023
* Closes #11 

* (this is a fork of #12)

---

Each `Tree` now has a globally unique id, meaning the same `Tree` can be
rendered in different `Ui`:s and still work, and you can have multiple
trees. However, it is up to the user to pick a globally unique id.

---------

Co-authored-by: tosti007 <git@brianjanssen.nl>
@tosti007 tosti007 deleted the fix-multi-tree-id-clash branch November 21, 2023 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants