Merge branch 'marshall/merge-main-into-gpui2' into marshall/gpui2-playground

This commit is contained in:
Marshall Bowers
2023-10-06 16:47:40 -04:00
9 changed files with 325 additions and 439 deletions
Generated
+285 -335
View File
File diff suppressed because it is too large Load Diff
+36 -38
View File
@@ -1,12 +1,12 @@
use std::fmt::Debug;
use super::scene::{Path, PathVertex};
use crate::{color::Color, json::ToJson};
use derive_more::Neg;
pub use pathfinder_geometry::*;
use rect::RectF;
use refineable::Refineable;
use serde::{Deserialize, Deserializer};
use serde_json::json;
use std::fmt::Debug;
use vector::{vec2f, Vector2F};
pub struct PathBuilder {
@@ -167,15 +167,6 @@ pub struct Size<T: Clone + Default + Debug> {
pub height: T,
}
impl Size<Length> {
pub fn full() -> Self {
Self {
width: relative(1.),
height: relative(1.),
}
}
}
impl<S, T: Clone + Default + Debug> From<taffy::geometry::Size<S>> for Size<T>
where
S: Into<T>,
@@ -203,8 +194,8 @@ where
impl Size<DefiniteLength> {
pub fn zero() -> Self {
Self {
width: px(0.),
height: px(0.),
width: pixels(0.).into(),
height: pixels(0.).into(),
}
}
@@ -244,6 +235,17 @@ pub struct Edges<T: Clone + Default + Debug> {
pub left: T,
}
impl<T: Clone + Default + Debug> Edges<T> {
pub fn uniform(value: T) -> Self {
Self {
top: value.clone(),
right: value.clone(),
bottom: value.clone(),
left: value.clone(),
}
}
}
impl Edges<Length> {
pub fn auto() -> Self {
Self {
@@ -256,10 +258,10 @@ impl Edges<Length> {
pub fn zero() -> Self {
Self {
top: px(0.),
right: px(0.),
bottom: px(0.),
left: px(0.),
top: pixels(0.).into(),
right: pixels(0.).into(),
bottom: pixels(0.).into(),
left: pixels(0.).into(),
}
}
@@ -279,10 +281,10 @@ impl Edges<Length> {
impl Edges<DefiniteLength> {
pub fn zero() -> Self {
Self {
top: px(0.),
right: px(0.),
bottom: px(0.),
left: px(0.),
top: pixels(0.).into(),
right: pixels(0.).into(),
bottom: pixels(0.).into(),
left: pixels(0.).into(),
}
}
@@ -299,10 +301,10 @@ impl Edges<DefiniteLength> {
impl Edges<AbsoluteLength> {
pub fn zero() -> Self {
Self {
top: px(0.),
right: px(0.),
bottom: px(0.),
left: px(0.),
top: pixels(0.),
right: pixels(0.),
bottom: pixels(0.),
left: pixels(0.),
}
}
@@ -331,7 +333,7 @@ impl Edges<f32> {
}
}
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Neg)]
pub enum AbsoluteLength {
Pixels(f32),
Rems(f32),
@@ -369,7 +371,7 @@ impl Default for AbsoluteLength {
}
/// A non-auto length that can be defined in pixels, rems, or percent of parent.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Neg)]
pub enum DefiniteLength {
Absolute(AbsoluteLength),
Relative(f32), // 0. to 1.
@@ -413,7 +415,7 @@ impl Default for DefiniteLength {
}
/// A length that can be defined in pixels, rems, percent of parent, or auto.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Neg)]
pub enum Length {
Definite(DefiniteLength),
Auto,
@@ -428,20 +430,16 @@ impl std::fmt::Debug for Length {
}
}
pub fn relative<T: From<DefiniteLength>>(fraction: f32) -> T {
DefiniteLength::Relative(fraction).into()
pub fn relative(fraction: f32) -> DefiniteLength {
DefiniteLength::Relative(fraction)
}
pub fn rems<T: From<AbsoluteLength>>(rems: f32) -> T {
AbsoluteLength::Rems(rems).into()
pub fn rems(rems: f32) -> AbsoluteLength {
AbsoluteLength::Rems(rems)
}
pub fn px<T: From<AbsoluteLength>>(pixels: f32) -> T {
AbsoluteLength::Pixels(pixels).into()
}
pub fn pixels<T: From<AbsoluteLength>>(pixels: f32) -> T {
AbsoluteLength::Pixels(pixels).into()
pub fn pixels(pixels: f32) -> AbsoluteLength {
AbsoluteLength::Pixels(pixels)
}
pub fn auto() -> Length {
-9
View File
@@ -160,15 +160,6 @@ pub fn black() -> Hsla {
}
}
pub fn white() -> Hsla {
Hsla {
h: 0.,
s: 0.,
l: 1.,
a: 1.,
}
}
impl From<Rgba> for Hsla {
fn from(color: Rgba) -> Self {
let r = color.r;
+2 -12
View File
@@ -12,21 +12,11 @@ use parking_lot::Mutex;
use std::sync::Arc;
use util::arc_cow::ArcCow;
impl<V: 'static> IntoElement<V> for ArcCow<'static, str> {
impl<V: 'static, S: Into<ArcCow<'static, str>>> IntoElement<V> for S {
type Element = Text;
fn into_element(self) -> Self::Element {
Text { text: self }
}
}
impl<V: 'static> IntoElement<V> for &'static str {
type Element = Text;
fn into_element(self) -> Self::Element {
Text {
text: ArcCow::from(self),
}
Text { text: self.into() }
}
}
-1
View File
@@ -6,7 +6,6 @@ pub mod interactive;
pub mod style;
pub mod view;
pub mod view_context;
pub mod view_handle;
pub use color::*;
pub use element::{AnyElement, Element, IntoElement, Layout, ParentElement};
+1 -3
View File
@@ -22,8 +22,6 @@ use gpui2_macros::styleable_helpers;
use refineable::{Refineable, RefinementCascade};
use std::sync::Arc;
pub type StyleCascade = RefinementCascade<Style>;
#[derive(Clone, Refineable, Debug)]
#[refineable(debug)]
pub struct Style {
@@ -131,7 +129,7 @@ impl Style {
color: self.text_color.map(Into::into),
font_family: self.font_family.clone(),
font_size: self.font_size.map(|size| size * cx.rem_size()),
font_weight: self.font_weight.map(Into::into),
font_weight: self.font_weight,
font_style: self.font_style,
underline: None,
})
+1 -36
View File
@@ -3,10 +3,7 @@ use std::{any::TypeId, rc::Rc};
use crate::{element::LayoutId, style::Style};
use anyhow::{anyhow, Result};
use derive_more::{Deref, DerefMut};
use gpui::{
geometry::Size, scene::EventHandler, AnyWindowHandle, BorrowWindowContext, EventContext,
Layout, MeasureParams, WindowContext,
};
use gpui::{geometry::Size, scene::EventHandler, EventContext, Layout, MeasureParams};
pub use gpui::{taffy::tree::NodeId, ViewContext as LegacyViewContext};
#[derive(Deref, DerefMut)]
@@ -80,35 +77,3 @@ impl<'a, 'b, 'c, V: 'static> ViewContext<'a, 'b, 'c, V> {
.computed_layout(layout_id)
}
}
impl<'a, 'b, 'c, V: 'static> BorrowWindowContext for ViewContext<'a, 'b, 'c, V> {
type Result<T> = T;
fn read_window<T, F>(&self, window: AnyWindowHandle, f: F) -> Self::Result<T>
where
F: FnOnce(&WindowContext) -> T,
{
self.legacy_cx.read_window(window, f)
}
fn read_window_optional<T, F>(&self, window: AnyWindowHandle, f: F) -> Option<T>
where
F: FnOnce(&WindowContext) -> Option<T>,
{
self.legacy_cx.read_window_optional(window, f)
}
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Self::Result<T>
where
F: FnOnce(&mut WindowContext) -> T,
{
self.legacy_cx.update_window(window, f)
}
fn update_window_optional<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Option<T>
where
F: FnOnce(&mut WindowContext) -> Option<T>,
{
self.legacy_cx.update_window_optional(window, f)
}
}
-4
View File
@@ -8,9 +8,6 @@ publish = false
name = "storybook"
path = "src/storybook.rs"
[features]
test-support = []
[dependencies]
anyhow.workspace = true
clap = { version = "4.4", features = ["derive", "string"] }
@@ -21,7 +18,6 @@ futures.workspace = true
gpui2 = { path = "../gpui2" }
itertools = "0.11.0"
log.workspace = true
refineable = { path = "../refineable" }
rust-embed.workspace = true
serde.workspace = true
settings = { path = "../settings" }
-1
View File
@@ -139,7 +139,6 @@ tree-sitter-nu.workspace = true
url = "2.2"
urlencoding = "2.1.2"
uuid.workspace = true
owning_ref = "0.4.1"
[dev-dependencies]
call = { path = "../call", features = ["test-support"] }