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

Add PopupCloseBehavior #4636

Merged
merged 6 commits into from
Jun 27, 2024
Merged

Add PopupCloseBehavior #4636

merged 6 commits into from
Jun 27, 2024

Conversation

Umatriz
Copy link
Contributor

@Umatriz Umatriz commented Jun 7, 2024

This PR adds PopupCloseBehavior to improve state of the #4607

PopupCloseBehavior determines when popup will be closed.

  • CloseOnClick popup will be closed if the click happens anywhere even in the popup's body
  • CloseOnClickAway popup will be closed if the click happens somewhere else but in the popup's body.

It also adds a test in the demo app which contains several popups examples.


My ideas about #4607 is to make every tooltip and popup a menu. So it will provide more control over popups and tooltips (you will be able to close a popup by calling something similar to the ui.close_menu if you need to). You won't need to manually handle it's opening. And also will allow to have multiple popups opened. That means you can have a popup inside a popup. And it will also lead to the easier creation of the popups. (should we create a tracking issue to track changes because to me it seems like a huge amount of changes to be done?)


`PopupCloseBehavior` determines when popup will be closed.
- `CloseOnClick` popup will be closed if the click happens anywhere even in the popup's body
- `CloseOnClickAway` popup will be closed if the click happens somewhere else but in the popup's body.
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Comment on lines 259 to 260
/// Popup will be closed on click
/// It is used in the [`ComboBox`]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Popup will be closed on click
/// It is used in the [`ComboBox`]
/// Popup will be closed on click anywhere, inside or outside the popup.
///
/// It is used in [`ComboBox`].

crates/egui/src/containers/popup.rs Show resolved Hide resolved

/// Popup will be closed if the click happened somewhere else
/// but in the popup's body
CloseOnClickAway,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CloseOnClickAway,
CloseOnClickOutside,

.inner;
});

let is_close = match close_behavior {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let is_close = match close_behavior {
let should_close = match close_behavior {

("is close" sounds like it is about proximity)

- Adds new option `PopupCloseBehavior::IgnoreClicks`
- Renames `CloseOnClickAway` -> `CloseOnClickOutside`
@Umatriz Umatriz requested a review from emilk June 25, 2024 13:22
@emilk emilk added the egui label Jun 26, 2024
@emilk
Copy link
Owner

emilk commented Jun 26, 2024

CI is red though

@Umatriz
Copy link
Contributor Author

Umatriz commented Jun 27, 2024

@emilk I fixed the doc test so now everything should be fine

@emilk emilk changed the title add PopupCloseBehavior Add PopupCloseBehavior Jun 27, 2024
@emilk emilk merged commit 5051e94 into emilk:master Jun 27, 2024
19 checks passed
@emilk emilk added the feature New feature or request label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants