[Add] Main UI with LogCard
This commit is contained in:
parent
bac1c608fe
commit
9416a9744f
17 changed files with 214 additions and 712 deletions
|
|
@ -1,21 +1,30 @@
|
|||
use std::{any::Any, sync::Arc};
|
||||
|
||||
use crate::gui::{
|
||||
elements::{
|
||||
elements::{Element, InteractableElement},
|
||||
log_card::LogCard,
|
||||
},
|
||||
interaction_result::InteractionResult,
|
||||
screens::screens::Screen,
|
||||
ui::UI,
|
||||
};
|
||||
use crossterm::event::KeyEvent;
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::Rect,
|
||||
layout::{Constraint, Layout, Margin, Rect},
|
||||
widgets::{Block, Borders},
|
||||
};
|
||||
|
||||
use crate::gui::{interaction_result::InteractionResult, screens::screens::Screen, ui::UI};
|
||||
use std::{any::Any, sync::Arc};
|
||||
|
||||
pub struct MainScreen {
|
||||
ui: Arc<UI>,
|
||||
log_card: LogCard,
|
||||
}
|
||||
|
||||
impl MainScreen {
|
||||
pub async fn new(ui: Arc<UI>) -> Self {
|
||||
MainScreen { ui }
|
||||
let mut log_card = LogCard::new();
|
||||
log_card.focus(true);
|
||||
MainScreen { ui, log_card }
|
||||
}
|
||||
}
|
||||
impl Screen for MainScreen {
|
||||
|
|
@ -32,10 +41,25 @@ impl Screen for MainScreen {
|
|||
}
|
||||
|
||||
fn render(&self, f: &mut Frame, rect: Rect) {
|
||||
f.render_widget(Block::default().title("Main").borders(Borders::ALL), rect);
|
||||
let main_block = Block::default().title("Main").borders(Borders::ALL);
|
||||
|
||||
f.render_widget(main_block, rect);
|
||||
|
||||
let inner = rect.inner(Margin {
|
||||
vertical: 1,
|
||||
horizontal: 1,
|
||||
});
|
||||
|
||||
let chunks = Layout::vertical([Constraint::Min(0)]).split(inner);
|
||||
|
||||
self.log_card.render(f, chunks[0]);
|
||||
}
|
||||
|
||||
fn handle_input(&mut self, event: KeyEvent) -> InteractionResult {
|
||||
if self.log_card.is_focused() {
|
||||
return self.log_card.interact(event);
|
||||
}
|
||||
|
||||
InteractionResult::Unhandled
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue