use modern (2018) pattern for modules

This commit is contained in:
yggverse 2024-09-27 22:36:22 +03:00
parent 1627902b8f
commit cdc3fe3388
28 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,69 @@
use gtk::{
glib::GString,
prelude::{EditableExt, EntryExt, WidgetExt},
Entry,
};
pub struct Request {
widget: Entry,
}
impl Request {
// Construct
pub fn new(text: Option<GString>) -> Self {
// GTK
let widget = Entry::builder()
.placeholder_text("URL or search term...")
.hexpand(true)
.progress_fraction(0.0)
.progress_pulse_step(0.1)
.text(match text {
Some(text) => text,
None => GString::new(),
})
.build();
// Connect events
widget.connect_changed(|entry| {
entry
.activate_action("win.update", None)
.expect("Action `win.update` not found")
});
widget.connect_activate(|entry| {
entry
.activate_action("win.tab_page_reload", None)
.expect("Action `win.tab_page_reload` not found")
});
// Result
Self { widget }
}
// Actions
pub fn update(&self) {
// @TODO animate progress fraction
}
// Setters
pub fn set_text(&self, value: &GString, activate: bool) {
self.widget.set_text(value);
if activate {
self.widget.emit_activate();
}
}
// Getters
pub fn widget(&self) -> &Entry {
&self.widget
}
pub fn is_empty(&self) -> bool {
0 == self.widget.text_length()
}
pub fn text(&self) -> GString {
self.widget.text()
}
}