forked from vislyhq/stretch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Emil Sjölander
committed
Apr 5, 2019
1 parent
6a2b01f
commit f3d2a5e
Showing
6 changed files
with
213 additions
and
175 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#[cfg(not(feature = "std"))] | ||
use alloc::{vec, vec::Vec}; | ||
|
||
use std::rc::Rc; | ||
use std::rc::Weak; | ||
use std::cell::RefCell; | ||
|
||
use crate::style::*; | ||
use crate::algo; | ||
use crate::geometry::Size; | ||
use crate::number::Number; | ||
use crate::result::{Layout, Cache, Result}; | ||
|
||
type MeasureFunc = Box<Fn(Size<Number>) -> Result<Size<f32>>>; | ||
|
||
pub(crate) struct InternalNode { | ||
pub(crate) style: Style, | ||
pub(crate) parents: Vec<Weak<RefCell<InternalNode>>>, | ||
pub(crate) children: Vec<Rc<RefCell<InternalNode>>>, | ||
pub(crate) measure: Option<MeasureFunc>, | ||
pub(crate) layout_cache: RefCell<Option<Cache>>, | ||
} | ||
|
||
pub struct Node(Rc<RefCell<InternalNode>>); | ||
|
||
impl Node { | ||
pub fn new(style: Style, children: Vec<&Node>) -> Node { | ||
let mut parent = Node(Rc::new(RefCell::new(InternalNode { | ||
style: style, | ||
parents: vec![], | ||
children: vec![], | ||
measure: None, | ||
layout_cache: RefCell::new(None), | ||
}))); | ||
|
||
for child in children { | ||
parent.add_child(child); | ||
} | ||
|
||
parent | ||
} | ||
|
||
pub fn add_child(&mut self, child: &Node) { | ||
child.0.borrow_mut().parents.push(Rc::downgrade(&self.0)); | ||
self.0.borrow_mut().children.push(Rc::clone(&child.0)); | ||
} | ||
|
||
// pub fn children(&self) -> Vec<Node> {} | ||
|
||
// pub fn mark_dirty(&mut self) {} | ||
|
||
// pub fn set_style(&mut self, Style) {} | ||
|
||
// pub fn set_children(&mut self, Vec<Node>) {} | ||
|
||
// pub fn add_child(&mut self, Node) {} | ||
|
||
// pub fn remove_child(&mut self, Node) -> Node {} | ||
|
||
// pub fn replace_child(&mut self, Node, u32) -> Node {} | ||
|
||
pub fn compute_layout(&self, size: Size<Number>) -> Result<Layout> { | ||
algo::compute(&self.0.borrow(), size) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
#[cfg(not(feature = "std"))] | ||
use alloc::vec::Vec; | ||
|
||
use core::any::Any; | ||
|
||
use crate::geometry::{Point, Size}; | ||
use crate::number::Number; | ||
use crate::algo::ComputeResult; | ||
|
||
pub type Result<T> = core::result::Result<T, Box<Any>>; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Layout { | ||
pub(crate) order: u32, | ||
pub size: Size<f32>, | ||
pub location: Point<f32>, | ||
pub children: Vec<Layout>, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Cache { | ||
pub node_size: Size<Number>, | ||
pub parent_size: Size<Number>, | ||
pub perform_layout: bool, | ||
|
||
pub result: ComputeResult, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters