From 3709eff34bd257e882102d4aea26a5f7e838c0f3 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 18 Aug 2023 01:59:21 -0600 Subject: [PATCH] Compiling --- crates/gpui/playground/src/element.rs | 29 +++++++---- crates/gpui/playground/src/frame.rs | 2 +- crates/gpui/playground/src/hoverable.rs | 19 ++++---- crates/gpui/playground/src/paint_context.rs | 6 ++- crates/gpui/playground/src/text.rs | 2 +- crates/gpui/src/app.rs | 17 +++++-- .../src/derive_refineable.rs | 48 +++++++++++++++---- crates/refineable/src/refineable.rs | 9 ++-- 8 files changed, 95 insertions(+), 37 deletions(-) diff --git a/crates/gpui/playground/src/element.rs b/crates/gpui/playground/src/element.rs index 2d59b7a48bb2338ca9381e9e37a56a1ad61a13f2..7b9a9910a21d7a9fac13e7c30e1526349a193beb 100644 --- a/crates/gpui/playground/src/element.rs +++ b/crates/gpui/playground/src/element.rs @@ -12,6 +12,7 @@ use gpui::{ EngineLayout, EventContext, RenderContext, ViewContext, }; use playground_macros::tailwind_lengths; +use refineable::Refineable; use std::{ any::{Any, TypeId}, cell::Cell, @@ -61,7 +62,7 @@ pub trait Element: 'static { fn declared_style(&mut self) -> &mut StyleRefinement; - fn computed_style(&mut self) -> &StyleRefinement { + fn computed_style(&mut self, cx: &mut ViewContext) -> &StyleRefinement { self.declared_style() } @@ -444,7 +445,8 @@ pub trait Element: 'static { // Object-safe counterpart of Element used by AnyElement to store elements as trait objects. trait ElementObject { - fn style(&mut self) -> &mut StyleRefinement; + fn declared_style(&mut self) -> &mut StyleRefinement; + fn computed_style(&mut self, cx: &mut ViewContext) -> &StyleRefinement; fn handlers_mut(&mut self) -> &mut Vec>; fn layout(&mut self, view: &mut V, cx: &mut LayoutContext) -> Result<(NodeId, Box)>; @@ -457,10 +459,14 @@ trait ElementObject { } impl> ElementObject for E { - fn style(&mut self) -> &mut StyleRefinement { + fn declared_style(&mut self) -> &mut StyleRefinement { Element::declared_style(self) } + fn computed_style(&mut self, cx: &mut ViewContext) -> &StyleRefinement { + Element::computed_style(self, cx) + } + fn handlers_mut(&mut self) -> &mut Vec> { Element::handlers_mut(self) } @@ -510,10 +516,13 @@ impl AnyElement { Ok(node_id) } - pub fn push_text_style(&mut self, cx: &mut impl RenderContext) -> bool { - let text_style = self.element.style().text_style(); + pub fn push_text_style<'a: 'b, 'b>(&mut self, cx: &mut impl RenderContext<'a, 'b, V>) -> bool { + let text_style = self + .element + .computed_style(cx.as_view_context()) + .text_style(); if let Some(text_style) = text_style { - cx.push_text_style(cx.text_style().refine(text_style)); + cx.push_text_style(cx.text_style().refined(&text_style)); true } else { false @@ -535,7 +544,7 @@ impl AnyElement { from_element: element_layout.as_mut(), }; - let style = self.element.style(); + let style = self.element.computed_style(cx.as_view_context()); let fill_color = style.fill.as_ref().and_then(|fill| fill.color()); if let Some(fill_color) = fill_color { @@ -583,7 +592,11 @@ impl Element for AnyElement { type Layout = (); fn declared_style(&mut self) -> &mut StyleRefinement { - self.element.style() + self.element.declared_style() + } + + fn computed_style(&mut self, cx: &mut ViewContext) -> &StyleRefinement { + self.element.computed_style(cx) } fn handlers_mut(&mut self) -> &mut Vec> { diff --git a/crates/gpui/playground/src/frame.rs b/crates/gpui/playground/src/frame.rs index 0b4bdbb1c10fb5026f114b7d7d6a4eaeca8ea299..9b7bbbe52002d769d2d65ec66580eb5ec17ad367 100644 --- a/crates/gpui/playground/src/frame.rs +++ b/crates/gpui/playground/src/frame.rs @@ -48,7 +48,7 @@ impl Element for Frame { .collect::>>()?; let rem_size = cx.rem_pixels(); - let style = Style::default().refine(&self.style); + let style = Style::default().refined(&self.style); let node_id = cx .layout_engine() .ok_or_else(|| anyhow!("no layout engine"))? diff --git a/crates/gpui/playground/src/hoverable.rs b/crates/gpui/playground/src/hoverable.rs index 1cbfdc283fc0188b12be88ea90cae7184ca054dd..6b41871db73d0882a5b07a37471876d6470e4230 100644 --- a/crates/gpui/playground/src/hoverable.rs +++ b/crates/gpui/playground/src/hoverable.rs @@ -3,17 +3,15 @@ use std::{cell::Cell, marker::PhantomData, rc::Rc}; use gpui::{ geometry::{rect::RectF, vector::Vector2F}, scene::MouseMove, - EngineLayout, + EngineLayout, ViewContext, }; +use refineable::Refineable; -use crate::{ - element::Element, - style::{Style, StyleRefinement}, -}; +use crate::{element::Element, style::StyleRefinement}; pub struct Hoverable { hover_style: StyleRefinement, - computed_style: Option