1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Fix mouse input

Now on Context.create_viewport in the render function will we have viewport_id and parent_viewport_id
New problem if a windows is fucused and we interact with other window the first event will be send to the last window that was focused
This commit is contained in:
Konkitoman
2023-07-24 14:24:30 +03:00
parent 3a1d9f2e21
commit 4d883b8217
36 changed files with 261 additions and 173 deletions

View File

@@ -1,5 +1,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use std::sync::{Arc, RwLock};
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
@@ -16,15 +18,20 @@ fn main() -> Result<(), eframe::Error> {
}
#[derive(Default)]
struct MyApp {
struct MyAppData {
allowed_to_close: bool,
show_confirmation_dialog: bool,
}
#[derive(Default)]
struct MyApp {
data: Arc<RwLock<MyAppData>>,
}
impl eframe::App for MyApp {
fn on_close_event(&mut self) -> bool {
self.show_confirmation_dialog = true;
self.allowed_to_close
self.data.write().unwrap().show_confirmation_dialog = true;
self.data.read().unwrap().allowed_to_close
}
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
@@ -32,23 +39,27 @@ impl eframe::App for MyApp {
ui.heading("Try to close the window");
});
if self.show_confirmation_dialog {
let show_confirmation_dialog = self.data.read().unwrap().show_confirmation_dialog;
if show_confirmation_dialog {
let data = self.data.clone();
// Show confirmation dialog:
egui::Window::new("Do you want to quit?")
.collapsible(false)
.resizable(false)
.show(ctx, |ui| {
.show(ctx, move |ui, _, _| {
ui.horizontal(|ui| {
if ui.button("Cancel").clicked() {
self.show_confirmation_dialog = false;
data.write().unwrap().show_confirmation_dialog = false;
}
if ui.button("Yes!").clicked() {
self.allowed_to_close = true;
frame.close();
data.write().unwrap().allowed_to_close = true;
}
});
});
if self.data.read().unwrap().allowed_to_close {
frame.close()
}
}
}
}