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

Can't interact with widgets added to layers other than Background #478

Open
zacx-z opened this issue Jun 11, 2021 · 5 comments
Open

Can't interact with widgets added to layers other than Background #478

zacx-z opened this issue Jun 11, 2021 · 5 comments

Comments

@zacx-z
Copy link

zacx-z commented Jun 11, 2021

just change the egui_template code into:

ui.with_layer_id(egui::LayerId::new(egui::Order::Middle, egui::Id::new("mid")), |ui| {
    ui.add(egui::Slider::new(value, 0.0..=10.0).text("value"));
    if ui.button("Increment").clicked() {
        *value += 1.0;
    }
});

and the widgets couldn't be interacted with any more. I suppose interactions are allowed in other layers because egui::LayerId::allow_interaction returns true? No more info could be found in the doc. It seems to be a bug.

@parasyte
Copy link
Contributor

parasyte commented Jun 11, 2021

The problem is that layers added with ui.with_layer_id() do not store any area state for the LayerId. When the interaction is checked, the LayerId under the pointer doesn't match, so no interactions occur.

Adding area state will fix the immediate issue. It looks like it can only be added with a frame delay, since the size of the child contents needs to be known.

This could be a blocker, but the Areas API doesn't support nested layers. E.g. only one layer at a time can request to be moved to the top, and it doesn't carry any of its child layers with it.

@zacx-z
Copy link
Author

zacx-z commented Jun 11, 2021

I just needed to draw main part of ui in the middle or foreground layer, and draw some backgrounds based on the response of the main part. The backgrounds do not have to be enabled for interaction. So it seems doable with Areas limited to be single-layered.

But it seems all built-in Areas are hardcoded to use LayerId::background(), and ui is only propagated by Area::show(). Just wondering if there's a case where ui.with_layer_id() could be used and has expected behaviors. Do I need to implement a new Area just to change the layer?

@parasyte
Copy link
Contributor

parasyte commented Jun 11, 2021

I wasn't clear. I'm talking about egui::memory::Areas, not egui::containers::Area. The former is for internal layer handling. The latter is a public container type used by Window containers.

It is possible to use the Area container to get some layering behavior, but they do not nest nicely due to the issue described above with Areas. These containers also don't flow with the normal layout, so you may have to allocate space and position them based on those allocations.

@zacx-z
Copy link
Author

zacx-z commented Jun 11, 2021

I see. I'll dig into it and see if I can get it to work.

@zacx-z zacx-z changed the title Can't interact widgets added to layers other than Background Can't interact with widgets added to layers other than Background Jun 16, 2021
@emilk
Copy link
Owner

emilk commented Apr 16, 2022

with_layer_id is for redirecting where Shapes are painted.

The only way to currently order widgets back-to-front is by using egui::Area. Though it is not very flexible at this moment.

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

No branches or pull requests

3 participants