Rename node to frame

This commit is contained in:
Nathan Sobo 2023-08-08 21:28:52 -06:00
parent c95aecdd53
commit 82c903de14
4 changed files with 33 additions and 33 deletions

View file

@ -24,19 +24,19 @@ use std::{any::Any, borrow::Cow, f32, ops::Range, sync::Arc};
use crate::color::Rgba; use crate::color::Rgba;
pub struct Node<V: View> { pub struct Frame<V: View> {
style: NodeStyle, style: FrameStyle,
children: Vec<AnyElement<V>>, children: Vec<AnyElement<V>>,
id: Option<Cow<'static, str>>, id: Option<Cow<'static, str>>,
} }
pub fn column<V: View>() -> Node<V> { pub fn column<V: View>() -> Frame<V> {
Node::default() Frame::default()
} }
pub fn row<V: View>() -> Node<V> { pub fn row<V: View>() -> Frame<V> {
Node { Frame {
style: NodeStyle { style: FrameStyle {
axis: Axis3d::X, axis: Axis3d::X,
..Default::default() ..Default::default()
}, },
@ -44,9 +44,9 @@ pub fn row<V: View>() -> Node<V> {
} }
} }
pub fn stack<V: View>() -> Node<V> { pub fn stack<V: View>() -> Frame<V> {
Node { Frame {
style: NodeStyle { style: FrameStyle {
axis: Axis3d::Z, axis: Axis3d::Z,
..Default::default() ..Default::default()
}, },
@ -54,7 +54,7 @@ pub fn stack<V: View>() -> Node<V> {
} }
} }
impl<V: View> Default for Node<V> { impl<V: View> Default for Frame<V> {
fn default() -> Self { fn default() -> Self {
Self { Self {
style: Default::default(), style: Default::default(),
@ -64,8 +64,8 @@ impl<V: View> Default for Node<V> {
} }
} }
impl<V: View> Element<V> for Node<V> { impl<V: View> Element<V> for Frame<V> {
type LayoutState = NodeLayout; type LayoutState = FrameLayout;
type PaintState = (); type PaintState = ();
fn layout( fn layout(
@ -88,7 +88,7 @@ impl<V: View> Element<V> for Node<V> {
scene: &mut SceneBuilder, scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
layout: &mut NodeLayout, layout: &mut FrameLayout,
view: &mut V, view: &mut V,
cx: &mut PaintContext<V>, cx: &mut PaintContext<V>,
) -> Self::PaintState { ) -> Self::PaintState {
@ -205,7 +205,7 @@ impl<V: View> Element<V> for Node<V> {
cx: &ViewContext<V>, cx: &ViewContext<V>,
) -> Value { ) -> Value {
json!({ json!({
"type": "Node", "type": "Frame",
"bounds": bounds.to_json(), "bounds": bounds.to_json(),
// TODO! // TODO!
// "children": self.content.iter().map(|child| child.debug(view, cx)).collect::<Vec<Value>>() // "children": self.content.iter().map(|child| child.debug(view, cx)).collect::<Vec<Value>>()
@ -217,7 +217,7 @@ impl<V: View> Element<V> for Node<V> {
} }
} }
impl<V: View> Node<V> { impl<V: View> Frame<V> {
pub fn id(mut self, id: impl Into<Cow<'static, str>>) -> Self { pub fn id(mut self, id: impl Into<Cow<'static, str>>) -> Self {
self.id = Some(id.into()); self.id = Some(id.into());
self self
@ -321,10 +321,10 @@ impl<V: View> Node<V> {
rem_pixels: f32, rem_pixels: f32,
view: &mut V, view: &mut V,
cx: &mut LayoutContext<V>, cx: &mut LayoutContext<V>,
) -> NodeLayout { ) -> FrameLayout {
let cross_axis = primary_axis.rotate(); let cross_axis = primary_axis.rotate();
let total_flex = self.style.flex(); let total_flex = self.style.flex();
let mut layout = NodeLayout { let mut layout = FrameLayout {
size: Default::default(), size: Default::default(),
padding: self.style.padding.fixed_pixels(rem_pixels), padding: self.style.padding.fixed_pixels(rem_pixels),
margins: self.style.margins.fixed_pixels(rem_pixels), margins: self.style.margins.fixed_pixels(rem_pixels),
@ -372,7 +372,7 @@ impl<V: View> Node<V> {
for child in &mut self.children { for child in &mut self.children {
if let Some(child_flex) = child if let Some(child_flex) = child
.metadata::<NodeStyle>() .metadata::<FrameStyle>()
.map(|style| style.flex().get(primary_axis)) .map(|style| style.flex().get(primary_axis))
{ {
if child_flex > 0. { if child_flex > 0. {
@ -391,7 +391,7 @@ impl<V: View> Node<V> {
// Distribute the remaining length among the flexible children. // Distribute the remaining length among the flexible children.
for child in &mut self.children { for child in &mut self.children {
if let Some(child_flex) = child if let Some(child_flex) = child
.metadata::<NodeStyle>() .metadata::<FrameStyle>()
.map(|style| style.flex().get(primary_axis)) .map(|style| style.flex().get(primary_axis))
{ {
if child_flex > 0. { if child_flex > 0. {
@ -564,7 +564,7 @@ struct Interactive<Style> {
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct NodeStyle { pub struct FrameStyle {
axis: Axis3d, axis: Axis3d,
wrap: bool, wrap: bool,
align: Alignment, align: Alignment,
@ -584,7 +584,7 @@ pub struct NodeStyle {
shadows: Vec<Shadow>, shadows: Vec<Shadow>,
} }
impl NodeStyle { impl FrameStyle {
fn flex(&self) -> Vector2F { fn flex(&self) -> Vector2F {
self.size.flex() + self.padding.flex() + self.margins.flex() self.size.flex() + self.padding.flex() + self.margins.flex()
} }
@ -1129,7 +1129,7 @@ pub struct Text {
)>, )>,
} }
pub fn text<V: View>(text: impl Into<Cow<'static, str>>) -> Node<V> { pub fn text<V: View>(text: impl Into<Cow<'static, str>>) -> Frame<V> {
row().child(Text { row().child(Text {
text: text.into(), text: text.into(),
..Default::default() ..Default::default()
@ -1137,7 +1137,7 @@ pub fn text<V: View>(text: impl Into<Cow<'static, str>>) -> Node<V> {
} }
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct NodeLayout { pub struct FrameLayout {
size: Vector2F, size: Vector2F,
padding: Edges<f32>, padding: Edges<f32>,
borders: Edges<f32>, borders: Edges<f32>,
@ -1457,7 +1457,7 @@ impl Vector2FExt for Vector2F {
} }
trait ElementExt<V: View> { trait ElementExt<V: View> {
fn margin_left(self, margin_left: impl Into<Length>) -> Node<V> fn margin_left(self, margin_left: impl Into<Length>) -> Frame<V>
where where
Self: Element<V> + Sized, Self: Element<V> + Sized,
{ {
@ -1470,7 +1470,7 @@ where
V: View, V: View,
E: Element<V>, E: Element<V>,
{ {
fn margin_left(self, margin_left: impl Into<Length>) -> Node<V> fn margin_left(self, margin_left: impl Into<Length>) -> Frame<V>
where where
Self: Sized, Self: Sized,
{ {

View file

@ -1,19 +1,19 @@
#![allow(dead_code, unused_variables)] #![allow(dead_code, unused_variables)]
use frame::{length::auto, *};
use gpui::{AnyElement, Element, LayoutContext, View, ViewContext}; use gpui::{AnyElement, Element, LayoutContext, View, ViewContext};
use node::{length::auto, *};
use std::{borrow::Cow, cell::RefCell, marker::PhantomData, rc::Rc}; use std::{borrow::Cow, cell::RefCell, marker::PhantomData, rc::Rc};
use tokens::{margin::m4, text::lg}; use tokens::{margin::m4, text::lg};
mod color; mod color;
mod node; mod frame;
mod themes; mod themes;
mod tokens; mod tokens;
#[derive(Element, Clone, Default)] #[derive(Element, Clone, Default)]
pub struct Playground<V: View>(PhantomData<V>); pub struct Playground<V: View>(PhantomData<V>);
impl<V: View> Node<V> {} impl<V: View> Frame<V> {}
impl<V: View> Playground<V> { impl<V: View> Playground<V> {
pub fn render(&mut self, _: &mut V, _: &mut gpui::ViewContext<V>) -> impl Element<V> { pub fn render(&mut self, _: &mut V, _: &mut gpui::ViewContext<V>) -> impl Element<V> {

View file

@ -10,7 +10,7 @@ pub mod color {
} }
pub mod text { pub mod text {
use crate::node::length::{rems, Rems}; use crate::frame::length::{rems, Rems};
pub fn xs() -> Rems { pub fn xs() -> Rems {
rems(0.75) rems(0.75)
@ -54,7 +54,7 @@ pub mod text {
} }
pub mod padding { pub mod padding {
use crate::node::length::{rems, Rems}; use crate::frame::length::{rems, Rems};
pub fn p1() -> Rems { pub fn p1() -> Rems {
rems(0.25) rems(0.25)
@ -110,7 +110,7 @@ pub mod padding {
} }
pub mod margin { pub mod margin {
use crate::node::length::{rems, Rems}; use crate::frame::length::{rems, Rems};
pub fn m1() -> Rems { pub fn m1() -> Rems {
rems(0.25) rems(0.25)

View file

@ -16,7 +16,7 @@ use crate::{
Action, AnyView, AnyViewHandle, AnyWindowHandle, AppContext, BorrowAppContext, Action, AnyView, AnyViewHandle, AnyWindowHandle, AppContext, BorrowAppContext,
BorrowWindowContext, Effect, Element, Entity, Handle, LayoutContext, MouseRegion, BorrowWindowContext, Effect, Element, Entity, Handle, LayoutContext, MouseRegion,
MouseRegionId, PaintContext, SceneBuilder, Subscription, View, ViewContext, ViewHandle, MouseRegionId, PaintContext, SceneBuilder, Subscription, View, ViewContext, ViewHandle,
WindowHandle, WindowInvalidation, WindowInvalidation,
}; };
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};