mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 01:00:02 +00:00
draft search results widget
This commit is contained in:
parent
1017a405d2
commit
98d2f15136
@ -1,11 +1,13 @@
|
|||||||
mod input;
|
mod input;
|
||||||
mod match_case;
|
mod match_case;
|
||||||
mod navigation;
|
mod navigation;
|
||||||
|
mod result;
|
||||||
mod separator;
|
mod separator;
|
||||||
|
|
||||||
use super::Subject;
|
use super::Subject;
|
||||||
use input::Input;
|
use input::Input;
|
||||||
use navigation::Navigation;
|
use navigation::Navigation;
|
||||||
|
use result::Result;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
prelude::{
|
prelude::{
|
||||||
@ -27,6 +29,7 @@ impl Form {
|
|||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(subject: &Rc<RefCell<Option<Subject>>>) -> Self {
|
pub fn new(subject: &Rc<RefCell<Option<Subject>>>) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
|
let result = Rc::new(Result::new());
|
||||||
let input = Rc::new(Input::new());
|
let input = Rc::new(Input::new());
|
||||||
let match_case = match_case::new();
|
let match_case = match_case::new();
|
||||||
let navigation = Rc::new(Navigation::new());
|
let navigation = Rc::new(Navigation::new());
|
||||||
@ -44,12 +47,15 @@ impl Form {
|
|||||||
g_box.append(&navigation.g_box);
|
g_box.append(&navigation.g_box);
|
||||||
g_box.append(&match_case);
|
g_box.append(&match_case);
|
||||||
g_box.append(&separator);
|
g_box.append(&separator);
|
||||||
|
g_box.append(&result.label);
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
input.entry.connect_changed({
|
input.entry.connect_changed({
|
||||||
let input = input.clone();
|
let input = input.clone();
|
||||||
let match_case = match_case.clone();
|
let match_case = match_case.clone();
|
||||||
let navigation = navigation.clone();
|
let navigation = navigation.clone();
|
||||||
|
let result = result.clone();
|
||||||
|
let separator = separator.clone();
|
||||||
let subject = subject.clone();
|
let subject = subject.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
let matches = find(
|
let matches = find(
|
||||||
@ -57,6 +63,13 @@ impl Form {
|
|||||||
input.entry.text().as_str(),
|
input.entry.text().as_str(),
|
||||||
match_case.is_active(),
|
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());
|
input.update(!matches.is_empty());
|
||||||
navigation.update(matches);
|
navigation.update(matches);
|
||||||
}
|
}
|
||||||
|
40
src/app/browser/window/tab/item/page/search/form/result.rs
Normal file
40
src/app/browser/window/tab/item/page/search/form/result.rs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -8,5 +8,6 @@ pub fn new() -> Separator {
|
|||||||
.margin_end(MARGIN)
|
.margin_end(MARGIN)
|
||||||
.margin_start(MARGIN)
|
.margin_start(MARGIN)
|
||||||
.margin_top(MARGIN)
|
.margin_top(MARGIN)
|
||||||
|
.visible(false)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user