WIP: Start rendering GPUI views to macOS status bar
This commit is contained in:
parent
f50c6af001
commit
6578af6f3b
5 changed files with 235 additions and 132 deletions
|
@ -1920,19 +1920,134 @@ impl MutableAppContext {
|
|||
},
|
||||
);
|
||||
root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx));
|
||||
this.open_platform_window(window_id, window_options);
|
||||
|
||||
let mut window =
|
||||
this.cx
|
||||
.platform
|
||||
.open_window(window_id, window_options, this.foreground.clone());
|
||||
let presenter = Rc::new(RefCell::new(
|
||||
this.build_presenter(window_id, window.titlebar_height()),
|
||||
));
|
||||
|
||||
{
|
||||
let mut app = this.upgrade();
|
||||
let presenter = Rc::downgrade(&presenter);
|
||||
window.on_event(Box::new(move |event| {
|
||||
app.update(|cx| {
|
||||
if let Some(presenter) = presenter.upgrade() {
|
||||
if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = &event {
|
||||
if cx.dispatch_keystroke(window_id, keystroke) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
presenter.borrow_mut().dispatch_event(event, false, cx)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = this.upgrade();
|
||||
window.on_active_status_change(Box::new(move |is_active| {
|
||||
app.update(|cx| cx.window_changed_active_status(window_id, is_active))
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = this.upgrade();
|
||||
window.on_resize(Box::new(move || {
|
||||
app.update(|cx| cx.window_was_resized(window_id))
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = this.upgrade();
|
||||
window.on_fullscreen(Box::new(move |is_fullscreen| {
|
||||
app.update(|cx| cx.window_was_fullscreen_changed(window_id, is_fullscreen))
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = this.upgrade();
|
||||
window.on_close(Box::new(move || {
|
||||
app.update(|cx| cx.remove_window(window_id));
|
||||
}));
|
||||
}
|
||||
|
||||
window.set_input_handler(Box::new(WindowInputHandler {
|
||||
app: this.upgrade().0,
|
||||
window_id,
|
||||
}));
|
||||
|
||||
let scene = presenter.borrow_mut().build_scene(
|
||||
window.size(),
|
||||
window.scale_factor(),
|
||||
false,
|
||||
this,
|
||||
);
|
||||
window.present_scene(scene);
|
||||
this.presenters_and_platform_windows
|
||||
.insert(window_id, (presenter.clone(), window));
|
||||
|
||||
(window_id, root_view)
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn add_status_bar_item<I, F>(&mut self, build_item: F)
|
||||
// where
|
||||
// I: View,
|
||||
// F: FnOnce(&mut ViewContext<I>) -> I,
|
||||
// {
|
||||
// mem::forget(self.platform.add_status_item());
|
||||
// }
|
||||
pub fn add_status_bar_item<T, F>(&mut self, build_root_view: F) -> (usize, ViewHandle<T>)
|
||||
where
|
||||
T: View,
|
||||
F: FnOnce(&mut ViewContext<T>) -> T,
|
||||
{
|
||||
self.update(|this| {
|
||||
let window_id = post_inc(&mut this.next_window_id);
|
||||
let root_view = this
|
||||
.build_and_insert_view(window_id, ParentId::Root, |cx| Some(build_root_view(cx)))
|
||||
.unwrap();
|
||||
this.cx.windows.insert(
|
||||
window_id,
|
||||
Window {
|
||||
root_view: root_view.clone().into(),
|
||||
focused_view_id: Some(root_view.id()),
|
||||
is_active: false,
|
||||
invalidation: None,
|
||||
is_fullscreen: false,
|
||||
},
|
||||
);
|
||||
root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx));
|
||||
|
||||
let mut status_item = this.cx.platform.add_status_item();
|
||||
let presenter = Rc::new(RefCell::new(this.build_presenter(window_id, 0.)));
|
||||
|
||||
{
|
||||
let mut app = this.upgrade();
|
||||
let presenter = Rc::downgrade(&presenter);
|
||||
status_item.on_event(Box::new(move |event| {
|
||||
app.update(|cx| {
|
||||
if let Some(presenter) = presenter.upgrade() {
|
||||
presenter.borrow_mut().dispatch_event(event, cx)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
let scene = presenter.borrow_mut().build_scene(
|
||||
status_item.size(),
|
||||
status_item.scale_factor(),
|
||||
false,
|
||||
this,
|
||||
);
|
||||
status_item.present_scene(scene);
|
||||
this.presenters_and_platform_windows
|
||||
.insert(window_id, (presenter.clone(), status_item));
|
||||
|
||||
(window_id, root_view)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn replace_root_view<T, F>(&mut self, window_id: usize, build_root_view: F) -> ViewHandle<T>
|
||||
where
|
||||
|
@ -1956,77 +2071,6 @@ impl MutableAppContext {
|
|||
self.flush_effects();
|
||||
}
|
||||
|
||||
fn open_platform_window(&mut self, window_id: usize, window_options: WindowOptions) {
|
||||
let mut window =
|
||||
self.cx
|
||||
.platform
|
||||
.open_window(window_id, window_options, self.foreground.clone());
|
||||
let presenter = Rc::new(RefCell::new(
|
||||
self.build_presenter(window_id, window.titlebar_height()),
|
||||
));
|
||||
|
||||
{
|
||||
let mut app = self.upgrade();
|
||||
let presenter = Rc::downgrade(&presenter);
|
||||
window.on_event(Box::new(move |event| {
|
||||
app.update(|cx| {
|
||||
if let Some(presenter) = presenter.upgrade() {
|
||||
if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = &event {
|
||||
if cx.dispatch_keystroke(window_id, keystroke) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
presenter.borrow_mut().dispatch_event(event, false, cx)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = self.upgrade();
|
||||
window.on_active_status_change(Box::new(move |is_active| {
|
||||
app.update(|cx| cx.window_changed_active_status(window_id, is_active))
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = self.upgrade();
|
||||
window.on_resize(Box::new(move || {
|
||||
app.update(|cx| cx.window_was_resized(window_id))
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = self.upgrade();
|
||||
window.on_fullscreen(Box::new(move |is_fullscreen| {
|
||||
app.update(|cx| cx.window_was_fullscreen_changed(window_id, is_fullscreen))
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
let mut app = self.upgrade();
|
||||
window.on_close(Box::new(move || {
|
||||
app.update(|cx| cx.remove_window(window_id));
|
||||
}));
|
||||
}
|
||||
|
||||
window.set_input_handler(Box::new(WindowInputHandler {
|
||||
app: self.upgrade().0,
|
||||
window_id,
|
||||
}));
|
||||
|
||||
let scene =
|
||||
presenter
|
||||
.borrow_mut()
|
||||
.build_scene(window.size(), window.scale_factor(), false, self);
|
||||
window.present_scene(scene);
|
||||
self.presenters_and_platform_windows
|
||||
.insert(window_id, (presenter.clone(), window));
|
||||
}
|
||||
|
||||
pub fn build_presenter(&mut self, window_id: usize, titlebar_height: f32) -> Presenter {
|
||||
Presenter::new(
|
||||
window_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue