Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui/table): Highlight the filter form only when it is active and in input mode #436

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ui/widget/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,10 @@ impl RenderTrait for Table<'_> {
self.widget_config.clone()
};

let block = widget_config.render_block(self.can_activate() && is_active, is_mouse_over);
let block = widget_config.render_block(
self.can_activate() && !self.mode.is_filter_input() && is_active,
is_mouse_over,
);

let constraints = constraints(self.items.digits());

Expand Down
15 changes: 8 additions & 7 deletions src/ui/widget/table/filter_form.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crossterm::event::KeyEvent;
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
widgets::{Block, BorderType, Borders, Paragraph},
widgets::{Block, Paragraph},
Frame,
};

Expand All @@ -18,7 +18,7 @@ struct Chunk {

#[derive(Debug)]
pub struct FilterForm {
block: Block<'static>,
widget_config: WidgetConfig,
input_widget: InputForm,
chunk: Chunk,
layout: Layout,
Expand All @@ -27,9 +27,7 @@ pub struct FilterForm {
impl Default for FilterForm {
fn default() -> Self {
Self {
block: Block::default()
.border_type(BorderType::Plain)
.borders(Borders::ALL),
widget_config: WidgetConfig::default(),
input_widget: InputForm::new(WidgetConfig::builder().block(Block::default()).build()),
chunk: Chunk::default(),
layout: Layout::default()
Expand All @@ -46,7 +44,7 @@ impl FilterForm {
pub fn update_chunk(&mut self, chunk: Rect) {
let block_chunk = Rect::new(chunk.x, chunk.y, chunk.width, FILTER_HEIGHT);

let inner_chunk = self.block.inner(block_chunk);
let inner_chunk = self.widget_config.block().inner(block_chunk);

let chunks = self.layout.split(inner_chunk);

Expand Down Expand Up @@ -75,7 +73,10 @@ impl FilterForm {
}

pub fn render(&mut self, f: &mut Frame<'_>, is_active: bool) {
f.render_widget(self.block.clone(), self.chunk.block);
f.render_widget(
self.widget_config.render_block(is_active, false),
self.chunk.block,
);

f.render_widget(Paragraph::new("FILTER: "), self.chunk.header);

Expand Down