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_native_core::BubbledUpState;
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.
@@ -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
*/
#[derive(Clone, PartialEq, Default, Debug)]
pub struct RinkLayout {
pub struct StretchLayout {
pub style: Style,
pub node: Option<Node>,
}
impl BubbledUpState for RinkLayout {
impl BubbledUpState for StretchLayout {
type Ctx = Stretch;
// 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 dioxus_core::{ElementId, Mutations, VNode, VirtualDom};
pub mod layout;
pub mod layout_attributes;
/// 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_html::{on::*, KeyCode};
use dioxus_native_core::{Tree, TreeNode};
use dioxus_native_core::{layout::StretchLayout, Tree, TreeNode};
use futures::{channel::mpsc::UnboundedReceiver, StreamExt};
use std::{
any::Any,
@@ -16,7 +16,7 @@ use std::{
};
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
// todo: fix loop
@@ -166,7 +166,7 @@ impl InnerInputState {
evts: &mut Vec<EventCore>,
resolved_events: &mut Vec<UserEvent>,
layout: &Stretch,
tree: &mut Tree<RinkLayout, StyleModifier>,
tree: &mut Tree<StretchLayout, StyleModifier>,
) {
let previous_mouse = self
.mouse
@@ -191,7 +191,7 @@ impl InnerInputState {
previous_mouse: Option<(MouseData, Vec<u16>)>,
resolved_events: &mut Vec<UserEvent>,
layout: &Stretch,
tree: &mut Tree<RinkLayout, StyleModifier>,
tree: &mut Tree<StretchLayout, StyleModifier>,
) {
struct Data<'b> {
new_pos: (i32, i32),
@@ -215,8 +215,8 @@ impl InnerInputState {
data: Arc<dyn Any + Send + Sync>,
will_bubble: &mut HashSet<ElementId>,
resolved_events: &mut Vec<UserEvent>,
node: &TreeNode<RinkLayout, StyleModifier>,
tree: &Tree<RinkLayout, StyleModifier>,
node: &TreeNode<StretchLayout, StyleModifier>,
tree: &Tree<StretchLayout, StyleModifier>,
) {
// only trigger event if the event was not triggered already by a child
if will_bubble.insert(node.id) {
@@ -543,7 +543,7 @@ impl RinkInputHandler {
pub fn get_events<'a>(
&self,
layout: &Stretch,
tree: &mut Tree<RinkLayout, StyleModifier>,
tree: &mut Tree<StretchLayout, StyleModifier>,
) -> Vec<UserEvent> {
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::*;
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 std::collections::HashSet;
use std::{io, time::Duration};
@@ -21,7 +21,6 @@ use tui::{backend::CrosstermBackend, Terminal};
mod config;
mod hooks;
mod layout;
mod render;
mod style;
mod style_attributes;
@@ -29,7 +28,6 @@ mod widget;
pub use config::*;
pub use hooks::*;
pub use layout::*;
pub use render::*;
pub fn launch(app: Component<()>) {
@@ -46,7 +44,7 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
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 to_update = tree.apply_mutations(vec![mutations]);
let mut stretch = Stretch::new();
@@ -62,7 +60,7 @@ pub fn render_vdom(
ctx: UnboundedSender<TermEvent>,
handler: RinkInputHandler,
cfg: Config,
mut tree: Tree<RinkLayout, StyleModifier>,
mut tree: Tree<StretchLayout, StyleModifier>,
mut stretch: Stretch,
) -> Result<()> {
// Setup input handling
@@ -148,21 +146,21 @@ pub fn render_vdom(
// resolve events before rendering
// todo: events do not trigger update?
for e in handler.get_events(&stretch, &mut tree) {
let tname = if e.data.is::<PointerData>() {
"PointerData"
} else if e.data.is::<WheelData>() {
"WheelData"
} else if e.data.is::<MouseData>() {
"MouseData"
} else if e.data.is::<KeyboardData>() {
"KeyboardData"
} else if e.data.is::<TouchData>() {
"TouchData"
} else if e.data.is::<(u16, u16)>() {
"(u16, u16)"
} else {
panic!()
};
// let tname = if e.data.is::<PointerData>() {
// "PointerData"
// } else if e.data.is::<WheelData>() {
// "WheelData"
// } else if e.data.is::<MouseData>() {
// "MouseData"
// } else if e.data.is::<KeyboardData>() {
// "KeyboardData"
// } else if e.data.is::<TouchData>() {
// "TouchData"
// } else if e.data.is::<(u16, u16)>() {
// "(u16, u16)"
// } else {
// panic!()
// };
// println!("{tname}: {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 stretch2::{
geometry::Point,
@@ -11,7 +11,7 @@ use crate::{
style::{RinkColor, RinkStyle},
style_attributes::{BorderEdge, BorderStyle},
widget::{RinkBuffer, RinkCell, RinkWidget, WidgetWithContext},
Config, RinkLayout, StyleModifier,
Config, StyleModifier,
};
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>(
frame: &mut tui::Frame<CrosstermBackend<Stdout>>,
layout: &Stretch,
tree: &Tree<RinkLayout, StyleModifier>,
node: &TreeNode<RinkLayout, StyleModifier>,
tree: &Tree<StretchLayout, StyleModifier>,
node: &TreeNode<StretchLayout, StyleModifier>,
cfg: Config,
) {
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<'_>) {
use tui::symbols::line::*;