From bb310277452568bf2089230be084001fc0c5291a Mon Sep 17 00:00:00 2001 From: kosay Date: Wed, 22 Nov 2023 02:26:17 +0900 Subject: [PATCH] feat(ui): Improve highlighting logic for active components. --- src/ui/widget/table.rs | 8 ++++++-- src/ui/widget/table/filter_form.rs | 15 ++++++++------- src/ui/widget/text.rs | 5 +++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/ui/widget/table.rs b/src/ui/widget/table.rs index cab4d5c0..e50603b1 100644 --- a/src/ui/widget/table.rs +++ b/src/ui/widget/table.rs @@ -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()); @@ -656,7 +659,8 @@ impl RenderTrait for Table<'_> { } Mode::FilterInput | Mode::FilterConfirm => { - self.filter_widget.render(f, self.mode.is_filter_input()); + self.filter_widget + .render(f, self.mode.is_filter_input() && is_active); f.render_stateful_widget(widget, self.chunk(), &mut self.state); } diff --git a/src/ui/widget/table/filter_form.rs b/src/ui/widget/table/filter_form.rs index ec6016f1..1f16dd29 100644 --- a/src/ui/widget/table/filter_form.rs +++ b/src/ui/widget/table/filter_form.rs @@ -1,7 +1,7 @@ use crossterm::event::KeyEvent; use ratatui::{ layout::{Constraint, Direction, Layout, Rect}, - widgets::{Block, BorderType, Borders, Paragraph}, + widgets::{Block, Paragraph}, Frame, }; @@ -18,7 +18,7 @@ struct Chunk { #[derive(Debug)] pub struct FilterForm { - block: Block<'static>, + widget_config: WidgetConfig, input_widget: InputForm, chunk: Chunk, layout: Layout, @@ -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() @@ -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); @@ -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); diff --git a/src/ui/widget/text.rs b/src/ui/widget/text.rs index 92bf5b74..7b4f173f 100644 --- a/src/ui/widget/text.rs +++ b/src/ui/widget/text.rs @@ -30,7 +30,8 @@ use crate::{ use self::{ highlight_content::{HighlightArea, HighlightContent, Point}, item::TextItem, - render::{Render, Scroll}, search_form::SearchForm, + render::{Render, Scroll}, + search_form::SearchForm, }; use super::{ @@ -814,7 +815,7 @@ impl RenderTrait for Text { self.search_widget.render( f, - self.mode.is_search_input(), + self.mode.is_search_input() && is_active, self.item.highlight_status(), ); }