call edittree_hook in morphisms already, add edittree() getter in ReprTreeExt to further simplify application code
This commit is contained in:
parent
7762fa4b12
commit
0bcfd7a65a
9 changed files with 49 additions and 73 deletions
examples/tty-02-digit/src
|
@ -84,30 +84,15 @@ async fn main() {
|
|||
}
|
||||
);
|
||||
|
||||
/* setup TTY-Display for DigitEditor
|
||||
* and call the hook defined above with `set_edittree_hook()`
|
||||
*
|
||||
*/
|
||||
let edittree_digit = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
rt_digit.clone(),
|
||||
SingletonBuffer::new(0).get_port()
|
||||
).unwrap();
|
||||
|
||||
let mut digit_u64_buffer = rt_digit
|
||||
.descend(Context::parse(&ctx, "ℤ_2^64~machine.UInt64")).unwrap()
|
||||
.singleton_buffer::<u64>();
|
||||
|
||||
/* setup terminal
|
||||
*/
|
||||
let app = TTYApplication::new({
|
||||
/* event handler
|
||||
*/
|
||||
let ctx = ctx.clone();
|
||||
|
||||
let mut edittree_digit = edittree_digit.clone();
|
||||
let digit_edittree = rt_digit.edittree( &ctx );
|
||||
move |ev| {
|
||||
edittree_digit.get().write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx));
|
||||
digit_edittree.get().write().unwrap().send_cmd_obj(ev.to_repr_tree(&ctx));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -124,27 +109,26 @@ async fn main() {
|
|||
.map_item(|p, a| {
|
||||
a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0)))
|
||||
})
|
||||
.offset(Vector2::new(5, 0)),
|
||||
);
|
||||
.offset(Vector2::new(5, 0)));
|
||||
|
||||
let label_str = ctx.read().unwrap().type_term_to_str(&rt_digit.read().unwrap().get_type());
|
||||
comp.push(
|
||||
nested_tty::make_label(&label_str)
|
||||
.map_item(|_pt,atom| atom.add_style_front(TerminalStyle::fg_color((90,90,90))))
|
||||
.offset(Vector2::new(1, 1))
|
||||
);
|
||||
comp.push(
|
||||
edittree_digit.get().read().unwrap().display_view()
|
||||
.offset(Vector2::new(3,2))
|
||||
);
|
||||
comp.push(
|
||||
digit_u64_buffer.get_port().map(
|
||||
|d| nested_tty::make_label(&format!("Digit value={}", d))
|
||||
)
|
||||
.offset(Vector2::new(1, 1)));
|
||||
|
||||
comp.push(rt_digit
|
||||
.edittree( &ctx ).get().read().unwrap()
|
||||
.display_view()
|
||||
.offset(Vector2::new(3,2)));
|
||||
|
||||
comp.push(rt_digit
|
||||
.descend(Context::parse(&ctx, "ℤ_2^64~machine.UInt64")).unwrap()
|
||||
.view_u64()
|
||||
.map(|d| nested_tty::make_label(&format!("Digit value={}", d)))
|
||||
.to_grid()
|
||||
.flatten()
|
||||
.offset(Vector2::new(5,3))
|
||||
);
|
||||
.offset(Vector2::new(5,3)));
|
||||
}
|
||||
|
||||
/* write the changes in the view of `term_port` to the terminal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue