Merge remote-tracking branch 'origin/sexy' into chat-theme-prep
This commit is contained in:
+31
-24
@@ -12,7 +12,6 @@ use anyhow::{anyhow, Result};
|
||||
use async_task::Task;
|
||||
use keymap::MatchResult;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use pathfinder_geometry::{rect::RectF, vector::vec2f};
|
||||
use platform::Event;
|
||||
use postage::{mpsc, sink::Sink as _, stream::Stream as _};
|
||||
use smol::prelude::*;
|
||||
@@ -305,7 +304,9 @@ impl TestAppContext {
|
||||
T: View,
|
||||
F: FnOnce(&mut ViewContext<T>) -> T,
|
||||
{
|
||||
self.cx.borrow_mut().add_window(build_root_view)
|
||||
self.cx
|
||||
.borrow_mut()
|
||||
.add_window(Default::default(), build_root_view)
|
||||
}
|
||||
|
||||
pub fn window_ids(&self) -> Vec<usize> {
|
||||
@@ -973,7 +974,11 @@ impl MutableAppContext {
|
||||
handle
|
||||
}
|
||||
|
||||
pub fn add_window<T, F>(&mut self, build_root_view: F) -> (usize, ViewHandle<T>)
|
||||
pub fn add_window<T, F>(
|
||||
&mut self,
|
||||
window_options: WindowOptions,
|
||||
build_root_view: F,
|
||||
) -> (usize, ViewHandle<T>)
|
||||
where
|
||||
T: View,
|
||||
F: FnOnce(&mut ViewContext<T>) -> T,
|
||||
@@ -990,7 +995,7 @@ impl MutableAppContext {
|
||||
invalidation: None,
|
||||
},
|
||||
);
|
||||
self.open_platform_window(window_id);
|
||||
self.open_platform_window(window_id, window_options);
|
||||
root_view.update(self, |view, cx| {
|
||||
view.on_focus(cx);
|
||||
cx.notify();
|
||||
@@ -1006,15 +1011,11 @@ impl MutableAppContext {
|
||||
self.remove_dropped_entities();
|
||||
}
|
||||
|
||||
fn open_platform_window(&mut self, window_id: usize) {
|
||||
let mut window = self.cx.platform.open_window(
|
||||
window_id,
|
||||
WindowOptions {
|
||||
bounds: RectF::new(vec2f(0., 0.), vec2f(1024., 768.)),
|
||||
title: "Zed".into(),
|
||||
},
|
||||
self.foreground.clone(),
|
||||
);
|
||||
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 text_layout_cache = TextLayoutCache::new(self.cx.platform.fonts());
|
||||
let presenter = Rc::new(RefCell::new(Presenter::new(
|
||||
window_id,
|
||||
@@ -1054,6 +1055,7 @@ impl MutableAppContext {
|
||||
app.update(|cx| {
|
||||
let scene = presenter.borrow_mut().build_scene(
|
||||
window.size(),
|
||||
window.titlebar_height(),
|
||||
window.scale_factor(),
|
||||
cx,
|
||||
);
|
||||
@@ -1210,7 +1212,12 @@ impl MutableAppContext {
|
||||
{
|
||||
let mut presenter = presenter.borrow_mut();
|
||||
presenter.invalidate(invalidation, self.as_ref());
|
||||
let scene = presenter.build_scene(window.size(), window.scale_factor(), self);
|
||||
let scene = presenter.build_scene(
|
||||
window.size(),
|
||||
window.titlebar_height(),
|
||||
window.scale_factor(),
|
||||
self,
|
||||
);
|
||||
window.present_scene(scene);
|
||||
}
|
||||
self.presenters_and_platform_windows
|
||||
@@ -3120,7 +3127,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
let (window_id, _) = cx.add_window(|cx| View::new(None, cx));
|
||||
let (window_id, _) = cx.add_window(Default::default(), |cx| View::new(None, cx));
|
||||
let handle_1 = cx.add_view(window_id, |cx| View::new(None, cx));
|
||||
let handle_2 = cx.add_view(window_id, |cx| View::new(Some(handle_1.clone()), cx));
|
||||
assert_eq!(cx.cx.views.len(), 3);
|
||||
@@ -3176,7 +3183,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let mouse_down_count = Arc::new(AtomicUsize::new(0));
|
||||
let (window_id, _) = cx.add_window(|_| View {
|
||||
let (window_id, _) = cx.add_window(Default::default(), |_| View {
|
||||
mouse_down_count: mouse_down_count.clone(),
|
||||
});
|
||||
let presenter = cx.presenters_and_platform_windows[&window_id].0.clone();
|
||||
@@ -3234,7 +3241,7 @@ mod tests {
|
||||
released: model_released.clone(),
|
||||
});
|
||||
|
||||
let (window_id, _) = cx.add_window(|_| View {
|
||||
let (window_id, _) = cx.add_window(Default::default(), |_| View {
|
||||
released: view_released.clone(),
|
||||
});
|
||||
|
||||
@@ -3277,7 +3284,7 @@ mod tests {
|
||||
type Event = usize;
|
||||
}
|
||||
|
||||
let (window_id, handle_1) = cx.add_window(|_| View::default());
|
||||
let (window_id, handle_1) = cx.add_window(Default::default(), |_| View::default());
|
||||
let handle_2 = cx.add_view(window_id, |_| View::default());
|
||||
let handle_2b = handle_2.clone();
|
||||
let handle_3 = cx.add_model(|_| Model);
|
||||
@@ -3330,7 +3337,7 @@ mod tests {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
let (window_id, _) = cx.add_window(|_| View);
|
||||
let (window_id, _) = cx.add_window(Default::default(), |_| View);
|
||||
let observing_view = cx.add_view(window_id, |_| View);
|
||||
let emitting_view = cx.add_view(window_id, |_| View);
|
||||
let observing_model = cx.add_model(|_| Model);
|
||||
@@ -3383,7 +3390,7 @@ mod tests {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
let (_, view) = cx.add_window(|_| View::default());
|
||||
let (_, view) = cx.add_window(Default::default(), |_| View::default());
|
||||
let model = cx.add_model(|_| Model::default());
|
||||
|
||||
view.update(cx, |_, c| {
|
||||
@@ -3423,7 +3430,7 @@ mod tests {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
let (window_id, _) = cx.add_window(|_| View);
|
||||
let (window_id, _) = cx.add_window(Default::default(), |_| View);
|
||||
let observing_view = cx.add_view(window_id, |_| View);
|
||||
let observing_model = cx.add_model(|_| Model);
|
||||
let observed_model = cx.add_model(|_| Model);
|
||||
@@ -3473,7 +3480,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let events: Arc<Mutex<Vec<String>>> = Default::default();
|
||||
let (window_id, view_1) = cx.add_window(|_| View {
|
||||
let (window_id, view_1) = cx.add_window(Default::default(), |_| View {
|
||||
events: events.clone(),
|
||||
name: "view 1".to_string(),
|
||||
});
|
||||
@@ -3583,7 +3590,7 @@ mod tests {
|
||||
actions_clone.borrow_mut().push(format!("{} d", view.id));
|
||||
});
|
||||
|
||||
let (window_id, view_1) = cx.add_window(|_| ViewA { id: 1 });
|
||||
let (window_id, view_1) = cx.add_window(Default::default(), |_| ViewA { id: 1 });
|
||||
let view_2 = cx.add_view(window_id, |_| ViewB { id: 2 });
|
||||
let view_3 = cx.add_view(window_id, |_| ViewA { id: 3 });
|
||||
let view_4 = cx.add_view(window_id, |_| ViewB { id: 4 });
|
||||
@@ -3663,7 +3670,7 @@ mod tests {
|
||||
view_2.keymap_context.set.insert("b".into());
|
||||
view_3.keymap_context.set.insert("c".into());
|
||||
|
||||
let (window_id, view_1) = cx.add_window(|_| view_1);
|
||||
let (window_id, view_1) = cx.add_window(Default::default(), |_| view_1);
|
||||
let view_2 = cx.add_view(window_id, |_| view_2);
|
||||
let view_3 = cx.add_view(window_id, |_| view_3);
|
||||
|
||||
|
||||
@@ -92,12 +92,15 @@ pub trait Window: WindowContext {
|
||||
pub trait WindowContext {
|
||||
fn size(&self) -> Vector2F;
|
||||
fn scale_factor(&self) -> f32;
|
||||
fn titlebar_height(&self) -> f32;
|
||||
fn present_scene(&mut self, scene: Scene);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WindowOptions<'a> {
|
||||
pub bounds: RectF,
|
||||
pub title: Option<&'a str>,
|
||||
pub titlebar_appears_transparent: bool,
|
||||
}
|
||||
|
||||
pub struct PathPromptOptions {
|
||||
|
||||
@@ -15,6 +15,7 @@ use cocoa::{
|
||||
foundation::{NSAutoreleasePool, NSInteger, NSSize, NSString},
|
||||
quartzcore::AutoresizingMask,
|
||||
};
|
||||
use core_graphics::display::CGRect;
|
||||
use ctor::ctor;
|
||||
use foreign_types::ForeignType as _;
|
||||
use objc::{
|
||||
@@ -153,11 +154,15 @@ impl Window {
|
||||
let pool = NSAutoreleasePool::new(nil);
|
||||
|
||||
let frame = options.bounds.to_ns_rect();
|
||||
let style_mask = NSWindowStyleMask::NSClosableWindowMask
|
||||
let mut style_mask = NSWindowStyleMask::NSClosableWindowMask
|
||||
| NSWindowStyleMask::NSMiniaturizableWindowMask
|
||||
| NSWindowStyleMask::NSResizableWindowMask
|
||||
| NSWindowStyleMask::NSTitledWindowMask;
|
||||
|
||||
if options.titlebar_appears_transparent {
|
||||
style_mask |= NSWindowStyleMask::NSFullSizeContentViewWindowMask;
|
||||
}
|
||||
|
||||
let native_window: id = msg_send![WINDOW_CLASS, alloc];
|
||||
let native_window = native_window.initWithContentRect_styleMask_backing_defer_(
|
||||
frame,
|
||||
@@ -213,6 +218,9 @@ impl Window {
|
||||
if let Some(title) = options.title.as_ref() {
|
||||
native_window.setTitle_(NSString::alloc(nil).init_str(title));
|
||||
}
|
||||
if options.titlebar_appears_transparent {
|
||||
native_window.setTitlebarAppearsTransparent_(YES);
|
||||
}
|
||||
native_window.setAcceptsMouseMovedEvents_(YES);
|
||||
|
||||
native_view.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
|
||||
@@ -329,6 +337,10 @@ impl platform::WindowContext for Window {
|
||||
fn present_scene(&mut self, scene: Scene) {
|
||||
self.0.as_ref().borrow_mut().present_scene(scene);
|
||||
}
|
||||
|
||||
fn titlebar_height(&self) -> f32 {
|
||||
self.0.as_ref().borrow().titlebar_height()
|
||||
}
|
||||
}
|
||||
|
||||
impl platform::WindowContext for WindowState {
|
||||
@@ -345,6 +357,14 @@ impl platform::WindowContext for WindowState {
|
||||
}
|
||||
}
|
||||
|
||||
fn titlebar_height(&self) -> f32 {
|
||||
unsafe {
|
||||
let frame = NSWindow::frame(self.native_window);
|
||||
let content_layout_rect: CGRect = msg_send![self.native_window, contentLayoutRect];
|
||||
(frame.size.height - content_layout_rect.size.height) as f32
|
||||
}
|
||||
}
|
||||
|
||||
fn present_scene(&mut self, scene: Scene) {
|
||||
self.scene_to_render = Some(scene);
|
||||
unsafe {
|
||||
|
||||
@@ -164,6 +164,10 @@ impl super::WindowContext for Window {
|
||||
self.scale_factor
|
||||
}
|
||||
|
||||
fn titlebar_height(&self) -> f32 {
|
||||
24.
|
||||
}
|
||||
|
||||
fn present_scene(&mut self, scene: crate::Scene) {
|
||||
self.current_scene = Some(scene);
|
||||
}
|
||||
|
||||
@@ -70,13 +70,14 @@ impl Presenter {
|
||||
pub fn build_scene(
|
||||
&mut self,
|
||||
window_size: Vector2F,
|
||||
titlebar_height: f32,
|
||||
scale_factor: f32,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> Scene {
|
||||
let mut scene = Scene::new(scale_factor);
|
||||
|
||||
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
||||
self.layout(window_size, cx);
|
||||
self.layout(window_size, titlebar_height, cx);
|
||||
self.after_layout(cx);
|
||||
let mut paint_cx = PaintContext {
|
||||
scene: &mut scene,
|
||||
@@ -98,7 +99,7 @@ impl Presenter {
|
||||
scene
|
||||
}
|
||||
|
||||
fn layout(&mut self, size: Vector2F, cx: &mut MutableAppContext) {
|
||||
fn layout(&mut self, size: Vector2F, titlebar_height: f32, cx: &mut MutableAppContext) {
|
||||
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
||||
let mut layout_ctx = LayoutContext {
|
||||
rendered_views: &mut self.rendered_views,
|
||||
@@ -108,6 +109,7 @@ impl Presenter {
|
||||
asset_cache: &self.asset_cache,
|
||||
view_stack: Vec::new(),
|
||||
app: cx,
|
||||
titlebar_height,
|
||||
};
|
||||
layout_ctx.layout(root_view_id, SizeConstraint::strict(size));
|
||||
}
|
||||
@@ -186,6 +188,7 @@ pub struct LayoutContext<'a> {
|
||||
pub asset_cache: &'a AssetCache,
|
||||
pub app: &'a mut MutableAppContext,
|
||||
view_stack: Vec<usize>,
|
||||
pub titlebar_height: f32,
|
||||
}
|
||||
|
||||
impl<'a> LayoutContext<'a> {
|
||||
|
||||
Reference in New Issue
Block a user