Skip to content

How do I detect clicks on the background of a layout with buttons and labels inside? #4856

Closed Answered by CanisLupus
CanisLupus asked this question in Q&A
Discussion options

You must be logged in to vote

I accidentally stumbled upon interact_bg just now 😅

You can call it with a Sense inside the widget you are drawing, and the background will detect that Sense:

ui.vertical(|ui| {
    // draw some buttons, labels, etc

    if ui.interact_bg(egui::Sense::click()).clicked() {
        // click-related code
    }
});

Keep in mind that interact_bg works with the ID of the parent element you are drawing, so if you have multiple ones they will each require a custom ID, which you can give them with push_id.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CanisLupus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant