Merge branch 'main' into randomized-tests-operation-script
This commit is contained in:
+309
-437
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
use crate::MutableAppContext;
|
||||
use crate::AppContext;
|
||||
use collections::{BTreeMap, HashMap, HashSet};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
@@ -93,10 +93,10 @@ impl<K: Clone + Hash + Eq + Copy, F> CallbackCollection<K, F> {
|
||||
drop(callbacks);
|
||||
}
|
||||
|
||||
pub fn emit<C: FnMut(&mut F, &mut MutableAppContext) -> bool>(
|
||||
pub fn emit<C: FnMut(&mut F, &mut AppContext) -> bool>(
|
||||
&mut self,
|
||||
key: K,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut AppContext,
|
||||
mut call_callback: C,
|
||||
) {
|
||||
let callbacks = self.internal.lock().callbacks.remove(&key);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Action, App, ForegroundPlatform, MutableAppContext};
|
||||
use crate::{platform::ForegroundPlatform, Action, App, AppContext};
|
||||
|
||||
pub struct Menu<'a> {
|
||||
pub name: &'a str,
|
||||
@@ -51,7 +51,7 @@ pub enum OsAction {
|
||||
Redo,
|
||||
}
|
||||
|
||||
impl MutableAppContext {
|
||||
impl AppContext {
|
||||
pub fn set_menus(&mut self, menus: Vec<Menu>) {
|
||||
self.foreground_platform
|
||||
.set_menus(menus, &self.keystroke_matcher);
|
||||
@@ -77,7 +77,7 @@ pub(crate) fn setup_menu_handlers(foreground_platform: &dyn ForegroundPlatform,
|
||||
let cx = app.0.clone();
|
||||
move |action| {
|
||||
let mut cx = cx.borrow_mut();
|
||||
if let Some(main_window_id) = cx.cx.platform.main_window_id() {
|
||||
if let Some(main_window_id) = cx.platform.main_window_id() {
|
||||
if let Some(view_id) = cx.focused_view_id(main_window_id) {
|
||||
cx.handle_dispatch_action_from_effect(main_window_id, Some(view_id), action);
|
||||
return;
|
||||
|
||||
@@ -17,11 +17,14 @@ use parking_lot::{Mutex, RwLock};
|
||||
use smol::stream::StreamExt;
|
||||
|
||||
use crate::{
|
||||
executor, geometry::vector::Vector2F, keymap_matcher::Keystroke, platform, Action,
|
||||
AnyViewHandle, AppContext, Appearance, Entity, Event, FontCache, Handle, InputHandler,
|
||||
KeyDownEvent, ModelContext, ModelHandle, MutableAppContext, Platform, ReadModelWith,
|
||||
ReadViewWith, RenderContext, Task, UpdateModel, UpdateView, View, ViewContext, ViewHandle,
|
||||
WeakHandle,
|
||||
executor,
|
||||
geometry::vector::Vector2F,
|
||||
keymap_matcher::Keystroke,
|
||||
platform,
|
||||
platform::{Appearance, Event, InputHandler, KeyDownEvent, Platform},
|
||||
Action, AnyViewHandle, AppContext, Entity, FontCache, Handle, ModelContext, ModelHandle,
|
||||
ReadModelWith, ReadViewWith, RenderContext, Task, UpdateModel, UpdateView, View, ViewContext,
|
||||
ViewHandle, WeakHandle,
|
||||
};
|
||||
use collections::BTreeMap;
|
||||
|
||||
@@ -31,7 +34,7 @@ use super::{
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TestAppContext {
|
||||
cx: Rc<RefCell<MutableAppContext>>,
|
||||
cx: Rc<RefCell<AppContext>>,
|
||||
foreground_platform: Rc<platform::test::ForegroundPlatform>,
|
||||
condition_duration: Option<Duration>,
|
||||
pub function_name: String,
|
||||
@@ -49,7 +52,7 @@ impl TestAppContext {
|
||||
first_entity_id: usize,
|
||||
function_name: String,
|
||||
) -> Self {
|
||||
let mut cx = MutableAppContext::new(
|
||||
let mut cx = AppContext::new(
|
||||
foreground,
|
||||
background,
|
||||
platform,
|
||||
@@ -150,15 +153,15 @@ impl TestAppContext {
|
||||
self.cx.borrow().window_ids().collect()
|
||||
}
|
||||
|
||||
pub fn root_view<T: View>(&self, window_id: usize) -> Option<ViewHandle<T>> {
|
||||
pub fn root_view(&self, window_id: usize) -> Option<AnyViewHandle> {
|
||||
self.cx.borrow().root_view(window_id)
|
||||
}
|
||||
|
||||
pub fn read<T, F: FnOnce(&AppContext) -> T>(&self, callback: F) -> T {
|
||||
callback(self.cx.borrow().as_ref())
|
||||
callback(&*self.cx.borrow())
|
||||
}
|
||||
|
||||
pub fn update<T, F: FnOnce(&mut MutableAppContext) -> T>(&mut self, callback: F) -> T {
|
||||
pub fn update<T, F: FnOnce(&mut AppContext) -> T>(&mut self, callback: F) -> T {
|
||||
let mut state = self.cx.borrow_mut();
|
||||
// Don't increment pending flushes in order for effects to be flushed before the callback
|
||||
// completes, which is helpful in tests.
|
||||
@@ -195,7 +198,7 @@ impl TestAppContext {
|
||||
}
|
||||
|
||||
pub fn font_cache(&self) -> Arc<FontCache> {
|
||||
self.cx.borrow().cx.font_cache.clone()
|
||||
self.cx.borrow().font_cache.clone()
|
||||
}
|
||||
|
||||
pub fn foreground_platform(&self) -> Rc<platform::test::ForegroundPlatform> {
|
||||
@@ -203,7 +206,7 @@ impl TestAppContext {
|
||||
}
|
||||
|
||||
pub fn platform(&self) -> Arc<dyn platform::Platform> {
|
||||
self.cx.borrow().cx.platform.clone()
|
||||
self.cx.borrow().platform.clone()
|
||||
}
|
||||
|
||||
pub fn foreground(&self) -> Rc<executor::Foreground> {
|
||||
@@ -397,7 +400,7 @@ impl ReadModelWith for TestAppContext {
|
||||
read: &mut dyn FnMut(&E, &AppContext) -> T,
|
||||
) -> T {
|
||||
let cx = self.cx.borrow();
|
||||
let cx = cx.as_ref();
|
||||
let cx = &*cx;
|
||||
read(handle.read(cx), cx)
|
||||
}
|
||||
}
|
||||
@@ -425,7 +428,7 @@ impl ReadViewWith for TestAppContext {
|
||||
V: View,
|
||||
{
|
||||
let cx = self.cx.borrow();
|
||||
let cx = cx.as_ref();
|
||||
let cx = &*cx;
|
||||
read(handle.read(cx), cx)
|
||||
}
|
||||
}
|
||||
@@ -514,7 +517,7 @@ impl<T: Entity> ModelHandle<T> {
|
||||
loop {
|
||||
{
|
||||
let cx = cx.borrow();
|
||||
let cx = cx.as_ref();
|
||||
let cx = &*cx;
|
||||
if predicate(
|
||||
handle
|
||||
.upgrade(cx)
|
||||
@@ -601,7 +604,7 @@ impl<T: View> ViewHandle<T> {
|
||||
loop {
|
||||
{
|
||||
let cx = cx.borrow();
|
||||
let cx = cx.as_ref();
|
||||
let cx = &*cx;
|
||||
if predicate(
|
||||
handle
|
||||
.upgrade(cx)
|
||||
|
||||
@@ -2,10 +2,10 @@ use std::{cell::RefCell, ops::Range, rc::Rc};
|
||||
|
||||
use pathfinder_geometry::rect::RectF;
|
||||
|
||||
use crate::{AnyView, AppContext, InputHandler, MutableAppContext};
|
||||
use crate::{platform::InputHandler, AnyView, AppContext};
|
||||
|
||||
pub struct WindowInputHandler {
|
||||
pub app: Rc<RefCell<MutableAppContext>>,
|
||||
pub app: Rc<RefCell<AppContext>>,
|
||||
pub window_id: usize,
|
||||
}
|
||||
|
||||
@@ -23,21 +23,21 @@ impl WindowInputHandler {
|
||||
let app = self.app.try_borrow().ok()?;
|
||||
|
||||
let view_id = app.focused_view_id(self.window_id)?;
|
||||
let view = app.cx.views.get(&(self.window_id, view_id))?;
|
||||
let view = app.views.get(&(self.window_id, view_id))?;
|
||||
let result = f(view.as_ref(), &app);
|
||||
Some(result)
|
||||
}
|
||||
|
||||
fn update_focused_view<T, F>(&mut self, f: F) -> Option<T>
|
||||
where
|
||||
F: FnOnce(usize, usize, &mut dyn AnyView, &mut MutableAppContext) -> T,
|
||||
F: FnOnce(usize, usize, &mut dyn AnyView, &mut AppContext) -> T,
|
||||
{
|
||||
let mut app = self.app.try_borrow_mut().ok()?;
|
||||
app.update(|app| {
|
||||
let view_id = app.focused_view_id(self.window_id)?;
|
||||
let mut view = app.cx.views.remove(&(self.window_id, view_id))?;
|
||||
let mut view = app.views.remove(&(self.window_id, view_id))?;
|
||||
let result = f(self.window_id, view_id, view.as_mut(), &mut *app);
|
||||
app.cx.views.insert((self.window_id, view_id), view);
|
||||
app.views.insert((self.window_id, view_id), view);
|
||||
Some(result)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ mod tests {
|
||||
use crate::fonts::{Properties as FontProperties, Weight};
|
||||
|
||||
#[crate::test(self)]
|
||||
fn test_layout_label_with_highlights(cx: &mut crate::MutableAppContext) {
|
||||
fn test_layout_label_with_highlights(cx: &mut crate::AppContext) {
|
||||
let default_style = TextStyle::new(
|
||||
"Menlo",
|
||||
12.,
|
||||
|
||||
@@ -630,7 +630,7 @@ mod tests {
|
||||
use std::env;
|
||||
|
||||
#[crate::test(self)]
|
||||
fn test_layout(cx: &mut crate::MutableAppContext) {
|
||||
fn test_layout(cx: &mut crate::AppContext) {
|
||||
let mut presenter = cx.build_presenter(0, 0., Default::default());
|
||||
let (_, view) = cx.add_window(Default::default(), |_| TestView);
|
||||
let constraint = SizeConstraint::new(vec2f(0., 0.), vec2f(100., 40.));
|
||||
@@ -725,7 +725,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[crate::test(self, iterations = 10, seed = 0)]
|
||||
fn test_random(cx: &mut crate::MutableAppContext, mut rng: StdRng) {
|
||||
fn test_random(cx: &mut crate::AppContext, mut rng: StdRng) {
|
||||
let operations = env::var("OPERATIONS")
|
||||
.map(|i| i.parse().expect("invalid `OPERATIONS` variable"))
|
||||
.unwrap_or(10);
|
||||
|
||||
@@ -5,12 +5,13 @@ use crate::{
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
platform::CursorStyle,
|
||||
platform::MouseButton,
|
||||
scene::{
|
||||
CursorRegion, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseHover,
|
||||
MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut,
|
||||
},
|
||||
DebugContext, Element, ElementBox, EventContext, LayoutContext, MeasurementContext,
|
||||
MouseButton, MouseRegion, MouseState, PaintContext, RenderContext, SizeConstraint, View,
|
||||
MouseRegion, MouseState, PaintContext, RenderContext, SizeConstraint, View,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::{marker::PhantomData, ops::Range};
|
||||
|
||||
@@ -4,8 +4,10 @@ use pathfinder_geometry::vector::{vec2f, Vector2F};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{
|
||||
geometry::rect::RectF, scene::MouseDrag, Axis, CursorStyle, Element, ElementBox,
|
||||
ElementStateHandle, MouseButton, MouseRegion, RenderContext, View,
|
||||
geometry::rect::RectF,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
scene::MouseDrag,
|
||||
Axis, Element, ElementBox, ElementStateHandle, MouseRegion, RenderContext, View,
|
||||
};
|
||||
|
||||
use super::{ConstrainedBox, Hook};
|
||||
|
||||
@@ -271,12 +271,10 @@ pub fn layout_highlighted_chunks<'a>(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
elements::Empty, fonts, ElementBox, Entity, MutableAppContext, RenderContext, View,
|
||||
};
|
||||
use crate::{elements::Empty, fonts, AppContext, ElementBox, Entity, RenderContext, View};
|
||||
|
||||
#[crate::test(self)]
|
||||
fn test_soft_wrapping_with_carriage_returns(cx: &mut MutableAppContext) {
|
||||
fn test_soft_wrapping_with_carriage_returns(cx: &mut AppContext) {
|
||||
let (window_id, _) = cx.add_window(Default::default(), |_| TestView);
|
||||
let mut presenter = cx.build_presenter(window_id, Default::default(), Default::default());
|
||||
fonts::with_font_cache(cx.font_cache().clone(), || {
|
||||
|
||||
@@ -5,9 +5,10 @@ use crate::{
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
json::{self, json},
|
||||
platform::ScrollWheelEvent,
|
||||
presenter::MeasurementContext,
|
||||
scene::MouseScrollWheel,
|
||||
ElementBox, MouseRegion, RenderContext, ScrollWheelEvent, View,
|
||||
ElementBox, MouseRegion, RenderContext, View,
|
||||
};
|
||||
use json::ToJson;
|
||||
use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
platform::{self, Dispatcher},
|
||||
util, MutableAppContext,
|
||||
util, AppContext,
|
||||
};
|
||||
|
||||
pub enum Foreground {
|
||||
@@ -941,7 +941,7 @@ impl<T> Task<T> {
|
||||
}
|
||||
|
||||
impl<T: 'static, E: 'static + Display> Task<Result<T, E>> {
|
||||
pub fn detach_and_log_err(self, cx: &mut MutableAppContext) {
|
||||
pub fn detach_and_log_err(self, cx: &mut AppContext) {
|
||||
cx.spawn(|_| async move {
|
||||
if let Err(err) = self.await {
|
||||
log::error!("{}", err);
|
||||
|
||||
@@ -28,7 +28,6 @@ pub mod json;
|
||||
pub mod keymap_matcher;
|
||||
pub mod platform;
|
||||
pub use gpui_macros::test;
|
||||
pub use platform::*;
|
||||
pub use presenter::{
|
||||
Axis, DebugContext, EventContext, LayoutContext, MeasurementContext, PaintContext,
|
||||
SizeConstraint, Vector2FExt,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::ffi::CStr;
|
||||
|
||||
use crate::platform::Appearance;
|
||||
use cocoa::{
|
||||
appkit::{NSAppearanceNameVibrantDark, NSAppearanceNameVibrantLight},
|
||||
base::id,
|
||||
@@ -7,8 +8,6 @@ use cocoa::{
|
||||
};
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
|
||||
use crate::Appearance;
|
||||
|
||||
impl Appearance {
|
||||
pub unsafe fn from_native(appearance: id) -> Self {
|
||||
let name: id = msg_send![appearance, name];
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use crate::{
|
||||
geometry::vector::vec2f,
|
||||
keymap_matcher::Keystroke,
|
||||
platform::{Event, NavigationDirection},
|
||||
KeyDownEvent, KeyUpEvent, Modifiers, ModifiersChangedEvent, MouseButton, MouseButtonEvent,
|
||||
MouseExitedEvent, MouseMovedEvent, ScrollDelta, ScrollWheelEvent, TouchPhase,
|
||||
platform::{
|
||||
Event, KeyDownEvent, KeyUpEvent, Modifiers, ModifiersChangedEvent, MouseButton,
|
||||
MouseButtonEvent, MouseExitedEvent, MouseMovedEvent, NavigationDirection, ScrollDelta,
|
||||
ScrollWheelEvent, TouchPhase,
|
||||
},
|
||||
};
|
||||
use cocoa::{
|
||||
appkit::{NSEvent, NSEventModifierFlags, NSEventPhase, NSEventType},
|
||||
|
||||
@@ -498,12 +498,12 @@ extern "C" {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::MutableAppContext;
|
||||
use crate::AppContext;
|
||||
use font_kit::properties::{Style, Weight};
|
||||
use platform::FontSystem as _;
|
||||
|
||||
#[crate::test(self, retries = 5)]
|
||||
fn test_layout_str(_: &mut MutableAppContext) {
|
||||
fn test_layout_str(_: &mut AppContext) {
|
||||
// This is failing intermittently on CI and we don't have time to figure it out
|
||||
let fonts = FontSystem::new();
|
||||
let menlo = fonts.load_family("Menlo", &Default::default()).unwrap();
|
||||
|
||||
@@ -2,9 +2,9 @@ use super::atlas::{AllocId, AtlasAllocator};
|
||||
use crate::{
|
||||
fonts::{FontId, GlyphId},
|
||||
geometry::{rect::RectI, vector::Vector2I},
|
||||
platform::RasterizationOptions,
|
||||
platform::{FontSystem, RasterizationOptions},
|
||||
scene::ImageGlyph,
|
||||
FontSystem, ImageData,
|
||||
ImageData,
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use metal::{MTLPixelFormat, TextureDescriptor, TextureRef};
|
||||
|
||||
@@ -5,8 +5,8 @@ use super::{
|
||||
use crate::{
|
||||
executor,
|
||||
keymap_matcher::KeymapMatcher,
|
||||
platform::{self, CursorStyle},
|
||||
Action, AppVersion, ClipboardItem, Event, Menu, MenuItem,
|
||||
platform::{self, AppVersion, CursorStyle, Event},
|
||||
Action, ClipboardItem, Menu, MenuItem,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use block::ConcreteBlock;
|
||||
@@ -150,7 +150,7 @@ pub struct MacForegroundPlatformState {
|
||||
resign_active: Option<Box<dyn FnMut()>>,
|
||||
reopen: Option<Box<dyn FnMut()>>,
|
||||
quit: Option<Box<dyn FnMut()>>,
|
||||
event: Option<Box<dyn FnMut(crate::Event) -> bool>>,
|
||||
event: Option<Box<dyn FnMut(platform::Event) -> bool>>,
|
||||
menu_command: Option<Box<dyn FnMut(&dyn Action)>>,
|
||||
validate_menu_command: Option<Box<dyn FnMut(&dyn Action) -> bool>>,
|
||||
will_open_menu: Option<Box<dyn FnMut()>>,
|
||||
@@ -342,7 +342,7 @@ impl platform::ForegroundPlatform for MacForegroundPlatform {
|
||||
self.0.borrow_mut().reopen = Some(callback);
|
||||
}
|
||||
|
||||
fn on_event(&self, callback: Box<dyn FnMut(crate::Event) -> bool>) {
|
||||
fn on_event(&self, callback: Box<dyn FnMut(platform::Event) -> bool>) {
|
||||
self.0.borrow_mut().event = Some(callback);
|
||||
}
|
||||
|
||||
@@ -577,7 +577,7 @@ impl platform::Platform for MacPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
fn screen_by_id(&self, id: uuid::Uuid) -> Option<Rc<dyn crate::Screen>> {
|
||||
fn screen_by_id(&self, id: uuid::Uuid) -> Option<Rc<dyn platform::Screen>> {
|
||||
Screen::find_by_id(id).map(|screen| Rc::new(screen) as Rc<_>)
|
||||
}
|
||||
|
||||
@@ -864,7 +864,7 @@ impl platform::Platform for MacPlatform {
|
||||
"macOS"
|
||||
}
|
||||
|
||||
fn os_version(&self) -> Result<crate::AppVersion> {
|
||||
fn os_version(&self) -> Result<crate::platform::AppVersion> {
|
||||
unsafe {
|
||||
let process_info = NSProcessInfo::processInfo(nil);
|
||||
let version = process_info.operatingSystemVersion();
|
||||
|
||||
@@ -6,8 +6,9 @@ use crate::{
|
||||
platform::{
|
||||
self,
|
||||
mac::{platform::NSViewLayerContentsRedrawDuringViewResize, renderer::Renderer},
|
||||
Event, FontSystem, WindowBounds,
|
||||
},
|
||||
Event, FontSystem, Scene, WindowBounds,
|
||||
Scene,
|
||||
};
|
||||
use cocoa::{
|
||||
appkit::{NSScreen, NSSquareStatusItemLength, NSStatusBar, NSStatusItem, NSView, NSWindow},
|
||||
@@ -185,15 +186,15 @@ impl platform::Window for StatusItem {
|
||||
0.
|
||||
}
|
||||
|
||||
fn appearance(&self) -> crate::Appearance {
|
||||
fn appearance(&self) -> platform::Appearance {
|
||||
unsafe {
|
||||
let appearance: id =
|
||||
msg_send![self.0.borrow().native_item.button(), effectiveAppearance];
|
||||
crate::Appearance::from_native(appearance)
|
||||
platform::Appearance::from_native(appearance)
|
||||
}
|
||||
}
|
||||
|
||||
fn screen(&self) -> Rc<dyn crate::Screen> {
|
||||
fn screen(&self) -> Rc<dyn platform::Screen> {
|
||||
unsafe {
|
||||
Rc::new(Screen {
|
||||
native_screen: self.0.borrow().native_window().screen(),
|
||||
@@ -205,11 +206,11 @@ impl platform::Window for StatusItem {
|
||||
self
|
||||
}
|
||||
|
||||
fn set_input_handler(&mut self, _: Box<dyn crate::InputHandler>) {}
|
||||
fn set_input_handler(&mut self, _: Box<dyn platform::InputHandler>) {}
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_: crate::PromptLevel,
|
||||
_: crate::platform::PromptLevel,
|
||||
_: &str,
|
||||
_: &[&str],
|
||||
) -> postage::oneshot::Receiver<usize> {
|
||||
@@ -251,7 +252,7 @@ impl platform::Window for StatusItem {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event) -> bool>) {
|
||||
fn on_event(&mut self, callback: Box<dyn FnMut(platform::Event) -> bool>) {
|
||||
self.0.borrow_mut().event_callback = Some(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ use crate::{
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
keymap_matcher::Keystroke,
|
||||
mac::platform::NSViewLayerContentsRedrawDuringViewResize,
|
||||
platform::{
|
||||
self,
|
||||
mac::{renderer::Renderer, screen::Screen},
|
||||
Event, WindowBounds,
|
||||
mac::{
|
||||
platform::NSViewLayerContentsRedrawDuringViewResize, renderer::Renderer, screen::Screen,
|
||||
},
|
||||
Event, InputHandler, KeyDownEvent, ModifiersChangedEvent, MouseButton, MouseButtonEvent,
|
||||
MouseMovedEvent, Scene, WindowBounds, WindowKind,
|
||||
},
|
||||
InputHandler, KeyDownEvent, ModifiersChangedEvent, MouseButton, MouseButtonEvent,
|
||||
MouseMovedEvent, Scene, WindowKind,
|
||||
};
|
||||
use block::ConcreteBlock;
|
||||
use cocoa::{
|
||||
@@ -670,14 +670,14 @@ impl platform::Window for Window {
|
||||
self.0.as_ref().borrow().titlebar_height()
|
||||
}
|
||||
|
||||
fn appearance(&self) -> crate::Appearance {
|
||||
fn appearance(&self) -> platform::Appearance {
|
||||
unsafe {
|
||||
let appearance: id = msg_send![self.0.borrow().native_window, effectiveAppearance];
|
||||
crate::Appearance::from_native(appearance)
|
||||
platform::Appearance::from_native(appearance)
|
||||
}
|
||||
}
|
||||
|
||||
fn screen(&self) -> Rc<dyn crate::Screen> {
|
||||
fn screen(&self) -> Rc<dyn platform::Screen> {
|
||||
unsafe {
|
||||
Rc::new(Screen {
|
||||
native_screen: self.0.as_ref().borrow().native_window.screen(),
|
||||
|
||||
@@ -64,7 +64,7 @@ impl super::ForegroundPlatform for ForegroundPlatform {
|
||||
fn on_resign_active(&self, _: Box<dyn FnMut()>) {}
|
||||
fn on_quit(&self, _: Box<dyn FnMut()>) {}
|
||||
fn on_reopen(&self, _: Box<dyn FnMut()>) {}
|
||||
fn on_event(&self, _: Box<dyn FnMut(crate::Event) -> bool>) {}
|
||||
fn on_event(&self, _: Box<dyn FnMut(crate::platform::Event) -> bool>) {}
|
||||
fn on_open_urls(&self, _: Box<dyn FnMut(Vec<String>)>) {}
|
||||
|
||||
fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {
|
||||
@@ -134,11 +134,11 @@ impl super::Platform for Platform {
|
||||
|
||||
fn quit(&self) {}
|
||||
|
||||
fn screen_by_id(&self, _id: uuid::Uuid) -> Option<Rc<dyn crate::Screen>> {
|
||||
fn screen_by_id(&self, _id: uuid::Uuid) -> Option<Rc<dyn crate::platform::Screen>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn screens(&self) -> Vec<Rc<dyn crate::Screen>> {
|
||||
fn screens(&self) -> Vec<Rc<dyn crate::platform::Screen>> {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ impl super::Platform for Platform {
|
||||
None
|
||||
}
|
||||
|
||||
fn add_status_item(&self) -> Box<dyn crate::Window> {
|
||||
fn add_status_item(&self) -> Box<dyn crate::platform::Window> {
|
||||
Box::new(Window::new(vec2f(24., 24.)))
|
||||
}
|
||||
|
||||
@@ -301,11 +301,11 @@ impl super::Window for Window {
|
||||
24.
|
||||
}
|
||||
|
||||
fn appearance(&self) -> crate::Appearance {
|
||||
crate::Appearance::Light
|
||||
fn appearance(&self) -> crate::platform::Appearance {
|
||||
crate::platform::Appearance::Light
|
||||
}
|
||||
|
||||
fn screen(&self) -> Rc<dyn crate::Screen> {
|
||||
fn screen(&self) -> Rc<dyn crate::platform::Screen> {
|
||||
Rc::new(Screen)
|
||||
}
|
||||
|
||||
@@ -313,9 +313,14 @@ impl super::Window for Window {
|
||||
self
|
||||
}
|
||||
|
||||
fn set_input_handler(&mut self, _: Box<dyn crate::InputHandler>) {}
|
||||
fn set_input_handler(&mut self, _: Box<dyn crate::platform::InputHandler>) {}
|
||||
|
||||
fn prompt(&self, _: crate::PromptLevel, _: &str, _: &[&str]) -> oneshot::Receiver<usize> {
|
||||
fn prompt(
|
||||
&self,
|
||||
_: crate::platform::PromptLevel,
|
||||
_: &str,
|
||||
_: &[&str],
|
||||
) -> oneshot::Receiver<usize> {
|
||||
let (done_tx, done_rx) = oneshot::channel();
|
||||
self.pending_prompts.borrow_mut().push_back(done_tx);
|
||||
done_rx
|
||||
@@ -343,7 +348,7 @@ impl super::Window for Window {
|
||||
|
||||
fn toggle_full_screen(&self) {}
|
||||
|
||||
fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event) -> bool>) {
|
||||
fn on_event(&mut self, callback: Box<dyn FnMut(crate::platform::Event) -> bool>) {
|
||||
self.event_handlers.push(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
use crate::{
|
||||
app::{AppContext, MutableAppContext, WindowInvalidation},
|
||||
app::WindowInvalidation,
|
||||
elements::Element,
|
||||
font_cache::FontCache,
|
||||
geometry::rect::RectF,
|
||||
json::{self, ToJson},
|
||||
platform::{CursorStyle, Event},
|
||||
platform::{Appearance, CursorStyle, Event, FontSystem, MouseButton, MouseMovedEvent},
|
||||
scene::{
|
||||
CursorRegion, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseEvent, MouseHover,
|
||||
MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut, Scene,
|
||||
},
|
||||
text_layout::TextLayoutCache,
|
||||
Action, AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, Appearance,
|
||||
AssetCache, ElementBox, Entity, FontSystem, ModelHandle, MouseButton, MouseMovedEvent,
|
||||
MouseRegion, MouseRegionId, MouseState, ParentId, ReadModel, ReadView, RenderContext,
|
||||
RenderParams, SceneBuilder, UpgradeModelHandle, UpgradeViewHandle, View, ViewHandle,
|
||||
WeakModelHandle, WeakViewHandle,
|
||||
Action, AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext,
|
||||
AssetCache, ElementBox, Entity, ModelHandle, MouseRegion, MouseRegionId, MouseState, ParentId,
|
||||
ReadModel, ReadView, RenderContext, RenderParams, SceneBuilder, UpgradeModelHandle,
|
||||
UpgradeViewHandle, View, ViewHandle, WeakModelHandle, WeakViewHandle,
|
||||
};
|
||||
use anyhow::bail;
|
||||
use collections::{HashMap, HashSet};
|
||||
@@ -56,7 +55,7 @@ impl Presenter {
|
||||
font_cache: Arc<FontCache>,
|
||||
text_layout_cache: TextLayoutCache,
|
||||
asset_cache: Arc<AssetCache>,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut AppContext,
|
||||
) -> Self {
|
||||
Self {
|
||||
window_id,
|
||||
@@ -80,7 +79,7 @@ impl Presenter {
|
||||
&mut self,
|
||||
invalidation: &mut WindowInvalidation,
|
||||
appearance: Appearance,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut AppContext,
|
||||
) {
|
||||
cx.start_frame();
|
||||
self.appearance = appearance;
|
||||
@@ -111,7 +110,7 @@ impl Presenter {
|
||||
&mut self,
|
||||
invalidation: &mut WindowInvalidation,
|
||||
appearance: Appearance,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut AppContext,
|
||||
) {
|
||||
self.invalidate(invalidation, appearance, cx);
|
||||
for (view_id, view) in &mut self.rendered_views {
|
||||
@@ -138,7 +137,7 @@ impl Presenter {
|
||||
window_size: Vector2F,
|
||||
scale_factor: f32,
|
||||
refreshing: bool,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut AppContext,
|
||||
) -> Scene {
|
||||
let mut scene_builder = SceneBuilder::new(scale_factor);
|
||||
|
||||
@@ -169,7 +168,7 @@ impl Presenter {
|
||||
}
|
||||
}
|
||||
|
||||
fn layout(&mut self, window_size: Vector2F, refreshing: bool, cx: &mut MutableAppContext) {
|
||||
fn layout(&mut self, window_size: Vector2F, refreshing: bool, cx: &mut AppContext) {
|
||||
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
||||
self.build_layout_context(window_size, refreshing, cx)
|
||||
.layout(root_view_id, SizeConstraint::strict(window_size));
|
||||
@@ -180,7 +179,7 @@ impl Presenter {
|
||||
&'a mut self,
|
||||
window_size: Vector2F,
|
||||
refreshing: bool,
|
||||
cx: &'a mut MutableAppContext,
|
||||
cx: &'a mut AppContext,
|
||||
) -> LayoutContext<'a> {
|
||||
LayoutContext {
|
||||
window_id: self.window_id,
|
||||
@@ -206,7 +205,7 @@ impl Presenter {
|
||||
&'a mut self,
|
||||
scene: &'a mut SceneBuilder,
|
||||
window_size: Vector2F,
|
||||
cx: &'a mut MutableAppContext,
|
||||
cx: &'a mut AppContext,
|
||||
) -> PaintContext {
|
||||
PaintContext {
|
||||
scene,
|
||||
@@ -234,7 +233,7 @@ impl Presenter {
|
||||
&mut self,
|
||||
event: Event,
|
||||
event_reused: bool,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut AppContext,
|
||||
) -> bool {
|
||||
let mut mouse_events = SmallVec::<[_; 2]>::new();
|
||||
let mut notified_views: HashSet<usize> = Default::default();
|
||||
@@ -557,7 +556,7 @@ impl Presenter {
|
||||
pub fn build_event_context<'a>(
|
||||
&'a mut self,
|
||||
notified_views: &'a mut HashSet<usize>,
|
||||
cx: &'a mut MutableAppContext,
|
||||
cx: &'a mut AppContext,
|
||||
) -> EventContext<'a> {
|
||||
EventContext {
|
||||
font_cache: &self.font_cache,
|
||||
@@ -595,7 +594,7 @@ pub struct LayoutContext<'a> {
|
||||
pub font_system: Arc<dyn FontSystem>,
|
||||
pub text_layout_cache: &'a TextLayoutCache,
|
||||
pub asset_cache: &'a AssetCache,
|
||||
pub app: &'a mut MutableAppContext,
|
||||
pub app: &'a mut AppContext,
|
||||
pub refreshing: bool,
|
||||
pub window_size: Vector2F,
|
||||
titlebar_height: f32,
|
||||
@@ -692,7 +691,7 @@ impl<'a> LayoutContext<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Deref for LayoutContext<'a> {
|
||||
type Target = MutableAppContext;
|
||||
type Target = AppContext;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.app
|
||||
@@ -804,7 +803,7 @@ impl<'a> Deref for PaintContext<'a> {
|
||||
pub struct EventContext<'a> {
|
||||
pub font_cache: &'a FontCache,
|
||||
pub text_layout_cache: &'a TextLayoutCache,
|
||||
pub app: &'a mut MutableAppContext,
|
||||
pub app: &'a mut AppContext,
|
||||
pub window_id: usize,
|
||||
pub notify_count: usize,
|
||||
view_stack: Vec<usize>,
|
||||
@@ -871,7 +870,7 @@ impl<'a> EventContext<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Deref for EventContext<'a> {
|
||||
type Target = MutableAppContext;
|
||||
type Target = AppContext;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.app
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use crate::{
|
||||
platform::{MouseButtonEvent, MouseMovedEvent, ScrollWheelEvent},
|
||||
scene::mouse_region::HandlerKey,
|
||||
};
|
||||
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
|
||||
use std::{
|
||||
mem::{discriminant, Discriminant},
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
|
||||
|
||||
use crate::{scene::mouse_region::HandlerKey, MouseButtonEvent, MouseMovedEvent, ScrollWheelEvent};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct MouseMove {
|
||||
pub region: RectF,
|
||||
|
||||
@@ -5,7 +5,7 @@ use collections::HashMap;
|
||||
use pathfinder_geometry::rect::RectF;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{EventContext, MouseButton};
|
||||
use crate::{platform::MouseButton, EventContext};
|
||||
|
||||
use super::{
|
||||
mouse_event::{
|
||||
@@ -290,7 +290,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Move, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Move, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -307,7 +307,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::MoveOut, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::MoveOut, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -325,7 +325,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Down, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Down, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -343,7 +343,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Up, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Up, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -361,7 +361,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Click, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Click, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -379,7 +379,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::DownOut, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::DownOut, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -397,7 +397,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::UpOut, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::UpOut, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -415,7 +415,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Drag, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Drag, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
@@ -429,7 +429,7 @@ impl HandlerSet {
|
||||
handler(e, cx);
|
||||
} else {
|
||||
panic!(
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Hover, found {:?}",
|
||||
"Mouse Region Event incorrectly called with mismatched event type. Expected MouseRegionEvent::Hover, found {:?}",
|
||||
region_event);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -17,9 +17,10 @@ use crate::{
|
||||
elements::Empty,
|
||||
executor::{self, ExecutorEvent},
|
||||
platform,
|
||||
platform::Platform,
|
||||
util::CwdBacktrace,
|
||||
Element, ElementBox, Entity, FontCache, Handle, MutableAppContext, Platform, RenderContext,
|
||||
Subscription, TestAppContext, View,
|
||||
AppContext, Element, ElementBox, Entity, FontCache, Handle, RenderContext, Subscription,
|
||||
TestAppContext, View,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -40,7 +41,7 @@ pub fn run_test(
|
||||
detect_nondeterminism: bool,
|
||||
test_fn: &mut (dyn RefUnwindSafe
|
||||
+ Fn(
|
||||
&mut MutableAppContext,
|
||||
&mut AppContext,
|
||||
Rc<platform::test::ForegroundPlatform>,
|
||||
Arc<executor::Deterministic>,
|
||||
u64,
|
||||
|
||||
@@ -5,7 +5,9 @@ use crate::{
|
||||
rect::RectF,
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
platform, scene, FontSystem, PaintContext,
|
||||
platform,
|
||||
platform::FontSystem,
|
||||
scene, PaintContext,
|
||||
};
|
||||
use ordered_float::OrderedFloat;
|
||||
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
|
||||
@@ -660,7 +662,7 @@ mod tests {
|
||||
use crate::fonts::{Properties, Weight};
|
||||
|
||||
#[crate::test(self)]
|
||||
fn test_wrap_line(cx: &mut crate::MutableAppContext) {
|
||||
fn test_wrap_line(cx: &mut crate::AppContext) {
|
||||
let font_cache = cx.font_cache().clone();
|
||||
let font_system = cx.platform().fonts();
|
||||
let family = font_cache
|
||||
@@ -721,7 +723,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[crate::test(self, retries = 5)]
|
||||
fn test_wrap_shaped_line(cx: &mut crate::MutableAppContext) {
|
||||
fn test_wrap_shaped_line(cx: &mut crate::AppContext) {
|
||||
// This is failing intermittently on CI and we don't have time to figure it out
|
||||
let font_cache = cx.font_cache().clone();
|
||||
let font_system = cx.platform().fonts();
|
||||
|
||||
@@ -2,6 +2,6 @@ mod select;
|
||||
|
||||
pub use select::{ItemType, Select, SelectStyle};
|
||||
|
||||
pub fn init(cx: &mut super::MutableAppContext) {
|
||||
pub fn init(cx: &mut super::AppContext) {
|
||||
select::init(cx);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
actions, elements::*, impl_actions, AppContext, Entity, MouseButton, MutableAppContext,
|
||||
RenderContext, View, ViewContext, WeakViewHandle,
|
||||
actions, elements::*, impl_actions, platform::MouseButton, AppContext, Entity, RenderContext,
|
||||
View, ViewContext, WeakViewHandle,
|
||||
};
|
||||
|
||||
pub struct Select {
|
||||
@@ -12,7 +12,7 @@ pub struct Select {
|
||||
item_count: usize,
|
||||
is_open: bool,
|
||||
list_state: UniformListState,
|
||||
build_style: Option<Box<dyn FnMut(&mut MutableAppContext) -> SelectStyle>>,
|
||||
build_style: Option<Box<dyn FnMut(&mut AppContext) -> SelectStyle>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
@@ -35,7 +35,7 @@ impl_actions!(select, [SelectItem]);
|
||||
|
||||
pub enum Event {}
|
||||
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_action(Select::toggle);
|
||||
cx.add_action(Select::select_item);
|
||||
}
|
||||
@@ -57,10 +57,7 @@ impl Select {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_style(
|
||||
mut self,
|
||||
f: impl 'static + FnMut(&mut MutableAppContext) -> SelectStyle,
|
||||
) -> Self {
|
||||
pub fn with_style(mut self, f: impl 'static + FnMut(&mut AppContext) -> SelectStyle) -> Self {
|
||||
self.build_style = Some(Box::new(f));
|
||||
self
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user