mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 07:03:14 -04:00
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> I removed (I hope so) all wildcard imports I found. For me on my pc this improved the build time: - for egui -5s - for eframe -12s * [x] I have followed the instructions in the PR template
53 lines
1.8 KiB
Rust
53 lines
1.8 KiB
Rust
#![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::{popup_below_widget, CentralPanel, ComboBox, Id, PopupCloseBehavior};
|
|
|
|
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}"));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|