allow visualizing enable state in text

this allows us to show whether the text inpout is currently selected in search popup
This commit is contained in:
extrawurst 2023-08-22 13:01:50 +02:00
parent 306ff91afa
commit 30211b2a6b
2 changed files with 17 additions and 2 deletions

View File

@ -57,6 +57,7 @@ impl LogSearchPopupComponent {
false, false,
); );
find_text.embed(); find_text.embed();
find_text.enabled(true);
Self { Self {
queue: queue.clone(), queue: queue.clone(),
@ -248,6 +249,9 @@ impl LogSearchPopupComponent {
Selection::AuthorsSearch => Selection::EnterText, Selection::AuthorsSearch => Selection::EnterText,
}; };
} }
self.find_text
.enabled(matches!(self.selection, Selection::EnterText));
} }
} }

View File

@ -37,6 +37,7 @@ pub struct TextInputComponent {
default_msg: String, default_msg: String,
msg: String, msg: String,
visible: bool, visible: bool,
selected: Option<bool>,
show_char_count: bool, show_char_count: bool,
theme: SharedTheme, theme: SharedTheme,
key_config: SharedKeyConfig, key_config: SharedKeyConfig,
@ -64,6 +65,7 @@ impl TextInputComponent {
show_char_count, show_char_count,
title: title.to_string(), title: title.to_string(),
default_msg: default_msg.to_string(), default_msg: default_msg.to_string(),
selected: None,
cursor_position: 0, cursor_position: 0,
input_type: InputType::Multiline, input_type: InputType::Multiline,
current_area: Cell::new(Rect::default()), current_area: Cell::new(Rect::default()),
@ -102,6 +104,11 @@ impl TextInputComponent {
self.embed = true; self.embed = true;
} }
///
pub fn enabled(&mut self, enable: bool) {
self.selected = Some(enable);
}
/// Move the cursor right one char. /// Move the cursor right one char.
fn incr_cursor(&mut self) { fn incr_cursor(&mut self) {
if let Some(pos) = self.next_char_position() { if let Some(pos) = self.next_char_position() {
@ -229,7 +236,8 @@ impl TextInputComponent {
} }
fn get_draw_text(&self) -> Text { fn get_draw_text(&self) -> Text {
let style = self.theme.text(true, false); let style =
self.theme.text(self.selected.unwrap_or(true), false);
let mut txt = Text::default(); let mut txt = Text::default();
// The portion of the text before the cursor is added // The portion of the text before the cursor is added
@ -367,7 +375,10 @@ impl DrawableComponent for TextInputComponent {
let txt = if self.msg.is_empty() { let txt = if self.msg.is_empty() {
Text::styled( Text::styled(
self.default_msg.as_str(), self.default_msg.as_str(),
self.theme.text(false, false), self.theme.text(
self.selected.unwrap_or_default(),
false,
),
) )
} else { } else {
self.get_draw_text() self.get_draw_text()