Reformat code
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
use std::any::Any;
|
||||
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
|
||||
use crossterm::event::KeyCode::Char;
|
||||
use rat_cursor::HasScreenCursor;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::Frame;
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::prelude::{Color, Line, Span, Style, Text, Widget};
|
||||
use ratatui::widgets::{Block, Borders, Paragraph, StatefulWidget};
|
||||
use crate::config::types::ApplicationConfig;
|
||||
use crate::constants::APP_CONIFG_FILE_PATH;
|
||||
use crate::widgets::popups::folder::AddFolderPopup;
|
||||
use crate::widgets::views::{View};
|
||||
use crate::widgets::views::View;
|
||||
use crossterm::event::KeyCode::Char;
|
||||
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
|
||||
use rat_cursor::HasScreenCursor;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::prelude::{Color, Line, Span, Style, Text, Widget};
|
||||
use ratatui::widgets::{Block, Borders, Paragraph, StatefulWidget};
|
||||
use std::any::Any;
|
||||
|
||||
pub struct MainView {
|
||||
app_config: ApplicationConfig,
|
||||
@@ -27,7 +26,7 @@ pub struct MainViewState {
|
||||
enum Status {
|
||||
Running,
|
||||
Exiting,
|
||||
Popup
|
||||
Popup,
|
||||
}
|
||||
|
||||
impl MainView {
|
||||
@@ -35,9 +34,9 @@ impl MainView {
|
||||
Self {
|
||||
state: MainViewState {
|
||||
popup: None,
|
||||
status: Status::Running
|
||||
status: Status::Running,
|
||||
},
|
||||
app_config: app_conf.clone()
|
||||
app_config: app_conf.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +58,9 @@ impl MainView {
|
||||
|
||||
impl View for MainView {
|
||||
fn handle_input(&mut self, event: &Event) -> color_eyre::Result<()> {
|
||||
if let Some(any) = self.state.popup.as_mut() &&
|
||||
let Some(popup) = any.downcast_mut::<AddFolderPopup>(){
|
||||
if let Some(any) = self.state.popup.as_mut()
|
||||
&& let Some(popup) = any.downcast_mut::<AddFolderPopup>()
|
||||
{
|
||||
popup.textarea.handle_input(event)?;
|
||||
}
|
||||
Ok(())
|
||||
@@ -90,7 +90,7 @@ impl StatefulWidget for MainView {
|
||||
type State = MainViewState;
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)
|
||||
where
|
||||
Self: Sized
|
||||
Self: Sized,
|
||||
{
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
@@ -101,12 +101,13 @@ impl StatefulWidget for MainView {
|
||||
])
|
||||
.split(area);
|
||||
|
||||
Self::render_header(state,chunks[0], buf);
|
||||
Self::render_game_list(state,chunks[1], buf);
|
||||
Self::render_footer(state,chunks[2], buf);
|
||||
Self::render_header(chunks[0], buf);
|
||||
Self::render_game_list(chunks[1], buf);
|
||||
Self::render_footer(state, chunks[2], buf);
|
||||
|
||||
if let Some(boxed) = state.popup.as_mut() &&
|
||||
let Some(popup) = boxed.downcast_mut::<AddFolderPopup>() {
|
||||
if let Some(boxed) = state.popup.as_mut()
|
||||
&& let Some(popup) = boxed.downcast_mut::<AddFolderPopup>()
|
||||
{
|
||||
popup.clone().render(area, buf, popup);
|
||||
}
|
||||
}
|
||||
@@ -114,16 +115,17 @@ impl StatefulWidget for MainView {
|
||||
|
||||
impl HasScreenCursor for MainView {
|
||||
fn screen_cursor(&self) -> Option<(u16, u16)> {
|
||||
if let Some(popup) = &self.state.popup &&
|
||||
let Some(add_folder) = popup.downcast_ref::<AddFolderPopup>() {
|
||||
return add_folder.textarea.screen_cursor()
|
||||
if let Some(popup) = &self.state.popup
|
||||
&& let Some(add_folder) = popup.downcast_ref::<AddFolderPopup>()
|
||||
{
|
||||
return add_folder.textarea.screen_cursor();
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl MainView {
|
||||
fn render_game_list(state: &mut MainViewState, area: Rect, buf: &mut Buffer) {
|
||||
fn render_game_list(area: Rect, buf: &mut Buffer) {
|
||||
let game_list = Block::new()
|
||||
.title(Line::raw("Games"))
|
||||
.borders(Borders::ALL)
|
||||
@@ -131,20 +133,19 @@ impl MainView {
|
||||
game_list.render(area, buf);
|
||||
}
|
||||
|
||||
fn render_header(state: &mut MainViewState, area: Rect, buf: &mut Buffer) {
|
||||
let title = Paragraph::new(
|
||||
Text::styled(
|
||||
"SuS Manager",
|
||||
Style::default().fg(Color::Green),
|
||||
)
|
||||
);
|
||||
fn render_header(area: Rect, buf: &mut Buffer) {
|
||||
let title = Paragraph::new(Text::styled(
|
||||
"SuS Manager",
|
||||
Style::default().fg(Color::Green),
|
||||
));
|
||||
title.render(area, buf);
|
||||
}
|
||||
|
||||
fn render_footer(state: &mut MainViewState, area: Rect, buf: &mut Buffer) {
|
||||
let mut navigation_text = vec![
|
||||
Span::styled("(q) quit / (a) add folders", Style::default().fg(Color::Green)),
|
||||
];
|
||||
let mut navigation_text = vec![Span::styled(
|
||||
"(q) quit / (a) add folders",
|
||||
Style::default().fg(Color::Green),
|
||||
)];
|
||||
if matches!(state.status, Status::Popup) {
|
||||
navigation_text[0] = Span::styled("(Esc) close", Style::default().fg(Color::Green));
|
||||
}
|
||||
@@ -152,4 +153,4 @@ impl MainView {
|
||||
let footer = Paragraph::new(line);
|
||||
footer.render(area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user