Skip to content

Commit

Permalink
egui_demo_app: add some native window info
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed May 22, 2023
1 parent a1d0e29 commit b5c24d6
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions crates/egui_demo_app/src/backend_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ impl BackendPanel {
{
frame.drag_window();
}

ui.button("Native window info (hover me)")
.on_hover_ui(|ui| {
window_info_ui(ui, &frame.info().window_info);
});
}
}

Expand Down Expand Up @@ -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))]
Expand Down

0 comments on commit b5c24d6

Please sign in to comment.