Fix errors preventing compilation

This commit is contained in:
Joscha 2022-06-13 16:43:28 +02:00
parent fb7e504f2c
commit 6fdce9db1e
5 changed files with 156 additions and 30 deletions

View file

@ -1,10 +1,9 @@
mod tree;
use crossterm::event::KeyEvent;
use crossterm::style::ContentStyle;
use toss::frame::{Frame, Pos, Size};
use crate::traits::{Msg, MsgStore};
use crate::store::{Msg, MsgStore};
use self::tree::TreeView;
@ -14,19 +13,28 @@ pub enum Mode {
// Flat,
}
pub struct Cursor<I> {
id: I,
/// Where on the screen the cursor is visible (`0.0` = first line, `1.0` =
/// last line).
proportion: f32,
}
pub struct Chat<M: Msg, S: MsgStore<M>> {
store: S,
cursor: Option<M::Id>,
room: String,
cursor: Option<Cursor<M::Id>>,
mode: Mode,
tree: TreeView,
tree: TreeView<M>,
// thread: ThreadView,
// flat: FlatView,
}
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
pub fn new(store: S) -> Self {
pub fn new(store: S, room: String) -> Self {
Self {
store,
room,
cursor: None,
mode: Mode::Tree,
tree: TreeView::new(),
@ -37,16 +45,21 @@ impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
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)
}
Mode::Tree => self.tree.handle_key_event(
&mut self.store,
&self.room,
&mut self.cursor,
event,
size,
),
}
}
pub fn render(&mut self, frame: &mut Frame, pos: Pos, size: Size) {
match self.mode {
Mode::Tree => self.tree.render(&mut self.store, frame, pos, size),
Mode::Tree => self
.tree
.render(&mut self.store, &self.room, frame, pos, size),
}
}
}