WIP: current view highlight

This commit is contained in:
2026-08-05 15:58:56 +02:00
parent c0b6ec1f97
commit 844fc57f1a

View File

@@ -1,4 +1,5 @@
use crate::modules::source::{FileDatabase, Word, WordSource};
use crate::modules::ui::app::UiState::FILTERLANG;
use crate::modules::ui::handler::handle_user_input;
use ratatui::{
DefaultTerminal, Frame,
@@ -82,7 +83,7 @@ impl App {
.constraints(vec![
Constraint::Length(3),
Constraint::Fill(1),
Constraint::Length(3),
Constraint::Length(1),
])
.split(frame.area());
@@ -103,8 +104,11 @@ impl App {
}
};
frame.render_widget(
Paragraph::new(word_filter.clone())
.block(Block::new().title("Word").borders(Borders::ALL)),
Paragraph::new(word_filter.clone()).block(
Block::new()
.title(self.format_ui_block_title("Word", UiState::FILTERWORD))
.borders(Borders::ALL),
),
filters_layout[0],
);
@@ -116,7 +120,11 @@ impl App {
}
};
frame.render_widget(
Paragraph::new(lang_filter).block(Block::new().title("Lang").borders(Borders::ALL)),
Paragraph::new(lang_filter).block(
Block::new()
.title(self.format_ui_block_title("Lang", UiState::FILTERLANG))
.borders(Borders::ALL),
),
filters_layout[1],
);
@@ -136,21 +144,38 @@ impl App {
lang: "".to_string(),
});
frame.render_widget(
Paragraph::new(word_to_add.key)
.block(Block::new().title("Word").borders(Borders::ALL)),
Paragraph::new(word_to_add.key).block(
Block::new()
.title(self.format_add_block_title("Word", AddState::KEY))
.borders(Borders::ALL),
),
add_words_heading_layout[0],
);
frame.render_widget(
Paragraph::new(word_to_add.lang)
.block(Block::new().title("Lang").borders(Borders::ALL)),
Paragraph::new(word_to_add.lang).block(
Block::new()
.title(self.format_add_block_title("Lang", AddState::LANG))
.borders(Borders::ALL),
),
add_words_heading_layout[1],
);
frame.render_widget(
Paragraph::new(word_to_add.description)
.block(Block::new().title("Description").borders(Borders::ALL)),
Paragraph::new(word_to_add.description).block(
Block::new()
.title(self.format_add_block_title("Description", AddState::DESCRIPTION))
.borders(Borders::ALL),
),
main_layout[1],
);
} else {
let highligh_symbol: &str = {
if self.state == UiState::LIST {
"> "
} else {
" "
}
};
let words_layout =
Layout::horizontal(vec![Constraint::Percentage(30), Constraint::Percentage(70)])
.split(main_layout[1]);
@@ -165,12 +190,12 @@ impl App {
.direction(ListDirection::TopToBottom)
.block(
Block::default()
.title("Entries")
.title(self.format_ui_block_title("Entries", UiState::LIST))
.borders(Borders::ALL)
.padding(Padding::horizontal(1)),
)
.highlight_style(Style::default().fg(Color::default()))
.highlight_symbol("> ")
.highlight_symbol(highligh_symbol)
.style(Style::default().fg(Color::DarkGray));
frame.render_stateful_widget(word_key_list, words_layout[0], &mut self.list_state);
@@ -209,6 +234,14 @@ impl App {
);
frame.render_widget(help_text, help_area);
/*
* State block
* */
// let state_layout = Layout::horizontal(vec![Constraint::Fill(1)])
// .flex(Flex::Center)
// .split(main_layout[2]);
// frame.render_widget(help_text, help_area);
}
pub fn update_word_list(&mut self) {
@@ -231,6 +264,26 @@ impl App {
self.word_list = word_list;
}
fn format_ui_block_title(&self, input: &str, matching_state: UiState) -> String {
if matching_state == self.state {
let mut result = input.to_string();
result.push_str("");
result
} else {
input.to_string()
}
}
fn format_add_block_title(&self, input: &str, matching_state: AddState) -> String {
if matching_state == self.add_state {
let mut result = input.to_string();
result.push_str("");
result
} else {
input.to_string()
}
}
fn handle_events(&mut self) -> io::Result<()> {
return handle_user_input(self);
}