-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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?) --- - Improvements on <#4607>
- Loading branch information
Showing
6 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "popups" | ||
edition.workspace = true | ||
license.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
eframe = { workspace = true, features = [ | ||
"default", | ||
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO | ||
] } | ||
env_logger = { version = "0.10", default-features = false, features = [ | ||
"auto-color", | ||
"humantime", | ||
] } | ||
|
||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Example of how to use menus, popups, context menus and tooltips. | ||
|
||
```sh | ||
cargo run -p popups | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release | ||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example | ||
|
||
use eframe::egui::*; | ||
|
||
fn main() -> Result<(), eframe::Error> { | ||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). | ||
let options = eframe::NativeOptions::default(); | ||
|
||
eframe::run_native("Popups", options, Box::new(|_| Ok(Box::<MyApp>::default()))) | ||
} | ||
|
||
#[derive(Default)] | ||
struct MyApp { | ||
checkbox: bool, | ||
number: u8, | ||
} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) { | ||
CentralPanel::default().show(ctx, |ui| { | ||
ui.label("PopupCloseBehavior::CloseOnClickAway popup"); | ||
let response = ui.button("Open"); | ||
let popup_id = Id::new("popup_id"); | ||
|
||
if response.clicked() { | ||
ui.memory_mut(|mem| mem.toggle_popup(popup_id)); | ||
} | ||
|
||
popup_below_widget( | ||
ui, | ||
popup_id, | ||
&response, | ||
PopupCloseBehavior::CloseOnClickOutside, | ||
|ui| { | ||
ui.set_min_width(300.0); | ||
ui.label("This popup will be open even if you click the checkbox"); | ||
ui.checkbox(&mut self.checkbox, "Checkbox"); | ||
}, | ||
); | ||
|
||
ui.label("PopupCloseBehavior::CloseOnClick popup"); | ||
ComboBox::from_label("ComboBox") | ||
.selected_text(format!("{}", self.number)) | ||
.show_ui(ui, |ui| { | ||
for num in 0..10 { | ||
ui.selectable_value(&mut self.number, num, format!("{num}")); | ||
} | ||
}); | ||
}); | ||
} | ||
} |