remove extra getters, give name to gobjects

This commit is contained in:
yggverse 2024-12-05 21:17:32 +02:00
parent 36d4673d44
commit 2799ce37fe
16 changed files with 76 additions and 180 deletions

View file

@ -2,12 +2,11 @@ mod widget;
use widget::Widget;
use adw::PasswordEntryRow;
use gtk::{gio::SimpleAction, glib::GString};
use gtk::gio::SimpleAction;
use std::rc::Rc;
pub struct Form {
widget: Rc<Widget>,
pub widget: Rc<Widget>,
}
impl Form {
@ -19,18 +18,4 @@ impl Form {
// Result
Self { widget }
}
// Actions
pub fn focus(&self) {
self.widget.focus();
}
// Getters
pub fn text(&self) -> GString {
self.widget.text()
}
pub fn gobject(&self) -> &PasswordEntryRow {
self.widget.gobject()
}
}

View file

@ -2,51 +2,33 @@ use adw::{
prelude::{EntryRowExt, PreferencesRowExt},
PasswordEntryRow,
};
use gtk::{
gio::SimpleAction,
glib::GString,
prelude::{ActionExt, EditableExt, WidgetExt},
};
use gtk::{gio::SimpleAction, prelude::ActionExt};
pub struct Widget {
gobject: PasswordEntryRow,
pub password_entry_row: PasswordEntryRow,
}
impl Widget {
// Construct
pub fn new(action_send: SimpleAction, title: Option<&str>, _max_length: Option<i32>) -> Self {
// Init gobject
let gobject = PasswordEntryRow::builder().show_apply_button(true).build();
// Init main widget
let password_entry_row = PasswordEntryRow::builder().show_apply_button(true).build();
if let Some(value) = title {
gobject.set_title(value);
password_entry_row.set_title(value);
}
/* @TODO adw 1.6 / ubuntu 24.10+
if let Some(value) = max_length {
gobject.set_max_length(value);
password_entry_row.set_max_length(value);
} */
// Init events
gobject.connect_apply(move |_| {
password_entry_row.connect_apply(move |_| {
action_send.activate(None);
});
// Return activated struct
Self { gobject }
}
// Actions
pub fn focus(&self) {
self.gobject.grab_focus();
}
// Getters
pub fn text(&self) -> GString {
self.gobject.text()
}
pub fn gobject(&self) -> &PasswordEntryRow {
&self.gobject
Self { password_entry_row }
}
}