mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
eframe: Add center to NativeOptions and monitor_size to WindowInfo (#2035)
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -208,7 +208,7 @@ pub enum HardwareAcceleration {
|
||||
/// Only a single native window is currently supported.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub struct NativeOptions {
|
||||
/// Sets whether or not the window will always be on top of other windows.
|
||||
/// Sets whether or not the window will always be on top of other windows at initialization.
|
||||
pub always_on_top: bool,
|
||||
|
||||
/// Show window in maximized mode
|
||||
@@ -347,6 +347,13 @@ pub struct NativeOptions {
|
||||
///
|
||||
/// For OpenGL ES 2.0: set this to [`egui_glow::ShaderVersion::Es100`] to solve blank texture problem (by using the "fallback shader").
|
||||
pub shader_version: Option<egui_glow::ShaderVersion>,
|
||||
|
||||
/// On desktop: make the window position to be centered at initialization.
|
||||
///
|
||||
/// Platform specific:
|
||||
///
|
||||
/// Wayland desktop currently not supported.
|
||||
pub centered: bool,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -389,6 +396,7 @@ impl Default for NativeOptions {
|
||||
event_loop_builder: None,
|
||||
#[cfg(feature = "glow")]
|
||||
shader_version: None,
|
||||
centered: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -712,6 +720,29 @@ impl Frame {
|
||||
self.output.visible = Some(visible);
|
||||
}
|
||||
|
||||
/// On desktop: Set the window always on top.
|
||||
///
|
||||
/// (Wayland desktop currently not supported)
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn set_always_on_top(&mut self, always_on_top: bool) {
|
||||
self.output.always_on_top = Some(always_on_top);
|
||||
}
|
||||
|
||||
/// On desktop: Set the window to be centered.
|
||||
///
|
||||
/// (Wayland desktop currently not supported)
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn set_centered(&mut self) {
|
||||
if let Some(monitor_size) = self.info.window_info.monitor_size {
|
||||
let inner_size = self.info.window_info.size;
|
||||
if monitor_size.x > 1.0 && monitor_size.y > 1.0 {
|
||||
let x = (monitor_size.x - inner_size.x) / 2.0;
|
||||
let y = (monitor_size.y - inner_size.y) / 2.0;
|
||||
self.set_window_pos(egui::Pos2 { x, y });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// for integrations only: call once per frame
|
||||
pub(crate) fn take_app_output(&mut self) -> backend::AppOutput {
|
||||
std::mem::take(&mut self.output)
|
||||
@@ -742,6 +773,9 @@ pub struct WindowInfo {
|
||||
|
||||
/// Window inner size in egui points (logical pixels).
|
||||
pub size: egui::Vec2,
|
||||
|
||||
/// Current monitor size in egui points (logical pixels)
|
||||
pub monitor_size: Option<egui::Vec2>,
|
||||
}
|
||||
|
||||
/// Information about the URL.
|
||||
@@ -915,5 +949,9 @@ pub(crate) mod backend {
|
||||
/// Set to some bool to change window visibility.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub visible: Option<bool>,
|
||||
|
||||
/// Set to some bool to tell the window always on top.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub always_on_top: Option<bool>,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user