moved stretch layout to native-core

This commit is contained in:
Evan Almloff committed 2022-03-26 20:28:29 -05:00
1 parent 26d92b6e51
commit 6adfa8805c
5 files changed
+35 -36

No files matched your search

@@ -1,8 +1,8 @@
use crate::BubbledUpState;
use dioxus_core::*; use dioxus_core::*;
use dioxus_native_core::BubbledUpState;
use stretch2::prelude::*; use stretch2::prelude::*;
use dioxus_native_core::layout_attributes::apply_layout_attributes; use crate::layout_attributes::apply_layout_attributes;
/* /*
The layout system uses the lineheight as one point. The layout system uses the lineheight as one point.
@@ -11,12 +11,12 @@ stretch uses fractional points, so we can rasterize if we need too, but not with
this means anything thats "1px" is 1 lineheight. Unfortunately, text cannot be smaller or bigger this means anything thats "1px" is 1 lineheight. Unfortunately, text cannot be smaller or bigger
*/ */
#[derive(Clone, PartialEq, Default, Debug)] #[derive(Clone, PartialEq, Default, Debug)]
pub struct RinkLayout { pub struct StretchLayout {
pub style: Style, pub style: Style,
pub node: Option<Node>, pub node: Option<Node>,
} }
impl BubbledUpState for RinkLayout { impl BubbledUpState for StretchLayout {
type Ctx = Stretch; type Ctx = Stretch;
// Although we pass in the parent, the state of RinkLayout must only depend on the parent for optimiztion purposes // Although we pass in the parent, the state of RinkLayout must only depend on the parent for optimiztion purposes
+1
View File
@@ -1,6 +1,7 @@
use std::collections::{HashMap, HashSet, VecDeque}; use std::collections::{HashMap, HashSet, VecDeque};
use dioxus_core::{ElementId, Mutations, VNode, VirtualDom}; use dioxus_core::{ElementId, Mutations, VNode, VirtualDom};
pub mod layout;
pub mod layout_attributes; pub mod layout_attributes;
/// A tree that can sync with dioxus mutations backed by a hashmap. /// A tree that can sync with dioxus mutations backed by a hashmap.
+7 -7
View File
@@ -4,7 +4,7 @@ use crossterm::event::{
use dioxus_core::*; use dioxus_core::*;
use dioxus_html::{on::*, KeyCode}; use dioxus_html::{on::*, KeyCode};
use dioxus_native_core::{Tree, TreeNode}; use dioxus_native_core::{layout::StretchLayout, Tree, TreeNode};
use futures::{channel::mpsc::UnboundedReceiver, StreamExt}; use futures::{channel::mpsc::UnboundedReceiver, StreamExt};
use std::{ use std::{
any::Any, any::Any,
@@ -16,7 +16,7 @@ use std::{
}; };
use stretch2::{prelude::Layout, Stretch}; use stretch2::{prelude::Layout, Stretch};
use crate::{style_attributes::StyleModifier, RinkLayout}; use crate::style_attributes::StyleModifier;
// a wrapper around the input state for easier access // a wrapper around the input state for easier access
// todo: fix loop // todo: fix loop
@@ -166,7 +166,7 @@ impl InnerInputState {
evts: &mut Vec<EventCore>, evts: &mut Vec<EventCore>,
resolved_events: &mut Vec<UserEvent>, resolved_events: &mut Vec<UserEvent>,
layout: &Stretch, layout: &Stretch,
tree: &mut Tree<RinkLayout, StyleModifier>, tree: &mut Tree<StretchLayout, StyleModifier>,
) { ) {
let previous_mouse = self let previous_mouse = self
.mouse .mouse
@@ -191,7 +191,7 @@ impl InnerInputState {
previous_mouse: Option<(MouseData, Vec<u16>)>, previous_mouse: Option<(MouseData, Vec<u16>)>,
resolved_events: &mut Vec<UserEvent>, resolved_events: &mut Vec<UserEvent>,
layout: &Stretch, layout: &Stretch,
tree: &mut Tree<RinkLayout, StyleModifier>, tree: &mut Tree<StretchLayout, StyleModifier>,
) { ) {
struct Data<'b> { struct Data<'b> {
new_pos: (i32, i32), new_pos: (i32, i32),
@@ -215,8 +215,8 @@ impl InnerInputState {
data: Arc<dyn Any + Send + Sync>, data: Arc<dyn Any + Send + Sync>,
will_bubble: &mut HashSet<ElementId>, will_bubble: &mut HashSet<ElementId>,
resolved_events: &mut Vec<UserEvent>, resolved_events: &mut Vec<UserEvent>,
node: &TreeNode<RinkLayout, StyleModifier>, node: &TreeNode<StretchLayout, StyleModifier>,
tree: &Tree<RinkLayout, StyleModifier>, tree: &Tree<StretchLayout, StyleModifier>,
) { ) {
// only trigger event if the event was not triggered already by a child // only trigger event if the event was not triggered already by a child
if will_bubble.insert(node.id) { if will_bubble.insert(node.id) {
@@ -543,7 +543,7 @@ impl RinkInputHandler {
pub fn get_events<'a>( pub fn get_events<'a>(
&self, &self,
layout: &Stretch, layout: &Stretch,
tree: &mut Tree<RinkLayout, StyleModifier>, tree: &mut Tree<StretchLayout, StyleModifier>,
) -> Vec<UserEvent> { ) -> Vec<UserEvent> {
let mut resolved_events = Vec::new(); let mut resolved_events = Vec::new();
+18 -20
View File
@@ -10,7 +10,7 @@ use crossterm::{
use dioxus_core::exports::futures_channel::mpsc::unbounded; use dioxus_core::exports::futures_channel::mpsc::unbounded;
use dioxus_core::*; use dioxus_core::*;
use dioxus_html::on::{KeyboardData, MouseData, PointerData, TouchData, WheelData}; use dioxus_html::on::{KeyboardData, MouseData, PointerData, TouchData, WheelData};
use dioxus_native_core::Tree; use dioxus_native_core::{layout::StretchLayout, Tree};
use futures::{channel::mpsc::UnboundedSender, pin_mut, StreamExt}; use futures::{channel::mpsc::UnboundedSender, pin_mut, StreamExt};
use std::collections::HashSet; use std::collections::HashSet;
use std::{io, time::Duration}; use std::{io, time::Duration};
@@ -21,7 +21,6 @@ use tui::{backend::CrosstermBackend, Terminal};
mod config; mod config;
mod hooks; mod hooks;
mod layout;
mod render; mod render;
mod style; mod style;
mod style_attributes; mod style_attributes;
@@ -29,7 +28,6 @@ mod widget;
pub use config::*; pub use config::*;
pub use hooks::*; pub use hooks::*;
pub use layout::*;
pub use render::*; pub use render::*;
pub fn launch(app: Component<()>) { pub fn launch(app: Component<()>) {
@@ -46,7 +44,7 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
cx.provide_root_context(state); cx.provide_root_context(state);
let mut tree: Tree<RinkLayout, StyleModifier> = Tree::new(); let mut tree: Tree<StretchLayout, StyleModifier> = Tree::new();
let mutations = dom.rebuild(); let mutations = dom.rebuild();
let to_update = tree.apply_mutations(vec![mutations]); let to_update = tree.apply_mutations(vec![mutations]);
let mut stretch = Stretch::new(); let mut stretch = Stretch::new();
@@ -62,7 +60,7 @@ pub fn render_vdom(
ctx: UnboundedSender<TermEvent>, ctx: UnboundedSender<TermEvent>,
handler: RinkInputHandler, handler: RinkInputHandler,
cfg: Config, cfg: Config,
mut tree: Tree<RinkLayout, StyleModifier>, mut tree: Tree<StretchLayout, StyleModifier>,
mut stretch: Stretch, mut stretch: Stretch,
) -> Result<()> { ) -> Result<()> {
// Setup input handling // Setup input handling
@@ -148,21 +146,21 @@ pub fn render_vdom(
// resolve events before rendering // resolve events before rendering
// todo: events do not trigger update? // todo: events do not trigger update?
for e in handler.get_events(&stretch, &mut tree) { for e in handler.get_events(&stretch, &mut tree) {
let tname = if e.data.is::<PointerData>() { // let tname = if e.data.is::<PointerData>() {
"PointerData" // "PointerData"
} else if e.data.is::<WheelData>() { // } else if e.data.is::<WheelData>() {
"WheelData" // "WheelData"
} else if e.data.is::<MouseData>() { // } else if e.data.is::<MouseData>() {
"MouseData" // "MouseData"
} else if e.data.is::<KeyboardData>() { // } else if e.data.is::<KeyboardData>() {
"KeyboardData" // "KeyboardData"
} else if e.data.is::<TouchData>() { // } else if e.data.is::<TouchData>() {
"TouchData" // "TouchData"
} else if e.data.is::<(u16, u16)>() { // } else if e.data.is::<(u16, u16)>() {
"(u16, u16)" // "(u16, u16)"
} else { // } else {
panic!() // panic!()
}; // };
// println!("{tname}: {e:?}"); // println!("{tname}: {e:?}");
vdom.handle_message(SchedulerMsg::Event(e)); vdom.handle_message(SchedulerMsg::Event(e));
} }
+5 -5
View File
@@ -1,4 +1,4 @@
use dioxus_native_core::{layout_attributes::UnitSystem, Tree, TreeNode}; use dioxus_native_core::{layout::StretchLayout, layout_attributes::UnitSystem, Tree, TreeNode};
use std::io::Stdout; use std::io::Stdout;
use stretch2::{ use stretch2::{
geometry::Point, geometry::Point,
@@ -11,7 +11,7 @@ use crate::{
style::{RinkColor, RinkStyle}, style::{RinkColor, RinkStyle},
style_attributes::{BorderEdge, BorderStyle}, style_attributes::{BorderEdge, BorderStyle},
widget::{RinkBuffer, RinkCell, RinkWidget, WidgetWithContext}, widget::{RinkBuffer, RinkCell, RinkWidget, WidgetWithContext},
Config, RinkLayout, StyleModifier, Config, StyleModifier,
}; };
const RADIUS_MULTIPLIER: [f32; 2] = [1.0, 0.5]; const RADIUS_MULTIPLIER: [f32; 2] = [1.0, 0.5];
@@ -19,8 +19,8 @@ const RADIUS_MULTIPLIER: [f32; 2] = [1.0, 0.5];
pub fn render_vnode<'a>( pub fn render_vnode<'a>(
frame: &mut tui::Frame<CrosstermBackend<Stdout>>, frame: &mut tui::Frame<CrosstermBackend<Stdout>>,
layout: &Stretch, layout: &Stretch,
tree: &Tree<RinkLayout, StyleModifier>, tree: &Tree<StretchLayout, StyleModifier>,
node: &TreeNode<RinkLayout, StyleModifier>, node: &TreeNode<StretchLayout, StyleModifier>,
cfg: Config, cfg: Config,
) { ) {
match &node.node_type { match &node.node_type {
@@ -80,7 +80,7 @@ pub fn render_vnode<'a>(
} }
} }
impl RinkWidget for &TreeNode<RinkLayout, StyleModifier> { impl RinkWidget for &TreeNode<StretchLayout, StyleModifier> {
fn render(self, area: Rect, mut buf: RinkBuffer<'_>) { fn render(self, area: Rect, mut buf: RinkBuffer<'_>) {
use tui::symbols::line::*; use tui::symbols::line::*;