This commit is contained in:
Nathan Sobo
2023-09-19 08:46:02 -06:00
parent df9a05ba92
commit 89519b1521
6 changed files with 79 additions and 5 deletions
+9 -2
View File
@@ -1,13 +1,15 @@
use anyhow::{anyhow, Result};
use slotmap::SlotMap;
use std::{any::Any, marker::PhantomData};
use std::{any::Any, marker::PhantomData, rc::Rc};
use super::{
platform::Platform,
window::{Window, WindowHandle, WindowId},
Context, LayoutId, Reference, View, WindowContext,
};
pub struct AppContext {
platform: Rc<dyn Platform>,
pub(crate) entities: SlotMap<EntityId, Option<Box<dyn Any>>>,
pub(crate) windows: SlotMap<WindowId, Option<Window>>,
// We recycle this memory across layout requests.
@@ -15,14 +17,19 @@ pub struct AppContext {
}
impl AppContext {
pub fn new() -> Self {
pub fn new(platform: Rc<dyn Platform>) -> Self {
AppContext {
platform,
entities: SlotMap::with_key(),
windows: SlotMap::with_key(),
layout_id_buffer: Default::default(),
}
}
pub fn test() -> Self {
Self::new(TestPlatform::new())
}
pub fn open_window<S: 'static>(
&mut self,
build_root_view: impl FnOnce(&mut WindowContext) -> View<S>,
+2 -2
View File
@@ -31,7 +31,7 @@ unsafe impl<T: Clone + Debug + Zeroable + Pod> Zeroable for Point<T> {}
unsafe impl<T: Clone + Debug + Zeroable + Pod> Pod for Point<T> {}
#[derive(Refineable, Default, Clone, Copy, Debug)]
#[derive(Refineable, Default, Clone, Copy, Debug, PartialEq)]
#[refineable(debug)]
pub struct Size<T: Clone + Debug> {
pub width: T,
@@ -65,7 +65,7 @@ impl Size<Length> {
}
}
#[derive(Refineable, Clone, Default, Debug)]
#[derive(Refineable, Clone, Default, Debug, PartialEq)]
#[refineable(debug)]
pub struct Bounds<T: Clone + Debug> {
pub origin: Point<T>,
+1
View File
@@ -3,6 +3,7 @@ mod color;
mod element;
mod elements;
mod geometry;
mod platform;
mod renderer;
mod scene;
mod style;
+58
View File
@@ -0,0 +1,58 @@
mod test;
use super::{AnyWindowHandle, Bounds, Point};
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
pub trait Platform {
fn open_window(
&self,
handle: AnyWindowHandle,
options: WindowOptions,
) -> Box<dyn PlatformWindow>;
}
pub trait PlatformWindow: HasRawWindowHandle + HasRawDisplayHandle {}
#[derive(Debug)]
pub struct WindowOptions<'a> {
pub bounds: WindowBounds,
pub titlebar: Option<TitlebarOptions<'a>>,
pub center: bool,
pub focus: bool,
pub show: bool,
pub kind: WindowKind,
pub is_movable: bool,
}
#[derive(Debug, Default)]
pub struct TitlebarOptions<'a> {
pub title: Option<&'a str>,
pub appears_transparent: bool,
pub traffic_light_position: Option<Point<f32>>,
}
#[derive(Copy, Clone, Debug)]
pub enum Appearance {
Light,
VibrantLight,
Dark,
VibrantDark,
}
impl Default for Appearance {
fn default() -> Self {
Self::Light
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum WindowKind {
Normal,
PopUp,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum WindowBounds {
Fullscreen,
Maximized,
Fixed(Bounds<f32>),
}
+9 -1
View File
@@ -5,7 +5,10 @@ use super::{
use anyhow::Result;
use derive_more::{Deref, DerefMut};
use gpui2::Reference;
use std::{any::Any, marker::PhantomData};
use std::{
any::{Any, TypeId},
marker::PhantomData,
};
pub struct AnyWindow {}
@@ -216,6 +219,11 @@ impl<S> WindowHandle<S> {
}
}
pub struct AnyWindowHandle {
id: WindowId,
state_type: TypeId,
}
#[derive(Clone)]
pub struct Layout {
pub order: u32,