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

Overlaping widgets #980

Closed
AlphaSteam opened this issue Dec 21, 2021 · 4 comments · Fixed by #2244
Closed

Overlaping widgets #980

AlphaSteam opened this issue Dec 21, 2021 · 4 comments · Fixed by #2244
Labels
design Some architectual design work needed feature New feature or request rerun Desired for Rerun.io

Comments

@AlphaSteam
Copy link

Hello,

I'm using egui for a game engine project for card roguelikes and I wanted to use egui for the cards as ui elements.
The problem is that no matter what I do, I can't put text inside an image. As I read on another issue, widgets are expected not to overlap inside a window.

Could it be possible to allow widgets to overlap each other if explicitly told to do so?
This could help do composed widgets like you do on HTML.

I've tried using Areas, Windows, and Layouts. I tried putting the widget with put and using rects. I tried changing the order of the Widgets.

I also tried creating two areas at the same place, but they don't move at the same time. Perhaps there's a way to link two areas so they move at the same time, but I couldn't figure it out.

card
I would like to put the text above and below, in front of the card.

If this is already possible, any help to achieve it will be appreciated.

Thanks for everyone's work on this project, it's an awesome library.

@BctfN0HUK7Yg
Copy link
Contributor

I think the better way is to create custom widget for card.
https://github.com/emilk/egui/blob/master/egui_demo_lib/src/apps/demo/toggle_switch.rs

@parasyte
Copy link
Contributor

For a little more context and a theoretical basis, thinking of a "widget" as its individual components (image, text, shapes, etc.) is probably not the right level of abstraction. A widget is a rectangular area that is allocated from the layout, but what exists inside that rectangle is up to the widget itself; it can render any shapes it wants inside that space.

This is how, e.g., the plot widget works. The paths and labels inside the plot are children of the parent rectangle. In short, widgets are a hierarchy, and "overlapping" can be naturally defined by the parent-child relationship.

@emilk
Copy link
Owner

emilk commented Apr 16, 2022

Overlapping widgets is something I also miss from time to time, e.g. to put controls on top of a canvas that can also be interacted with.

Right now the only way to have overlapping widgets is to use Area:s (e.g. Windows). egui remember the position and sizes of each Area and can therefor on each frame know which one is on top for any single position, and therefore which one should receive a click. The problem is: if you have multiple overlapping widgets in the same Area, which should receive the click?

Some idea for solutions:

  • The first widget you add gets the interaction. Requires rendering the widgets front-to-back, which requires adding some better layering (sub-layers per Area) or z-order on the Shapes. This would be a nice feature in any case.
  • Having one Area be the child of another, so that it follows the parent:s clip area, and ordering, etc. Seems a bit complicated, but perhaps doable.

How does other immediate mode API:s handle this?

@emilk emilk added feature New feature or request design Some architectual design work needed labels Apr 16, 2022
@emilk
Copy link
Owner

emilk commented Apr 19, 2022

Related: #1516

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Some architectual design work needed feature New feature or request rerun Desired for Rerun.io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants