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

Ui.collapsing does not work with multiple Ui.collapsing of the same name after version 0.27.0 #4265

Closed
UnknownSuperficialNight opened this issue Mar 29, 2024 · 4 comments
Labels
bug Something is broken

Comments

@UnknownSuperficialNight
Copy link

UnknownSuperficialNight commented Mar 29, 2024

Describe the bug

using ui.collapsing in a scrollarea with multiple ui.collapsing in with the same name causes issues with clicking on them aswell as closing them it seems the only the bottom one can be clicked on i have videos below

Expected behavior

Here is a video using egui version '0.26.2'

Synopsis: I can click on all the elements with no problem, and clicking on any of them will trigger the rest to open and close without any issues.

Version.0.26.2.mp4

Here is a video of egui version 0.27.1 and 0.27.0 does the same thing as 0.27.1

Synopsis: After version 0.27.0, I can't click on all the elements, only the very bottom one. And when I do, sometimes it opens; other times, it opens then closes as well. When it opens, it seems to glitch while scrolling down, going up, then back down a little. All this stops happening if you have one ui.collapse with a different name. In the video below, I called it "hi," and you can see that the element works with no problems.

Version.0.27.1.mp4

Desktop information):**

  • OS: Gnu/Linux
  • Arch: x86_64
  • Desktop: KDE Plasma v: 5.27.11
  • Distro: Gentoo Base System release 2.14
@UnknownSuperficialNight UnknownSuperficialNight added the bug Something is broken label Mar 29, 2024
@emilk
Copy link
Owner

emilk commented Mar 29, 2024

The collapsing header needs a unique Id to store its state ('am i collapsed or not'). When using ui.collapsing the title is used as its Id, causing an Id clash. This was and still is a bug, it is just that the bug manifests differently now.

Use CollapsingHader::id_source to give each header its own unique Id.

If you compile with debug_assertions (or set Options::warn_on_id_clash) you should see a warning printed on screen when you have Id clashes

@emilk emilk closed this as completed Mar 29, 2024
emilk added a commit that referenced this issue Mar 29, 2024
@UnknownSuperficialNight
Copy link
Author

The collapsing header needs a unique Id to store its state ('am i collapsed or not'). When using ui.collapsing the title is used as its Id, causing an Id clash. This was and still is a bug, it is just that the bug manifests differently now.

Use CollapsingHader::id_source to give each header its own unique Id.

If you compile with debug_assertions (or set Options::warn_on_id_clash) you should see a warning printed on screen when you have Id clashes

Is it possible to retain the functionality to purposefully share the same Id in order to be able to click on one of the matching Id and all with the same match open?

@YgorSouza
Copy link
Contributor

Is it possible to retain the functionality to purposefully share the same Id in order to be able to click on one of the matching Id and all with the same match open?

Here is an example that does what you are asking for:

        egui::CentralPanel::default().show(ctx, |ui| {
            (1..=5).for_each(|i| {
                let header = format!("header {}", i % 2);
                let open_id = egui::Id::new(&header);
                let open = ui
                    .data_mut(|data| data.get_persisted(open_id))
                    .unwrap_or(false);
                let toggle = CollapsingHeader::new(header)
                    .id_source(("different id", i))
                    .open(Some(open))
                    .show(ui, |ui| ui.label(format!("Body {i}")))
                    .header_response
                    .clicked();
                if toggle {
                    ui.data_mut(|data| data.insert_persisted(open_id, !open));
                }
            });
        });
Screencast.from.2024-03-29.19-28-45.webm

(If you don't want the open state to be persisted to the disk, use get_temp/insert_temp instead of persisted.

@UnknownSuperficialNight
Copy link
Author

UnknownSuperficialNight commented Mar 29, 2024

Is it possible to retain the functionality to purposefully share the same Id in order to be able to click on one of the matching Id and all with the same match open?

Here is an example that does what you are asking for:

        egui::CentralPanel::default().show(ctx, |ui| {
            (1..=5).for_each(|i| {
                let header = format!("header {}", i % 2);
                let open_id = egui::Id::new(&header);
                let open = ui
                    .data_mut(|data| data.get_persisted(open_id))
                    .unwrap_or(false);
                let toggle = CollapsingHeader::new(header)
                    .id_source(("different id", i))
                    .open(Some(open))
                    .show(ui, |ui| ui.label(format!("Body {i}")))
                    .header_response
                    .clicked();
                if toggle {
                    ui.data_mut(|data| data.insert_persisted(open_id, !open));
                }
            });
        });

Screencast.from.2024-03-29.19-28-45.webm

(If you don't want the open state to be persisted to the disk, use get_temp/insert_temp instead of persisted.

You're a legend thanks a bunch i learned quite a lot from that example

emilk added a commit that referenced this issue Apr 2, 2024
hacknus pushed a commit to hacknus/egui that referenced this issue Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

3 participants