Merge branch 'gpui2' into marshall/gpui2-playground
This commit is contained in:
@@ -3607,7 +3607,7 @@ impl<V> BorrowWindowContext for EventContext<'_, '_, '_, V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum Reference<'a, T> {
|
||||
pub enum Reference<'a, T> {
|
||||
Immutable(&'a T),
|
||||
Mutable(&'a mut T),
|
||||
}
|
||||
|
||||
+38
-36
@@ -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,6 +167,15 @@ 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>,
|
||||
@@ -194,8 +203,8 @@ where
|
||||
impl Size<DefiniteLength> {
|
||||
pub fn zero() -> Self {
|
||||
Self {
|
||||
width: pixels(0.).into(),
|
||||
height: pixels(0.).into(),
|
||||
width: px(0.),
|
||||
height: px(0.),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,17 +244,6 @@ 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 {
|
||||
@@ -258,10 +256,10 @@ impl Edges<Length> {
|
||||
|
||||
pub fn zero() -> Self {
|
||||
Self {
|
||||
top: pixels(0.).into(),
|
||||
right: pixels(0.).into(),
|
||||
bottom: pixels(0.).into(),
|
||||
left: pixels(0.).into(),
|
||||
top: px(0.),
|
||||
right: px(0.),
|
||||
bottom: px(0.),
|
||||
left: px(0.),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,10 +279,10 @@ impl Edges<Length> {
|
||||
impl Edges<DefiniteLength> {
|
||||
pub fn zero() -> Self {
|
||||
Self {
|
||||
top: pixels(0.).into(),
|
||||
right: pixels(0.).into(),
|
||||
bottom: pixels(0.).into(),
|
||||
left: pixels(0.).into(),
|
||||
top: px(0.),
|
||||
right: px(0.),
|
||||
bottom: px(0.),
|
||||
left: px(0.),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,10 +299,10 @@ impl Edges<DefiniteLength> {
|
||||
impl Edges<AbsoluteLength> {
|
||||
pub fn zero() -> Self {
|
||||
Self {
|
||||
top: pixels(0.),
|
||||
right: pixels(0.),
|
||||
bottom: pixels(0.),
|
||||
left: pixels(0.),
|
||||
top: px(0.),
|
||||
right: px(0.),
|
||||
bottom: px(0.),
|
||||
left: px(0.),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +331,7 @@ impl Edges<f32> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Neg)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum AbsoluteLength {
|
||||
Pixels(f32),
|
||||
Rems(f32),
|
||||
@@ -371,7 +369,7 @@ impl Default for AbsoluteLength {
|
||||
}
|
||||
|
||||
/// A non-auto length that can be defined in pixels, rems, or percent of parent.
|
||||
#[derive(Clone, Copy, Neg)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum DefiniteLength {
|
||||
Absolute(AbsoluteLength),
|
||||
Relative(f32), // 0. to 1.
|
||||
@@ -415,7 +413,7 @@ impl Default for DefiniteLength {
|
||||
}
|
||||
|
||||
/// A length that can be defined in pixels, rems, percent of parent, or auto.
|
||||
#[derive(Clone, Copy, Neg)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Length {
|
||||
Definite(DefiniteLength),
|
||||
Auto,
|
||||
@@ -430,16 +428,20 @@ impl std::fmt::Debug for Length {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn relative(fraction: f32) -> DefiniteLength {
|
||||
DefiniteLength::Relative(fraction)
|
||||
pub fn relative<T: From<DefiniteLength>>(fraction: f32) -> T {
|
||||
DefiniteLength::Relative(fraction).into()
|
||||
}
|
||||
|
||||
pub fn rems(rems: f32) -> AbsoluteLength {
|
||||
AbsoluteLength::Rems(rems)
|
||||
pub fn rems<T: From<AbsoluteLength>>(rems: f32) -> T {
|
||||
AbsoluteLength::Rems(rems).into()
|
||||
}
|
||||
|
||||
pub fn pixels(pixels: f32) -> AbsoluteLength {
|
||||
AbsoluteLength::Pixels(pixels)
|
||||
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 auto() -> Length {
|
||||
|
||||
@@ -22,8 +22,8 @@ use std::{
|
||||
};
|
||||
|
||||
pub struct TextLayoutCache {
|
||||
prev_frame: Mutex<HashMap<CacheKeyValue, Arc<LineLayout>>>,
|
||||
curr_frame: RwLock<HashMap<CacheKeyValue, Arc<LineLayout>>>,
|
||||
prev_frame: Mutex<HashMap<OwnedCacheKey, Arc<LineLayout>>>,
|
||||
curr_frame: RwLock<HashMap<OwnedCacheKey, Arc<LineLayout>>>,
|
||||
fonts: Arc<dyn platform::FontSystem>,
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ impl TextLayoutCache {
|
||||
font_size: f32,
|
||||
runs: &'a [(usize, RunStyle)],
|
||||
) -> Line {
|
||||
let key = &CacheKeyRef {
|
||||
let key = &BorrowedCacheKey {
|
||||
text,
|
||||
font_size: OrderedFloat(font_size),
|
||||
runs,
|
||||
@@ -72,7 +72,7 @@ impl TextLayoutCache {
|
||||
Line::new(layout, runs)
|
||||
} else {
|
||||
let layout = Arc::new(self.fonts.layout_line(text, font_size, runs));
|
||||
let key = CacheKeyValue {
|
||||
let key = OwnedCacheKey {
|
||||
text: text.into(),
|
||||
font_size: OrderedFloat(font_size),
|
||||
runs: SmallVec::from(runs),
|
||||
@@ -84,7 +84,7 @@ impl TextLayoutCache {
|
||||
}
|
||||
|
||||
trait CacheKey {
|
||||
fn key(&self) -> CacheKeyRef;
|
||||
fn key(&self) -> BorrowedCacheKey;
|
||||
}
|
||||
|
||||
impl<'a> PartialEq for (dyn CacheKey + 'a) {
|
||||
@@ -102,15 +102,15 @@ impl<'a> Hash for (dyn CacheKey + 'a) {
|
||||
}
|
||||
|
||||
#[derive(Eq)]
|
||||
struct CacheKeyValue {
|
||||
struct OwnedCacheKey {
|
||||
text: String,
|
||||
font_size: OrderedFloat<f32>,
|
||||
runs: SmallVec<[(usize, RunStyle); 1]>,
|
||||
}
|
||||
|
||||
impl CacheKey for CacheKeyValue {
|
||||
fn key(&self) -> CacheKeyRef {
|
||||
CacheKeyRef {
|
||||
impl CacheKey for OwnedCacheKey {
|
||||
fn key(&self) -> BorrowedCacheKey {
|
||||
BorrowedCacheKey {
|
||||
text: self.text.as_str(),
|
||||
font_size: self.font_size,
|
||||
runs: self.runs.as_slice(),
|
||||
@@ -118,38 +118,38 @@ impl CacheKey for CacheKeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for CacheKeyValue {
|
||||
impl PartialEq for OwnedCacheKey {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.key().eq(&other.key())
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for CacheKeyValue {
|
||||
impl Hash for OwnedCacheKey {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.key().hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Borrow<dyn CacheKey + 'a> for CacheKeyValue {
|
||||
impl<'a> Borrow<dyn CacheKey + 'a> for OwnedCacheKey {
|
||||
fn borrow(&self) -> &(dyn CacheKey + 'a) {
|
||||
self as &dyn CacheKey
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct CacheKeyRef<'a> {
|
||||
struct BorrowedCacheKey<'a> {
|
||||
text: &'a str,
|
||||
font_size: OrderedFloat<f32>,
|
||||
runs: &'a [(usize, RunStyle)],
|
||||
}
|
||||
|
||||
impl<'a> CacheKey for CacheKeyRef<'a> {
|
||||
fn key(&self) -> CacheKeyRef {
|
||||
impl<'a> CacheKey for BorrowedCacheKey<'a> {
|
||||
fn key(&self) -> BorrowedCacheKey {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialEq for CacheKeyRef<'a> {
|
||||
impl<'a> PartialEq for BorrowedCacheKey<'a> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.text == other.text
|
||||
&& self.font_size == other.font_size
|
||||
@@ -162,7 +162,7 @@ impl<'a> PartialEq for CacheKeyRef<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Hash for CacheKeyRef<'a> {
|
||||
impl<'a> Hash for BorrowedCacheKey<'a> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.text.hash(state);
|
||||
self.font_size.hash(state);
|
||||
|
||||
Reference in New Issue
Block a user