WIP: current view highlight
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use crate::modules::source::{FileDatabase, Word, WordSource};
|
use crate::modules::source::{FileDatabase, Word, WordSource};
|
||||||
|
use crate::modules::ui::app::UiState::FILTERLANG;
|
||||||
use crate::modules::ui::handler::handle_user_input;
|
use crate::modules::ui::handler::handle_user_input;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
DefaultTerminal, Frame,
|
DefaultTerminal, Frame,
|
||||||
@@ -82,7 +83,7 @@ impl App {
|
|||||||
.constraints(vec![
|
.constraints(vec![
|
||||||
Constraint::Length(3),
|
Constraint::Length(3),
|
||||||
Constraint::Fill(1),
|
Constraint::Fill(1),
|
||||||
Constraint::Length(3),
|
Constraint::Length(1),
|
||||||
])
|
])
|
||||||
.split(frame.area());
|
.split(frame.area());
|
||||||
|
|
||||||
@@ -103,8 +104,11 @@ impl App {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new(word_filter.clone())
|
Paragraph::new(word_filter.clone()).block(
|
||||||
.block(Block::new().title("Word").borders(Borders::ALL)),
|
Block::new()
|
||||||
|
.title(self.format_ui_block_title("Word", UiState::FILTERWORD))
|
||||||
|
.borders(Borders::ALL),
|
||||||
|
),
|
||||||
filters_layout[0],
|
filters_layout[0],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -116,7 +120,11 @@ impl App {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
frame.render_widget(
|
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],
|
filters_layout[1],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -136,21 +144,38 @@ impl App {
|
|||||||
lang: "".to_string(),
|
lang: "".to_string(),
|
||||||
});
|
});
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new(word_to_add.key)
|
Paragraph::new(word_to_add.key).block(
|
||||||
.block(Block::new().title("Word").borders(Borders::ALL)),
|
Block::new()
|
||||||
|
.title(self.format_add_block_title("Word", AddState::KEY))
|
||||||
|
.borders(Borders::ALL),
|
||||||
|
),
|
||||||
add_words_heading_layout[0],
|
add_words_heading_layout[0],
|
||||||
);
|
);
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new(word_to_add.lang)
|
Paragraph::new(word_to_add.lang).block(
|
||||||
.block(Block::new().title("Lang").borders(Borders::ALL)),
|
Block::new()
|
||||||
|
.title(self.format_add_block_title("Lang", AddState::LANG))
|
||||||
|
.borders(Borders::ALL),
|
||||||
|
),
|
||||||
add_words_heading_layout[1],
|
add_words_heading_layout[1],
|
||||||
);
|
);
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new(word_to_add.description)
|
Paragraph::new(word_to_add.description).block(
|
||||||
.block(Block::new().title("Description").borders(Borders::ALL)),
|
Block::new()
|
||||||
|
.title(self.format_add_block_title("Description", AddState::DESCRIPTION))
|
||||||
|
.borders(Borders::ALL),
|
||||||
|
),
|
||||||
main_layout[1],
|
main_layout[1],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
let highligh_symbol: &str = {
|
||||||
|
if self.state == UiState::LIST {
|
||||||
|
"> "
|
||||||
|
} else {
|
||||||
|
" "
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let words_layout =
|
let words_layout =
|
||||||
Layout::horizontal(vec![Constraint::Percentage(30), Constraint::Percentage(70)])
|
Layout::horizontal(vec![Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||||
.split(main_layout[1]);
|
.split(main_layout[1]);
|
||||||
@@ -165,12 +190,12 @@ impl App {
|
|||||||
.direction(ListDirection::TopToBottom)
|
.direction(ListDirection::TopToBottom)
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.title("Entries")
|
.title(self.format_ui_block_title("Entries", UiState::LIST))
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.padding(Padding::horizontal(1)),
|
.padding(Padding::horizontal(1)),
|
||||||
)
|
)
|
||||||
.highlight_style(Style::default().fg(Color::default()))
|
.highlight_style(Style::default().fg(Color::default()))
|
||||||
.highlight_symbol("> ")
|
.highlight_symbol(highligh_symbol)
|
||||||
.style(Style::default().fg(Color::DarkGray));
|
.style(Style::default().fg(Color::DarkGray));
|
||||||
frame.render_stateful_widget(word_key_list, words_layout[0], &mut self.list_state);
|
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);
|
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) {
|
pub fn update_word_list(&mut self) {
|
||||||
@@ -231,6 +264,26 @@ impl App {
|
|||||||
self.word_list = word_list;
|
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<()> {
|
fn handle_events(&mut self) -> io::Result<()> {
|
||||||
return handle_user_input(self);
|
return handle_user_input(self);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user