feat: added a ui/ to hold ui functions

This commit is contained in:
Nickiel12 2023-05-31 21:15:12 -07:00
parent 11e10c0f5e
commit e4a840d7e4
4 changed files with 39 additions and 11 deletions

View file

@ -4,3 +4,5 @@ pub mod app;
pub mod tui; pub mod tui;
pub mod ui; pub mod ui;
pub mod uis;

View file

@ -1,6 +1,4 @@
use std::rc::Rc; use crate::app::App;
use crate::app::{AppResult, App};
use ratatui::{ use ratatui::{
backend::Backend, backend::Backend,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Layout, Rect},
@ -10,6 +8,8 @@ use ratatui::{
Frame, Frame,
}; };
use crate::uis::render_history_tab;
pub fn render<B: Backend> (f: &mut Frame<B>, app: &App) { pub fn render<B: Backend> (f: &mut Frame<B>, app: &App) {
@ -19,24 +19,33 @@ pub fn render<B: Backend> (f: &mut Frame<B>, app: &App) {
.constraints([Constraint::Length(3), Constraint::Min(0)].as_ref()) .constraints([Constraint::Length(3), Constraint::Min(0)].as_ref())
.split(size); .split(size);
let bottom_block = Block::default(); let bottom_block = Block::default()
.borders(Borders::ALL);
f.render_widget(bottom_block, chunks[1]); f.render_widget(bottom_block, chunks[1]);
render_statusbar(f, chunks[0], app); render_statusbar(f, chunks[0], app);
let bottom_chunk = Layout::default()
.direction(Direction::Vertical)
.margin(1)
.constraints([Constraint::Percentage(100)])
.split(chunks[1]);
// if app.tabs selected == history,
render_history_tab(f, bottom_chunk[0], app);
} }
pub fn render_statusbar<B: Backend> (f: &mut Frame<B>, status_rect: Rect, app: &App) { pub fn render_statusbar<B: Backend> (f: &mut Frame<B>, status_rect: Rect, app: &App) {
let status_bar_chunks = Layout::default() let status_bar_chunks = Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Min(10)]) .constraints([Constraint::Percentage(75), Constraint::Min(10)])
.margin(1)
.split(status_rect); .split(status_rect);
let top_block = Block::default() let left_block = Block::default()
.borders(Borders::ALL);
let right_block = Block::default()
.borders(Borders::ALL); .borders(Borders::ALL);
f.render_widget(top_block, status_rect);
let titles = app let titles = app
.tabs .tabs
@ -46,9 +55,10 @@ pub fn render_statusbar<B: Backend> (f: &mut Frame<B>, status_rect: Rect, app: &
.collect(); .collect();
let tabs = Tabs::new(titles) let tabs = Tabs::new(titles)
.block(Block::default().borders(Borders::NONE)) //.block(Block::default().borders(Borders::NONE))
.block(left_block)
.select(app.tab_index) .select(app.tab_index)
.style(Style::default().fg(Color::Cyan)) //.style(Style::default().fg(Color::Cyan))
.highlight_style( .highlight_style(
Style::default() Style::default()
.fg(Color::White) .fg(Color::White)
@ -62,7 +72,7 @@ pub fn render_statusbar<B: Backend> (f: &mut Frame<B>, status_rect: Rect, app: &
Text::styled("Aurora", Text::styled("Aurora",
Style::default().fg(Color::Green) Style::default().fg(Color::Green)
) )
); ).block(right_block);
f.render_widget(connection_paragraph, status_bar_chunks[1]); f.render_widget(connection_paragraph, status_bar_chunks[1]);
} }

12
src/uis/history.rs Normal file
View file

@ -0,0 +1,12 @@
use ratatui::{backend::Backend, Frame, layout::Rect, widgets::Paragraph, text::Text, style::{Style, Color}};
use crate::app::App;
pub fn render_history_tab<B: Backend> (f: &mut Frame<B>, status_rect: Rect, app: &App) {
let connection_paragraph = Paragraph::new(
Text::styled("I'm a ghost!",
Style::default().fg(Color::Green)
)
);
f.render_widget(connection_paragraph, status_rect);
}

4
src/uis/mod.rs Normal file
View file

@ -0,0 +1,4 @@
pub mod history;
pub use self::history::render_history_tab;