Introduce a WindowContext::focus method that implies the window id

This commit is contained in:
Antonio Scandurra 2023-07-05 09:39:04 +02:00
parent 31483db5d8
commit 25564ea058
3 changed files with 8 additions and 8 deletions

View file

@ -244,8 +244,7 @@ impl ContextMenu {
let show_count = self.show_count; let show_count = self.show_count;
cx.defer(move |this, cx| { cx.defer(move |this, cx| {
if cx.handle().is_focused(cx) && this.show_count == show_count { if cx.handle().is_focused(cx) && this.show_count == show_count {
let window_id = cx.window_id(); (**cx).focus(this.previously_focused_view_id.take());
(**cx).focus(window_id, this.previously_focused_view_id.take());
} }
}); });
} else { } else {

View file

@ -2971,14 +2971,12 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
} }
pub fn focus(&mut self, handle: &AnyViewHandle) { pub fn focus(&mut self, handle: &AnyViewHandle) {
self.window_context self.window_context.focus(Some(handle.view_id));
.focus(handle.window_id, Some(handle.view_id));
} }
pub fn focus_self(&mut self) { pub fn focus_self(&mut self) {
let window_id = self.window_id;
let view_id = self.view_id; let view_id = self.view_id;
self.window_context.focus(window_id, Some(view_id)); self.window_context.focus(Some(view_id));
} }
pub fn is_self_focused(&self) -> bool { pub fn is_self_focused(&self) -> bool {
@ -2997,8 +2995,7 @@ impl<'a, 'b, V: View> ViewContext<'a, 'b, V> {
} }
pub fn blur(&mut self) { pub fn blur(&mut self) {
let window_id = self.window_id; self.window_context.focus(None);
self.window_context.focus(window_id, None);
} }
pub fn on_window_should_close<F>(&mut self, mut callback: F) pub fn on_window_should_close<F>(&mut self, mut callback: F)

View file

@ -1096,6 +1096,10 @@ impl<'a> WindowContext<'a> {
self.window.focused_view_id self.window.focused_view_id
} }
pub fn focus(&mut self, view_id: Option<usize>) {
self.app_context.focus(self.window_id, view_id);
}
pub fn window_bounds(&self) -> WindowBounds { pub fn window_bounds(&self) -> WindowBounds {
self.window.platform_window.bounds() self.window.platform_window.bounds()
} }