wip: Refactor ReprTree; add ReprTreeBuilder
This commit is contained in:
parent
41c02465be
commit
26186b3375
20 changed files with 924 additions and 563 deletions
examples/tty-02-digit/src
|
@ -11,7 +11,7 @@ use {
|
|||
cgmath::Vector2,
|
||||
nested::{
|
||||
editors::ObjCommander,
|
||||
repr_tree::{Context, ReprTree, ReprTreeExt},
|
||||
repr_tree::{Context, ReprTree, ReprTreeExt, ReprTreeBuilder},
|
||||
edit_tree::{EditTree}
|
||||
},
|
||||
nested_tty::{
|
||||
|
@ -39,50 +39,23 @@ async fn main() {
|
|||
|
||||
nested_tty::setup_edittree_hook(&ctx);
|
||||
|
||||
/* structure of Repr-Tree
|
||||
*
|
||||
* === Repr-Tree ===
|
||||
*
|
||||
* <Digit 10>
|
||||
* / | \
|
||||
* / | \
|
||||
* / | \
|
||||
* u64 EditTree Char
|
||||
* - Editor \
|
||||
* - Display EditTree
|
||||
* / | \ - Editor
|
||||
* / | \ - Display
|
||||
* TTY PixelBuf SDF / | \
|
||||
* / | \
|
||||
* TTY PixelBuf SDF
|
||||
*/
|
||||
let mut rt_digit = ReprTree::new_arc( Context::parse(&ctx, "<Digit 16>") );
|
||||
let digit_builder = ReprTreeBuilder::new( ctx.clone() )
|
||||
.require(Context::parse(&ctx, "<Digit 16> ~ ℤ_2^64 ~ machine.UInt64"))
|
||||
.require(Context::parse(&ctx, "<Digit 16> ~ EditTree"))
|
||||
;
|
||||
|
||||
/* add initial representation
|
||||
* <Digit 16> ~ Char
|
||||
*/
|
||||
rt_digit.insert_leaf(
|
||||
let mut rt_digit = ReprTree::from_singleton_buffer(
|
||||
Context::parse(&ctx, "Char"),
|
||||
nested::repr_tree::ReprLeaf::from_singleton_buffer( SingletonBuffer::new('5') )
|
||||
SingletonBuffer::new('5')
|
||||
);
|
||||
|
||||
/* furthermore, setup projections to and from u8 value,
|
||||
* this synchronizes the buffers
|
||||
*/
|
||||
ctx.read().unwrap().apply_morphism(
|
||||
&rt_digit,
|
||||
&laddertypes::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<Digit 16>~Char"),
|
||||
dst_type: Context::parse(&ctx, "<Digit 16>~ℤ_2^64~machine.UInt64")
|
||||
}
|
||||
);
|
||||
ctx.read().unwrap().apply_morphism(
|
||||
&rt_digit,
|
||||
&laddertypes::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<Digit 16>~Char"),
|
||||
dst_type: Context::parse(&ctx, "<Digit 16>~EditTree")
|
||||
}
|
||||
rt_digit.write().unwrap().set_halo(
|
||||
Context::parse(&ctx, "<Digit 16>")
|
||||
);
|
||||
rt_digit = digit_builder.build_from(rt_digit)
|
||||
.expect("failed to build repr tree");
|
||||
|
||||
/* setup terminal
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue