add sensitive input status code support

This commit is contained in:
yggverse 2024-10-17 16:34:35 +03:00
parent a15738f391
commit 861046e162
8 changed files with 231 additions and 18 deletions

View file

@ -0,0 +1,40 @@
mod widget;
use widget::Widget;
use adw::PasswordEntryRow;
use gtk::{gio::SimpleAction, glib::GString};
use std::sync::Arc;
pub struct Form {
widget: Arc<Widget>,
}
impl Form {
// Construct
pub fn new_arc(
action_send: Arc<SimpleAction>,
title: Option<&str>,
max_length: Option<i32>,
) -> Arc<Self> {
// Init widget
let widget = Widget::new_arc(action_send, title, max_length);
// Result
Arc::new(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

@ -0,0 +1,56 @@
use adw::{
prelude::{EntryRowExt, PreferencesRowExt},
PasswordEntryRow,
};
use gtk::{
gio::SimpleAction,
glib::GString,
prelude::{ActionExt, EditableExt, WidgetExt},
};
use std::sync::Arc;
pub struct Widget {
gobject: PasswordEntryRow,
}
impl Widget {
// Construct
pub fn new_arc(
action_send: Arc<SimpleAction>,
title: Option<&str>,
max_length: Option<i32>,
) -> Arc<Self> {
// Init gobject
let gobject = PasswordEntryRow::builder().show_apply_button(true).build();
if let Some(value) = title {
gobject.set_title(value);
}
if let Some(value) = max_length {
gobject.set_max_length(value);
}
// Init events
gobject.connect_apply(move |_| {
action_send.activate(None);
});
// Return activated struct
Arc::new(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
}
}

View file

@ -0,0 +1,33 @@
use adw::PasswordEntryRow;
use gtk::{prelude::BoxExt, Box, Orientation};
use std::sync::Arc;
const MARGIN: i32 = 6;
const SPACING: i32 = 8;
pub struct Widget {
gobject: Box,
}
impl Widget {
// Construct
pub fn new_arc(response: &PasswordEntryRow) -> Arc<Self> {
let gobject = Box::builder()
.margin_bottom(MARGIN)
.margin_end(MARGIN)
.margin_start(MARGIN)
.margin_top(MARGIN)
.spacing(SPACING)
.orientation(Orientation::Vertical)
.build();
gobject.append(response);
Arc::new(Self { gobject })
}
// Getters
pub fn gobject(&self) -> &Box {
&self.gobject
}
}