Skip to content

Use eguis native modals#250

Open
mkalte666 wants to merge 1 commit intojannistpl:mainfrom
mkalte666:egui_modal
Open

Use eguis native modals#250
mkalte666 wants to merge 1 commit intojannistpl:mainfrom
mkalte666:egui_modal

Conversation

@mkalte666
Copy link

@mkalte666 mkalte666 commented Mar 14, 2025

This commit/PR modifies the drawing routines so that instead of using a custom modal implementation, eguis native egui::containers::Modal is used.

This comes with a few modifications:

  • FileDialog::update_ui() now either creates a modal, or a window.
  • In case as_modal is true, we fake a title bar, for consistent looks.
  • In case as_modal is true, inner modals are drawn using eguis modal functionality as well, and are nested (so, their own drawn overlay).
  • Custom background drawing and input blocking has been removed.

Todos left are

  • Check if the sub-modals are working properly
  • Evaluate if the early return in case of sub-modals is needed in
    the as_modal=true case; inputs should be blocked so that might be
    prettier.
  • Make the modal movable.

EDIT: ok my afternoon plans were canceled the moment i posted the pr, so i went on and this was honestly a quick thing to check, and with the early return it works nicely.

Feel free to review, i think i am done with this for now.

This closes #232

Have a good day!
~mkalte

@jannistpl
Copy link
Owner

Hey mkalte,

Thank you for this PR! The fact that we have to render our own title bar is quite annoying. I think egui should enable something like this in modals by default.

But your implementation is a good workaround for now. I'll take a closer look at the PR this evening.

@mkalte666
Copy link
Author

Thanks for your message.

Egui has an internal TitleBar struct for this, which sadly is not exposed. Also, from reading it, i doubt you can be adapted "just like that". What im doing is quite cheaty.

I have updated, squashed commits, fixed the clippy warnings i got locally, and edited the commit message to follow your naming convenctions. Hope this helps.

One thing i have not been able to fix so far is enable moving of the modal window. I will tinker around with this a bit more and maybe update this again in an hour or so. This will probably mostly affect the create_modal function however, and its Area properties, so everything else should stay as is (tm).

@mkalte666
Copy link
Author

mkalte666 commented Mar 14, 2025

Ok, so the egui builtin modal is intentionally made to be centered.

Either

  • Live with this. Documentation would need updating that movable and resizeable will not work in modal-mode.
  • Workaround via native modal - create a screen filling shim frame and draw a draggable frame in the middle. Its a shame there still are no nested windows in egui o.o
  • Workaround using the old modal way. This can be done via ui layer ordering IIRC.

I am not sure what the best approach would be - its not my library after all. The only thing im sure of is that it cannot remain as is; the initial reason i created this PR in the first place is that a file dialog created from within a native egui modal will not properly overlay the modal that created it, even though the dialogs are the last thing i draw in my main drawing function.

@jannistpl
Copy link
Owner

jannistpl commented Mar 14, 2025

Thank you for putting so much time into this. At the moment the egui modals still feel relatively rudimentary. I think we should just live with the fact that we can't move the window in modal mode and update the documentation accordingly. In the end, I don't really see a use case for wanting to move a modal window anyway. If that is desired in the future, we will probably have to open an issue or PR at egui.

@jannistpl
Copy link
Owner

I've tested the changes a bit. So far, it looks good. I don't think the biggest issue is that we can't move the window, but rather that we can't resize it. Is this configurable in egui's modal windows? I haven't used the built-in modals myself.

If that's not possible, it's probably best to open an issue at egui to get the modals to work with regular windows.

@mkalte666
Copy link
Author

I've tested the changes a bit. So far, it looks good. I don't think the biggest issue is that we can't move the window, but rather that we can't resize it. Is this configurable in egui's modal windows? I haven't used the built-in modals myself.

As far as i know it is not, but i think it can be feasibly emulated as well. If you aren't in a rush, i think i can allocate some time at work Thursday or Friday to work on this again.

@jannistpl
Copy link
Owner

As far as i know it is not, but i think it can be feasibly emulated as well. If you aren't in a rush, i think i can allocate some time at work Thursday or Friday to work on this again.

That would be great if you could take a look after that. I only build a new release when there's one at egui anyway. So no stress about getting it done quickly :)

@mkalte666
Copy link
Author

As far as i know it is not, but i think it can be feasibly emulated as well. If you aren't in a rush, i think i can allocate some time at work Thursday or Friday to work on this again.

That would be great if you could take a look after that. I only build a new release when there's one at egui anyway. So no stress about getting it done quickly :)

I have not forgotten about this, im just quite busy o.o

@jannistpl
Copy link
Owner

@mkalte666 Everything's fine, I understand! The file dialog still works with the custom implementation, so no stress. Take your time :)

This commit modifies the drawing routines so that instead of using a
custom modal implementaion, eguis native egui::containers::Modal is
used.

This comes with a few modifications:

  * FileDialog::update_ui() now either creates a modal, or a window.
  * In case as_modal is true, we fake a title bar, for consistent looks.
  * In case as_modal is true, inner modals are drawn using eguis modal
    functionality as well, and are nested (so, their own drawn overlay).
  * Custom background drawing and input blocking has been removed.

This closes jannistpl#232

Have a good day!
~mkalte
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

Successfully merging this pull request may close these issues.

Adopt the official modal system of egui v0.30

2 participants