Fix rendering of editor and pseudo message
This commit is contained in:
parent
e6e6bcaf31
commit
18573e5a37
4 changed files with 53 additions and 27 deletions
|
|
@ -3,7 +3,6 @@ use toss::frame::Frame;
|
||||||
use crate::store::{Msg, MsgStore, Path, Tree};
|
use crate::store::{Msg, MsgStore, Path, Tree};
|
||||||
use crate::ui::chat::blocks::Block;
|
use crate::ui::chat::blocks::Block;
|
||||||
use crate::ui::widgets::empty::Empty;
|
use crate::ui::widgets::empty::Empty;
|
||||||
use crate::ui::widgets::text::Text;
|
|
||||||
use crate::ui::ChatMsg;
|
use crate::ui::ChatMsg;
|
||||||
|
|
||||||
use super::tree_blocks::{BlockId, Root, TreeBlocks};
|
use super::tree_blocks::{BlockId, Root, TreeBlocks};
|
||||||
|
|
@ -73,7 +72,7 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
) {
|
) {
|
||||||
// Ghost cursor in front, for positioning according to last cursor line
|
// Ghost cursor in front, for positioning according to last cursor line
|
||||||
if self.last_cursor.refers_to(id) {
|
if self.last_cursor.refers_to(id) {
|
||||||
let block = Block::new(frame, BlockId::LastCursor, Empty);
|
let block = Block::new(frame, BlockId::LastCursor, Empty::new());
|
||||||
blocks.blocks_mut().push_back(block);
|
blocks.blocks_mut().push_back(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,24 +95,25 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
|
|
||||||
// Trailing ghost cursor, for positioning according to last cursor line
|
// Trailing ghost cursor, for positioning according to last cursor line
|
||||||
if self.last_cursor.refers_to_last_child_of(id) {
|
if self.last_cursor.refers_to_last_child_of(id) {
|
||||||
let block = Block::new(frame, BlockId::LastCursor, Empty);
|
let block = Block::new(frame, BlockId::LastCursor, Empty::new());
|
||||||
blocks.blocks_mut().push_back(block);
|
blocks.blocks_mut().push_back(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trailing editor or pseudomessage
|
// Trailing editor or pseudomessage
|
||||||
if self.cursor.refers_to_last_child_of(id) {
|
if self.cursor.refers_to_last_child_of(id) {
|
||||||
match self.cursor {
|
match self.cursor {
|
||||||
Cursor::Editor { .. } => blocks
|
Cursor::Editor { .. } => {
|
||||||
.blocks_mut()
|
blocks
|
||||||
.push_back(self.editor_block(nick, frame, indent)),
|
.blocks_mut()
|
||||||
Cursor::Pseudo { .. } => blocks
|
.push_back(self.editor_block(nick, frame, indent + 1))
|
||||||
.blocks_mut()
|
}
|
||||||
.push_back(self.pseudo_block(nick, frame, indent)),
|
Cursor::Pseudo { .. } => {
|
||||||
|
blocks
|
||||||
|
.blocks_mut()
|
||||||
|
.push_back(self.pseudo_block(nick, frame, indent + 1))
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
// TODO Render proper editor or pseudocursor
|
|
||||||
let block = Block::new(frame, BlockId::Cursor, Text::new("TODO"));
|
|
||||||
blocks.blocks_mut().push_back(block);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,13 +131,13 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
if let Cursor::Editor { parent: None, .. } | Cursor::Pseudo { parent: None, .. } =
|
if let Cursor::Editor { parent: None, .. } | Cursor::Pseudo { parent: None, .. } =
|
||||||
self.last_cursor
|
self.last_cursor
|
||||||
{
|
{
|
||||||
let block = Block::new(frame, BlockId::LastCursor, Empty);
|
let block = Block::new(frame, BlockId::LastCursor, Empty::new());
|
||||||
blocks.blocks_mut().push_back(block);
|
blocks.blocks_mut().push_back(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.cursor {
|
match self.cursor {
|
||||||
Cursor::Bottom => {
|
Cursor::Bottom => {
|
||||||
let block = Block::new(frame, BlockId::Cursor, Empty);
|
let block = Block::new(frame, BlockId::Cursor, Empty::new());
|
||||||
blocks.blocks_mut().push_back(block);
|
blocks.blocks_mut().push_back(block);
|
||||||
}
|
}
|
||||||
Cursor::Editor { parent: None, .. } => blocks
|
Cursor::Editor { parent: None, .. } => blocks
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ use time::macros::format_description;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::ui::widgets::background::Background;
|
use crate::ui::widgets::background::Background;
|
||||||
|
use crate::ui::widgets::empty::Empty;
|
||||||
use crate::ui::widgets::text::Text;
|
use crate::ui::widgets::text::Text;
|
||||||
use crate::ui::widgets::BoxedWidget;
|
use crate::ui::widgets::BoxedWidget;
|
||||||
|
|
||||||
const TIME_FORMAT: &[FormatItem<'_>] = format_description!("[year]-[month]-[day] [hour]:[minute]");
|
const TIME_FORMAT: &[FormatItem<'_>] = format_description!("[year]-[month]-[day] [hour]:[minute]");
|
||||||
const TIME_EMPTY: &str = " ";
|
const TIME_WIDTH: u16 = 16;
|
||||||
|
|
||||||
fn style() -> ContentStyle {
|
fn style() -> ContentStyle {
|
||||||
ContentStyle::default().grey()
|
ContentStyle::default().grey()
|
||||||
|
|
@ -19,19 +20,20 @@ fn style_inverted() -> ContentStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn widget(time: Option<OffsetDateTime>, highlighted: bool) -> BoxedWidget {
|
pub fn widget(time: Option<OffsetDateTime>, highlighted: bool) -> BoxedWidget {
|
||||||
let text = if let Some(time) = time {
|
|
||||||
time.format(TIME_FORMAT).expect("could not format time")
|
|
||||||
} else {
|
|
||||||
TIME_EMPTY.to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
let style = if highlighted {
|
let style = if highlighted {
|
||||||
style_inverted()
|
style_inverted()
|
||||||
} else {
|
} else {
|
||||||
style()
|
style()
|
||||||
};
|
};
|
||||||
|
|
||||||
Background::new(Text::new((text, style)))
|
if let Some(time) = time {
|
||||||
.style(style)
|
let text = time.format(TIME_FORMAT).expect("could not format time");
|
||||||
.into()
|
Background::new(Text::new((text, style)))
|
||||||
|
.style(style)
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
Background::new(Empty::new().width(TIME_WIDTH))
|
||||||
|
.style(style)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ impl EuphRoom {
|
||||||
let heading_style = ContentStyle::new().bold();
|
let heading_style = ContentStyle::new().bold();
|
||||||
|
|
||||||
if !list.is_empty() {
|
if !list.is_empty() {
|
||||||
list.add_unsel(Empty);
|
list.add_unsel(Empty::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let row = Styled::new(name, heading_style).then_plain(format!(" ({})", sessions.len()));
|
let row = Styled::new(name, heading_style).then_plain(format!(" ({})", sessions.len()));
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,36 @@ use toss::frame::{Frame, Size};
|
||||||
|
|
||||||
use super::Widget;
|
use super::Widget;
|
||||||
|
|
||||||
pub struct Empty;
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
|
pub struct Empty {
|
||||||
|
size: Size,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Empty {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { size: Size::ZERO }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn width(mut self, width: u16) -> Self {
|
||||||
|
self.size.width = width;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn height(mut self, height: u16) -> Self {
|
||||||
|
self.size.height = height;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(mut self, size: Size) -> Self {
|
||||||
|
self.size = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Widget for Empty {
|
impl Widget for Empty {
|
||||||
fn size(&self, _frame: &mut Frame, _max_width: Option<u16>, _max_height: Option<u16>) -> Size {
|
fn size(&self, _frame: &mut Frame, _max_width: Option<u16>, _max_height: Option<u16>) -> Size {
|
||||||
Size::ZERO
|
self.size
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn render(self: Box<Self>, _frame: &mut Frame) {}
|
async fn render(self: Box<Self>, _frame: &mut Frame) {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue