Browse Source

egui_demo_app: add some native window info

pull/3015/head
Emil Ernerfeldt 1 year ago
parent
commit
b5c24d6ec8
  1. 54
      crates/egui_demo_app/src/backend_panel.rs

54
crates/egui_demo_app/src/backend_panel.rs

@ -190,6 +190,11 @@ impl BackendPanel {
{ {
frame.drag_window(); frame.drag_window();
} }
ui.button("Native window info (hover me)")
.on_hover_ui(|ui| {
window_info_ui(ui, &frame.info().window_info);
});
} }
} }
@ -284,6 +289,55 @@ impl BackendPanel {
} }
} }
#[cfg(not(target_arch = "wasm32"))]
fn window_info_ui(ui: &mut egui::Ui, window_info: &eframe::WindowInfo) {
let eframe::WindowInfo {
position,
fullscreen,
minimized,
maximized,
focused,
size,
monitor_size,
} = window_info;
egui::Grid::new("window_info_grid")
.num_columns(2)
.show(ui, |ui| {
if let Some(egui::Pos2 { x, y }) = position {
ui.label("Position:");
ui.monospace(format!("{x:.0}, {y:.0}"));
ui.end_row();
}
ui.label("Fullscreen:");
ui.label(fullscreen.to_string());
ui.end_row();
ui.label("Minimized:");
ui.label(minimized.to_string());
ui.end_row();
ui.label("Maximized:");
ui.label(maximized.to_string());
ui.end_row();
ui.label("Focused:");
ui.label(focused.to_string());
ui.end_row();
ui.label("Window size:");
ui.monospace(format!("{x:.0} x {y:.0}", x = size.x, y = size.y));
ui.end_row();
if let Some(egui::Vec2 { x, y }) = monitor_size {
ui.label("Monitor size:");
ui.monospace(format!("{x:.0} x {y:.0}"));
ui.end_row();
}
});
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]

Loading…
Cancel
Save