mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -04:00
eframe: read the state of native window's input focus and request it (#2900)
* Add ability to read the native window's focus state * Add `eframe::Frame::focus()` for requesting the native window's focus * rename the output field `active` → `focused` for consistency
This commit is contained in:
@@ -814,6 +814,15 @@ impl Frame {
|
||||
self.output.minimized = Some(minimized);
|
||||
}
|
||||
|
||||
/// Bring the window into focus (native only). Has no effect on Wayland, or if the window is minimized or invisible.
|
||||
///
|
||||
/// This method puts the window on top of other applications and takes input focus away from them,
|
||||
/// which, if unexpected, will disturb the user.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn focus(&mut self) {
|
||||
self.output.focus = Some(true);
|
||||
}
|
||||
|
||||
/// Maximize or unmaximize window. (native only)
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn set_maximized(&mut self, maximized: bool) {
|
||||
@@ -938,6 +947,9 @@ pub struct WindowInfo {
|
||||
/// Are we maximized?
|
||||
pub maximized: bool,
|
||||
|
||||
/// Is the window focused and able to receive input?
|
||||
pub focused: bool,
|
||||
|
||||
/// Window inner size in egui points (logical pixels).
|
||||
pub size: egui::Vec2,
|
||||
|
||||
@@ -1129,6 +1141,10 @@ pub(crate) mod backend {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub maximized: Option<bool>,
|
||||
|
||||
/// Set to some bool to focus window.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub focus: Option<bool>,
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub screenshot_requested: bool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user