Add constructors for different types of blocks
This commit is contained in:
parent
d638ba2887
commit
e7cd0568e9
1 changed files with 43 additions and 6 deletions
|
|
@ -17,9 +17,8 @@ pub enum MsgContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MsgBlock<I> {
|
pub struct MsgBlock<I> {
|
||||||
id: I,
|
pub id: I,
|
||||||
cursor: bool,
|
pub content: MsgContent,
|
||||||
content: MsgContent,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> MsgBlock<I> {
|
impl<I> MsgBlock<I> {
|
||||||
|
|
@ -42,12 +41,50 @@ pub enum BlockBody<I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Block<I> {
|
pub struct Block<I> {
|
||||||
line: i32,
|
pub line: i32,
|
||||||
indent: usize,
|
pub indent: usize,
|
||||||
body: BlockBody<I>,
|
pub body: BlockBody<I>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> Block<I> {
|
impl<I> Block<I> {
|
||||||
|
pub fn bottom() -> Self {
|
||||||
|
Self {
|
||||||
|
line: 0,
|
||||||
|
indent: 0,
|
||||||
|
body: BlockBody::Marker(MarkerBlock::Bottom),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn after(indent: usize, id: I) -> Self {
|
||||||
|
Self {
|
||||||
|
line: 0,
|
||||||
|
indent,
|
||||||
|
body: BlockBody::Marker(MarkerBlock::After(id)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn msg(indent: usize, id: I, nick: Styled, lines: Vec<Styled>) -> Self {
|
||||||
|
Self {
|
||||||
|
line: 0,
|
||||||
|
indent,
|
||||||
|
body: BlockBody::Msg(MsgBlock {
|
||||||
|
id,
|
||||||
|
content: MsgContent::Msg { nick, lines },
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn placeholder(indent: usize, id: I) -> Self {
|
||||||
|
Self {
|
||||||
|
line: 0,
|
||||||
|
indent,
|
||||||
|
body: BlockBody::Msg(MsgBlock {
|
||||||
|
id,
|
||||||
|
content: MsgContent::Placeholder,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn height(&self) -> i32 {
|
pub fn height(&self) -> i32 {
|
||||||
match &self.body {
|
match &self.body {
|
||||||
BlockBody::Marker(m) => 0,
|
BlockBody::Marker(m) => 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue