[WIP] Console Box for Main UI
This commit is contained in:
parent
9416a9744f
commit
b8658e84b9
9 changed files with 409 additions and 19 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use crate::gui::elements::elements::InteractableElement;
|
||||
use crate::gui::elements::elements::{InteractableElement, JoinableElement};
|
||||
use crate::gui::interaction_result::InteractionResult;
|
||||
use crate::gui::util::borders::draw_block_joins;
|
||||
use crate::{APP_STATE, gui::elements::elements::Element};
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use ratatui::{
|
||||
|
|
@ -20,6 +21,9 @@ pub struct UiLogEntry {
|
|||
pub struct LogCard {
|
||||
focused: bool,
|
||||
scroll: u16,
|
||||
|
||||
pub borders: Borders,
|
||||
pub joins: Borders,
|
||||
}
|
||||
|
||||
impl LogCard {
|
||||
|
|
@ -27,6 +31,8 @@ impl LogCard {
|
|||
Self {
|
||||
focused: false,
|
||||
scroll: 0,
|
||||
borders: Borders::ALL,
|
||||
joins: Borders::NONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -49,8 +55,12 @@ impl Element for LogCard {
|
|||
.collect();
|
||||
|
||||
let block = Block::default()
|
||||
.title("Logs")
|
||||
.borders(Borders::ALL)
|
||||
.title(if self.focused {
|
||||
"Logs J/K to scroll"
|
||||
} else {
|
||||
"Logs"
|
||||
})
|
||||
.borders(self.borders)
|
||||
.border_style(if self.focused {
|
||||
Style::default().fg(Color::Yellow)
|
||||
} else {
|
||||
|
|
@ -63,6 +73,32 @@ impl Element for LogCard {
|
|||
.scroll((self.scroll, 0));
|
||||
|
||||
f.render_widget(paragraph, area);
|
||||
draw_block_joins(f, area, self.borders, self.joins);
|
||||
}
|
||||
}
|
||||
impl JoinableElement for LogCard {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_element(&self) -> &dyn Element {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_element_mut(&mut self) -> &mut dyn Element {
|
||||
self
|
||||
}
|
||||
|
||||
fn set_borders(&mut self, borders: Borders) {
|
||||
self.borders = borders;
|
||||
}
|
||||
|
||||
fn set_joins(&mut self, joins: Borders) {
|
||||
self.joins = joins;
|
||||
}
|
||||
}
|
||||
impl InteractableElement for LogCard {
|
||||
|
|
@ -84,13 +120,13 @@ impl InteractableElement for LogCard {
|
|||
|
||||
fn interact(&mut self, key: KeyEvent) -> InteractionResult {
|
||||
match key.code {
|
||||
KeyCode::Up => {
|
||||
KeyCode::Char('J') | KeyCode::Char('j') => {
|
||||
if self.scroll > 0 {
|
||||
self.scroll -= 1;
|
||||
}
|
||||
InteractionResult::Handled
|
||||
}
|
||||
KeyCode::Down => {
|
||||
KeyCode::Char('K') | KeyCode::Char('k') => {
|
||||
self.scroll += 1;
|
||||
InteractionResult::Handled
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue