This commit is contained in:
Nathan Sobo 2023-08-12 10:00:08 -06:00
parent 4b4b949972
commit 0d31d6dac5
4 changed files with 35 additions and 41 deletions

18
Cargo.lock generated
View file

@ -3181,12 +3181,9 @@ dependencies = [
[[package]] [[package]]
name = "grid" name = "grid"
version = "0.9.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0634107a3a005070dd73e27e74ecb691a94e9e5ba7829f434db7fbf73a6b5c47" checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c"
dependencies = [
"no-std-compat",
]
[[package]] [[package]]
name = "h2" name = "h2"
@ -4608,12 +4605,6 @@ dependencies = [
"static_assertions", "static_assertions",
] ]
[[package]]
name = "no-std-compat"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
[[package]] [[package]]
name = "node_runtime" name = "node_runtime"
version = "0.1.0" version = "0.1.0"
@ -7662,9 +7653,8 @@ dependencies = [
[[package]] [[package]]
name = "taffy" name = "taffy"
version = "0.3.12" version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/DioxusLabs/taffy?rev=dab541d6104d58e2e10ce90c4a1dad0b703160cd#dab541d6104d58e2e10ce90c4a1dad0b703160cd"
checksum = "3540ec65df399929a04a485feb50144475735920cc47eaf8eba09c70b1df4055"
dependencies = [ dependencies = [
"arrayvec 0.7.4", "arrayvec 0.7.4",
"grid", "grid",

View file

@ -47,12 +47,12 @@ serde_derive.workspace = true
serde_json.workspace = true serde_json.workspace = true
smallvec.workspace = true smallvec.workspace = true
smol.workspace = true smol.workspace = true
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "dab541d6104d58e2e10ce90c4a1dad0b703160cd" }
time.workspace = true time.workspace = true
tiny-skia = "0.5" tiny-skia = "0.5"
usvg = { version = "0.14", features = [] } usvg = { version = "0.14", features = [] }
uuid = { version = "1.1.2", features = ["v4"] } uuid = { version = "1.1.2", features = ["v4"] }
waker-fn = "1.1.0" waker-fn = "1.1.0"
taffy = "0.3.12"
[build-dependencies] [build-dependencies]
bindgen = "0.65.1" bindgen = "0.65.1"

View file

@ -16,7 +16,7 @@ optional_struct = "0.3.1"
serde.workspace = true serde.workspace = true
simplelog = "0.9" simplelog = "0.9"
smallvec.workspace = true smallvec.workspace = true
taffy = "0.3.12" taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "dab541d6104d58e2e10ce90c4a1dad0b703160cd" }
util = { path = "../../util" } util = { path = "../../util" }
[dev-dependencies] [dev-dependencies]

View file

@ -18,8 +18,8 @@ use gpui::{
use length::{Length, Rems}; use length::{Length, Rems};
use log::warn; use log::warn;
use optional_struct::*; use optional_struct::*;
use smallvec::SmallVec;
use std::{any::Any, borrow::Cow, f32, ops::Range, sync::Arc}; use std::{any::Any, borrow::Cow, f32, ops::Range, sync::Arc};
use taffy::prelude::Style as TaffyStyle;
use util::ResultExt; use util::ResultExt;
use crate::color::{Hsla, Rgba}; use crate::color::{Hsla, Rgba};
@ -28,6 +28,7 @@ use self::length::rems;
pub struct Frame<V> { pub struct Frame<V> {
style: FrameStyle, style: FrameStyle,
metadata: FrameMetadata,
children: Vec<AnyElement<V>>, children: Vec<AnyElement<V>>,
id: Option<Cow<'static, str>>, id: Option<Cow<'static, str>>,
before_paint: Option<Box<dyn FnMut(RectF, &mut FrameLayout, &mut PaintContext<V>)>>, before_paint: Option<Box<dyn FnMut(RectF, &mut FrameLayout, &mut PaintContext<V>)>>,
@ -49,6 +50,7 @@ impl<V> Default for Frame<V> {
fn default() -> Self { fn default() -> Self {
Self { Self {
style: Default::default(), style: Default::default(),
metadata: Default::default(),
children: Default::default(), children: Default::default(),
id: None, id: None,
before_paint: None, before_paint: None,
@ -76,6 +78,25 @@ impl<V: 'static> Element<V> for Frame<V> {
} }
} }
let mut child_node_ids = SmallVec::<[_; 2]>::new();
for child in &mut self.children {
child.layout(constraint, view, cx);
child_node_ids.extend(
child
.metadata::<FrameMetadata>()
.and_then(|meta| meta.layout_node_id),
);
}
self.metadata.layout_node_id = cx
.layout_engine()
.new_with_children(self.style.layout.clone(), child_node_ids.as_slice())
.log_err();
if pushed_text_style {
cx.pop_text_style();
}
(todo!(), todo!()) (todo!(), todo!())
} }
@ -196,7 +217,7 @@ impl<V: 'static> Element<V> for Frame<V> {
} }
fn metadata(&self) -> Option<&dyn Any> { fn metadata(&self) -> Option<&dyn Any> {
Some(&self.style) Some(&self.metadata)
} }
} }
@ -295,6 +316,11 @@ struct Interactive<Style> {
disabled: Style, disabled: Style,
} }
#[derive(Default)]
pub struct FrameMetadata {
layout_node_id: Option<taffy::tree::NodeId>,
}
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct FrameStyle { pub struct FrameStyle {
text: OptionalTextStyle, text: OptionalTextStyle,
@ -303,7 +329,7 @@ pub struct FrameStyle {
borders: Borders, borders: Borders,
corner_radius: f32, corner_radius: f32,
shadows: Vec<Shadow>, shadows: Vec<Shadow>,
layout: TaffyStyle, layout: taffy::style::Style,
} }
#[optional_struct] #[optional_struct]
@ -1309,28 +1335,6 @@ impl Vector2FExt for Vector2F {
} }
} }
trait ElementExt<V: 'static> {
fn margin_left(self, margin_left: impl Into<Length>) -> Frame<V>
where
Self: Element<V> + Sized,
{
column().child(self).margin_left(margin_left)
}
}
impl<V, E> ElementExt<V> for E
where
V: 'static,
E: Element<V>,
{
fn margin_left(self, margin_left: impl Into<Length>) -> Frame<V>
where
Self: Sized,
{
column().child(self).margin_left(margin_left)
}
}
pub fn view<F, E>(mut render: F) -> ViewFn pub fn view<F, E>(mut render: F) -> ViewFn
where where
F: 'static + FnMut(&mut ViewContext<ViewFn>) -> E, F: 'static + FnMut(&mut ViewContext<ViewFn>) -> E,