On Windows and MacOS, add Window::has_focus

This commit is contained in:
Amr Bashir 2023-01-17 03:30:14 +02:00 committed by GitHub
parent 067535eb38
commit a88d2e079d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 102 additions and 2 deletions

View file

@ -23,6 +23,7 @@ pub struct Window {
register_redraw_request: Box<dyn Fn()>,
resize_notify_fn: Box<dyn Fn(PhysicalSize<u32>)>,
destroy_fn: Option<Box<dyn FnOnce()>>,
has_focus: Rc<RefCell<bool>>,
}
impl Window {
@ -42,7 +43,8 @@ impl Window {
let register_redraw_request = Box::new(move || runner.request_redraw(RootWI(id)));
target.register(&canvas, id, prevent_default);
let has_focus = Rc::new(RefCell::new(false));
target.register(&canvas, id, prevent_default, has_focus.clone());
let runner = target.runner.clone();
let resize_notify_fn = Box::new(move |new_size| {
@ -62,6 +64,7 @@ impl Window {
register_redraw_request,
resize_notify_fn,
destroy_fn: Some(destroy_fn),
has_focus,
};
backend::set_canvas_size(
@ -399,6 +402,10 @@ impl Window {
}
#[inline]
pub fn has_focus(&self) -> bool {
*self.has_focus.borrow()
}
pub fn title(&self) -> String {
String::new()
}