Layout using new algorithm and new blocks

This commit is contained in:
Joscha 2022-07-31 19:57:45 +02:00
parent 6f4d94afa5
commit ae8ec70e5e
7 changed files with 459 additions and 254 deletions

View file

@ -0,0 +1,88 @@
use crate::ui::chat::blocks::Blocks;
use super::Cursor;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockId<I> {
Msg(I),
Cursor,
LastCursor,
}
impl<I: Clone> BlockId<I> {
pub fn from_cursor(cursor: &Cursor<I>) -> Self {
match cursor {
Cursor::Msg(id) => Self::Msg(id.clone()),
_ => Self::Cursor,
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum Root<I> {
Bottom,
Tree(I),
}
pub struct TreeBlocks<I> {
blocks: Blocks<BlockId<I>>,
top_root: Root<I>,
bottom_root: Root<I>,
}
impl<I> TreeBlocks<I> {
pub fn new(top_root: Root<I>, bottom_root: Root<I>) -> Self {
Self {
blocks: Blocks::new(),
top_root,
bottom_root,
}
}
/// See [`Blocks::new_below`].
pub fn new_below(line: i32, top_root: Root<I>, bottom_root: Root<I>) -> Self {
Self {
blocks: Blocks::new_below(line),
top_root,
bottom_root,
}
}
pub fn blocks(&self) -> &Blocks<BlockId<I>> {
&self.blocks
}
pub fn blocks_mut(&mut self) -> &mut Blocks<BlockId<I>> {
&mut self.blocks
}
pub fn into_blocks(self) -> Blocks<BlockId<I>> {
self.blocks
}
pub fn top_root(&self) -> &Root<I> {
&self.top_root
}
pub fn top_root_mut(&mut self) -> &mut Root<I> {
&mut self.top_root
}
pub fn bottom_root(&self) -> &Root<I> {
&self.bottom_root
}
pub fn bottom_root_mut(&mut self) -> &mut Root<I> {
&mut self.bottom_root
}
pub fn prepend(&mut self, other: Self) {
self.blocks.prepend(other.blocks);
self.top_root = other.top_root;
}
pub fn append(&mut self, other: Self) {
self.blocks.append(other.blocks);
self.bottom_root = other.bottom_root;
}
}