diff --git a/src/app/browser/window/tab/item/page/search/form.rs b/src/app/browser/window/tab/item/page/search/form.rs index d287d4c3..e5f97d9f 100644 --- a/src/app/browser/window/tab/item/page/search/form.rs +++ b/src/app/browser/window/tab/item/page/search/form.rs @@ -1,11 +1,13 @@ mod input; mod match_case; mod navigation; +mod result; mod separator; use super::Subject; use input::Input; use navigation::Navigation; +use result::Result; use gtk::{ prelude::{ @@ -27,6 +29,7 @@ impl Form { /// Create new `Self` pub fn new(subject: &Rc>>) -> Self { // Init components + let result = Rc::new(Result::new()); let input = Rc::new(Input::new()); let match_case = match_case::new(); let navigation = Rc::new(Navigation::new()); @@ -44,12 +47,15 @@ impl Form { g_box.append(&navigation.g_box); g_box.append(&match_case); g_box.append(&separator); + g_box.append(&result.label); // Connect events input.entry.connect_changed({ let input = input.clone(); let match_case = match_case.clone(); let navigation = navigation.clone(); + let result = result.clone(); + let separator = separator.clone(); let subject = subject.clone(); move |_| { let matches = find( @@ -57,6 +63,13 @@ impl Form { input.entry.text().as_str(), match_case.is_active(), ); + if !matches.is_empty() { + result.show(0, matches.len()); + separator.set_visible(true); + } else { + result.hide(); + separator.set_visible(false); + } input.update(!matches.is_empty()); navigation.update(matches); } diff --git a/src/app/browser/window/tab/item/page/search/form/result.rs b/src/app/browser/window/tab/item/page/search/form/result.rs new file mode 100644 index 00000000..d61a1a7f --- /dev/null +++ b/src/app/browser/window/tab/item/page/search/form/result.rs @@ -0,0 +1,40 @@ +use gtk::{prelude::WidgetExt, Label}; + +const MARGIN: i32 = 3; + +pub struct Result { + pub label: Label, +} + +impl Result { + // Constructors + + /// Create new `Self` + pub fn new() -> Self { + Self { + label: Label::builder() + .margin_end(MARGIN) + .margin_start(MARGIN) + .visible(false) + .build(), + } + } + + // Actions + + pub fn show(&self, current: usize, total: usize) { + if total > 0 { + self.label + .set_label(&format!("{current} if {total} matches")); + self.label.remove_css_class("error"); + } else { + self.label.set_label(&format!("Phrase not found")); + self.label.add_css_class("error"); + } + self.label.set_visible(true); + } + + pub fn hide(&self) { + self.label.set_visible(false); + } +} diff --git a/src/app/browser/window/tab/item/page/search/form/separator.rs b/src/app/browser/window/tab/item/page/search/form/separator.rs index 9071d7d7..94b6016d 100644 --- a/src/app/browser/window/tab/item/page/search/form/separator.rs +++ b/src/app/browser/window/tab/item/page/search/form/separator.rs @@ -8,5 +8,6 @@ pub fn new() -> Separator { .margin_end(MARGIN) .margin_start(MARGIN) .margin_top(MARGIN) + .visible(false) .build() }