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

Allow for requesting the user's attention to the window (#2905)

* add method for requesting attention to the main window

* use another enum member for user attention type instead of nested `Option`s

(also, document the enum members now that they don't mirror `winit`)

* update the docstring

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* add an example app for testing window attention requests

* Apply suggestions from code review

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* remove `chrono` dependency and improve the attention example's readability

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
TicClick
2023-04-19 15:29:17 +02:00
committed by GitHub
parent d1af798a9b
commit e3a021eea6
9 changed files with 206 additions and 3 deletions

View File

@@ -802,6 +802,20 @@ impl Frame {
self.output.focus = Some(true);
}
/// If the window is unfocused, attract the user's attention (native only).
///
/// Typically, this means that the window will flash on the taskbar, or bounce, until it is interacted with.
///
/// When the window comes into focus, or if `None` is passed, the attention request will be automatically reset.
///
/// See [winit's documentation][user_attention_details] for platform-specific effect details.
///
/// [user_attention_details]: https://docs.rs/winit/latest/winit/window/enum.UserAttentionType.html
#[cfg(not(target_arch = "wasm32"))]
pub fn request_user_attention(&mut self, kind: egui::UserAttentionType) {
self.output.attention = Some(kind);
}
/// Maximize or unmaximize window. (native only)
#[cfg(not(target_arch = "wasm32"))]
pub fn set_maximized(&mut self, maximized: bool) {
@@ -1126,6 +1140,10 @@ pub(crate) mod backend {
#[cfg(not(target_arch = "wasm32"))]
pub focus: Option<bool>,
/// Set to request a user's attention to the native window.
#[cfg(not(target_arch = "wasm32"))]
pub attention: Option<egui::UserAttentionType>,
#[cfg(not(target_arch = "wasm32"))]
pub screenshot_requested: bool,
}