Hook up TreeView to Chat

This commit is contained in:
Joscha 2022-06-13 10:27:15 +02:00
parent 14125c1650
commit e72fd60d16
2 changed files with 55 additions and 7 deletions

View file

@ -1,9 +1,13 @@
mod tree;
use crossterm::event::KeyEvent;
use crossterm::style::ContentStyle;
use toss::frame::{Frame, Pos, Size};
use crate::traits::{Msg, MsgStore};
use self::tree::TreeView;
pub enum Mode {
Tree,
// Thread,
@ -11,10 +15,10 @@ pub enum Mode {
}
pub struct Chat<M: Msg, S: MsgStore<M>> {
cursor: Option<M::Id>,
store: S,
cursor: Option<M::Id>,
mode: Mode,
// tree: TreeView,
tree: TreeView,
// thread: ThreadView,
// flat: FlatView,
}
@ -22,20 +26,27 @@ pub struct Chat<M: Msg, S: MsgStore<M>> {
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
pub fn new(store: S) -> Self {
Self {
cursor: None,
store,
cursor: None,
mode: Mode::Tree,
tree: TreeView::new(),
}
}
}
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
pub fn handle_key_event(&mut self, key: KeyEvent, size: Size) {
// TODO
pub fn handle_key_event(&mut self, event: KeyEvent, size: Size) {
match self.mode {
Mode::Tree => {
self.tree
.handle_key_event(&mut self.store, &mut self.cursor, event, size)
}
}
}
pub fn render(&mut self, frame: &mut Frame, pos: Pos, size: Size) {
// TODO
frame.write(Pos::new(0, 0), "Hello world!", ContentStyle::default());
match self.mode {
Mode::Tree => self.tree.render(&mut self.store, frame, pos, size),
}
}
}

37
cove-tui/src/chat/tree.rs Normal file
View file

@ -0,0 +1,37 @@
use crossterm::event::KeyEvent;
use crossterm::style::ContentStyle;
use toss::frame::{Frame, Pos, Size};
use crate::traits::{Msg, MsgStore};
pub struct TreeView {}
impl TreeView {
pub fn new() -> Self {
Self {}
}
pub fn handle_key_event<M, S>(
&mut self,
store: &mut S,
cursor: &mut Option<M::Id>,
event: KeyEvent,
size: Size,
) where
M: Msg,
S: MsgStore<M>,
{
// TODO
}
pub fn render<M: Msg, S: MsgStore<M>>(
&mut self,
store: &mut S,
frame: &mut Frame,
pos: Pos,
size: Size,
) {
// TODO
frame.write(Pos::new(0, 0), "Hello world!", ContentStyle::default());
}
}