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

Output events when widgets gain keyboard focus

Part of https://github.com/emilk/egui/issues/167
This commit is contained in:
Emil Ernerfeldt
2021-03-07 19:32:27 +01:00
parent a370339db7
commit cd4c07e09a
15 changed files with 140 additions and 12 deletions

View File

@@ -117,6 +117,7 @@ impl epi::App for WrapApp {
});
self.backend_panel.update(ctx, frame);
if self.backend_panel.open || ctx.memory().everything_is_visible() {
egui::SidePanel::left("backend_panel", 150.0).show(ctx, |ui| {
self.backend_panel.ui(ui, frame);
@@ -128,6 +129,8 @@ impl epi::App for WrapApp {
app.update(ctx, frame);
}
}
self.backend_panel.end_of_frame(ctx);
}
}
@@ -216,6 +219,9 @@ struct BackendPanel {
#[cfg_attr(feature = "persistence", serde(skip))]
frame_history: crate::frame_history::FrameHistory,
#[cfg_attr(feature = "persistence", serde(skip))]
output_event_history: std::collections::VecDeque<egui::OutputEvent>,
}
impl Default for BackendPanel {
@@ -227,6 +233,7 @@ impl Default for BackendPanel {
max_size_points_ui: egui::Vec2::new(1024.0, 2048.0),
max_size_points_active: egui::Vec2::new(1024.0, 2048.0),
frame_history: Default::default(),
output_event_history: Default::default(),
}
}
}
@@ -242,6 +249,15 @@ impl BackendPanel {
}
}
fn end_of_frame(&mut self, ctx: &egui::CtxRef) {
for event in &ctx.output().events {
self.output_event_history.push_back(event.clone());
}
while self.output_event_history.len() > 10 {
self.output_event_history.pop_front();
}
}
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut epi::Frame<'_>) {
ui.heading("💻 Backend");
@@ -298,6 +314,14 @@ impl BackendPanel {
frame.quit();
}
}
ui.collapsing("Output events", |ui| {
ui.set_max_width(350.0);
ui.label("Recent output events from egui:");
for event in &self.output_event_history {
ui.monospace(format!("{:?}", event));
}
});
}
fn pixels_per_point_ui(