feat: main layout implemented with 0 logic

This commit is contained in:
2026-08-01 18:36:36 +02:00
parent cbbf83363e
commit 8ba68fc98c

View File

@@ -1,10 +1,16 @@
use crate::modules::source::FileDatabase; use crate::modules::source::FileDatabase;
use crossterm::event::{
self,
Event::{self, Key},
};
use ratatui::{ use ratatui::{
DefaultTerminal, Frame, DefaultTerminal, Frame,
layout::{Constraint, Direction, Layout}, layout::{Constraint, Direction, Flex, Layout},
widgets::Paragraph, style::{Color, Style},
text::Text,
widgets::{Block, Borders, Padding, Paragraph},
}; };
use std::io::{self}; use std::io;
pub enum UiState { pub enum UiState {
LIST, LIST,
@@ -39,22 +45,81 @@ impl App {
pub fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> { pub fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> {
while !self.exit { while !self.exit {
terminal.draw(|frame| self.draw(frame))?; terminal.draw(|frame| self.draw(frame))?;
// self.handle_events()?; let event_result = self.handle_events();
if let Err(_) = event_result {
break;
}
} }
Ok(()) Ok(())
} }
fn draw(&self, frame: &mut Frame) { fn draw(&self, frame: &mut Frame) {
let main_layout = Layout::default() let main_layout = Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Vertical)
.spacing(0)
.margin(1) .margin(1)
.constraints(vec![Constraint::Max(10)]) .constraints(vec![
Constraint::Length(3),
Constraint::Fill(1),
Constraint::Length(3),
])
.split(frame.area()); .split(frame.area());
frame.render_widget(Paragraph::new("Word filter"), main_layout[0]); let filters_layout = Layout::default()
.direction(Direction::Horizontal)
.spacing(1)
.constraints(vec![Constraint::Fill(1), Constraint::Length(8)])
.split(main_layout[0]);
let words_layout =
Layout::horizontal(vec![Constraint::Percentage(30), Constraint::Percentage(70)])
.split(main_layout[1]);
let help_layout = Layout::horizontal(vec![Constraint::Fill(1)])
.flex(Flex::Center)
.split(main_layout[2]);
frame.render_widget(
Paragraph::new("test word").block(Block::new().title("Word").borders(Borders::ALL)),
filters_layout[0],
);
frame.render_widget(
Paragraph::new("en").block(Block::new().title("Lang").borders(Borders::ALL)),
filters_layout[1],
);
frame.render_widget(
Paragraph::new("Word list").block(Block::new().borders(Borders::ALL).title("Entries")),
words_layout[0],
);
frame.render_widget(
Paragraph::new("Selected word description").block(Block::new().borders(Borders::ALL)),
words_layout[1],
);
let help_text = Text::raw("(m)ove | (f)ilter | (d)elete | (e)dit | (a)dd | (q)uit ")
.style(Style::new().fg(Color::DarkGray));
let help_area = help_layout[0].centered(
Constraint::Length(help_text.width() as u16),
Constraint::Length(1),
);
frame.render_widget(help_text, help_area);
} }
// fn handle_events(&mut self) -> io::Result<()> { fn handle_events(&mut self) -> io::Result<()> {
// todo!() if let Event::Key(key) = event::read()? {
// } match key.code {
event::KeyCode::Char(c) => {
if c == 'q' {
return Err(io::Error::last_os_error()); // FIXME: this is not right
}
}
_ => return Ok(()),
}
}
Ok(())
}
} }