refactor: impl App only once (everything's already in the same file

This commit is contained in:
Muhammad Nauman Raza 2025-02-19 18:02:31 +00:00
parent e0653bf938
commit 682282858c
Signed by untrusted user: devraza
GPG key ID: 91EAD6081011574B

View file

@ -52,6 +52,29 @@ impl Default for App {
}
impl App {
fn render_header(area: Rect, buf: &mut Buffer) {
Block::new()
.title(Line::raw(" txtris ").centered().style(HEADER_STYLE))
.borders(Borders::TOP)
.render(area, buf);
}
fn render_list(&mut self, area: Rect, buf: &mut Buffer) {
let block = Block::new()
.title(Line::raw(" Menu ").centered().style(MENU_HEADER_STYLE))
.borders(Borders::ALL);
let items: Vec<&'static str> = self.menu.items.clone();
let list = List::new(items)
.block(block)
.highlight_style(SELECTED_STYLE)
.highlight_symbol(" ")
.highlight_spacing(HighlightSpacing::Always);
StatefulWidget::render(list, area, buf, &mut self.menu.state);
}
fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
while !self.should_exit {
terminal.draw(|frame| frame.render_widget(&mut self, frame.area()))?;
@ -106,28 +129,3 @@ impl Widget for &mut App {
self.render_list(list_area, buf);
}
}
impl App {
fn render_header(area: Rect, buf: &mut Buffer) {
Block::new()
.title(Line::raw(" txtris ").centered().style(HEADER_STYLE))
.borders(Borders::TOP)
.render(area, buf);
}
fn render_list(&mut self, area: Rect, buf: &mut Buffer) {
let block = Block::new()
.title(Line::raw(" Menu ").centered().style(MENU_HEADER_STYLE))
.borders(Borders::ALL);
let items: Vec<&'static str> = self.menu.items.clone();
let list = List::new(items)
.block(block)
.highlight_style(SELECTED_STYLE)
.highlight_symbol(" ")
.highlight_spacing(HighlightSpacing::Always);
StatefulWidget::render(list, area, buf, &mut self.menu.state);
}
}