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

View file

@ -1,19 +1,19 @@
#![allow(dead_code, unused_variables)]
use frame::{length::auto, *};
use gpui::{AnyElement, Element, LayoutContext, View, ViewContext};
use node::{length::auto, *};
use std::{borrow::Cow, cell::RefCell, marker::PhantomData, rc::Rc};
use tokens::{margin::m4, text::lg};
mod color;
mod node;
mod frame;
mod themes;
mod tokens;
#[derive(Element, Clone, Default)]
pub struct Playground<V: View>(PhantomData<V>);
impl<V: View> Node<V> {}
impl<V: View> Frame<V> {}
impl<V: View> Playground<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 {
use crate::node::length::{rems, Rems};
use crate::frame::length::{rems, Rems};
pub fn xs() -> Rems {
rems(0.75)
@ -54,7 +54,7 @@ pub mod text {
}
pub mod padding {
use crate::node::length::{rems, Rems};
use crate::frame::length::{rems, Rems};
pub fn p1() -> Rems {
rems(0.25)
@ -110,7 +110,7 @@ pub mod padding {
}
pub mod margin {
use crate::node::length::{rems, Rems};
use crate::frame::length::{rems, Rems};
pub fn m1() -> Rems {
rems(0.25)

View file

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