mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 01:00:02 +00:00
remove extra getters, give name to gobjects
This commit is contained in:
parent
36d4673d44
commit
2799ce37fe
@ -38,7 +38,7 @@ impl Input {
|
||||
size_limit: Option<usize>,
|
||||
) {
|
||||
self.widget.update(Some(
|
||||
Response::new(action, base, title, size_limit).gobject(),
|
||||
&Response::new(action, base, title, size_limit).widget.g_box,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,12 @@ use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, Uri, UriHideFlags},
|
||||
prelude::WidgetExt,
|
||||
Box,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Response {
|
||||
// Components
|
||||
widget: Rc<Widget>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Response {
|
||||
@ -41,9 +40,9 @@ impl Response {
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(
|
||||
title.gobject(),
|
||||
form.gobject(),
|
||||
control.gobject(),
|
||||
&title.widget.label,
|
||||
&form.widget.text_view,
|
||||
&control.widget.g_box,
|
||||
));
|
||||
|
||||
// Init events
|
||||
@ -55,7 +54,7 @@ impl Response {
|
||||
control.update(size_limit.map(|limit| {
|
||||
limit as i32
|
||||
- (base.to_string_partial(UriHideFlags::QUERY).len() as i32
|
||||
+ Uri::escape_string(form.text().as_str(), None, false).len() as i32)
|
||||
+ Uri::escape_string(&form.widget.text(), None, false).len() as i32)
|
||||
}));
|
||||
}
|
||||
});
|
||||
@ -67,21 +66,18 @@ impl Response {
|
||||
Some(&format!(
|
||||
"{}?{}",
|
||||
base.to_string_partial(UriHideFlags::QUERY),
|
||||
Uri::escape_string(form.text().as_str(), None, false),
|
||||
Uri::escape_string(&form.widget.text(), None, false),
|
||||
)),
|
||||
true,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
widget.gobject().connect_realize(move |_| form.focus());
|
||||
widget.g_box.connect_realize(move |_| {
|
||||
form.widget.text_view.grab_focus();
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Self { widget }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ use counter::Counter;
|
||||
use send::Send;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, Box};
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Control {
|
||||
counter: Rc<Counter>,
|
||||
send: Rc<Send>,
|
||||
widget: Rc<Widget>,
|
||||
pub counter: Rc<Counter>,
|
||||
pub send: Rc<Send>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Control {
|
||||
@ -23,7 +23,7 @@ impl Control {
|
||||
let send = Rc::new(Send::new(action_send));
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(counter.gobject(), send.gobject()));
|
||||
let widget = Rc::new(Widget::new(&counter.widget.label, &send.widget.button));
|
||||
|
||||
// Return activated struct
|
||||
Self {
|
||||
@ -42,9 +42,4 @@ impl Control {
|
||||
None => false,
|
||||
});
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,10 @@ mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::Label;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Counter {
|
||||
widget: Rc<Widget>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Counter {
|
||||
@ -21,9 +20,4 @@ impl Counter {
|
||||
pub fn update(&self, chars_left: Option<i32>) {
|
||||
self.widget.update(chars_left);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Label {
|
||||
self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
use gtk::{prelude::WidgetExt, Label};
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Label,
|
||||
pub label: Label,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
gobject: Label::builder().build(),
|
||||
label: Label::builder().build(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,21 +17,16 @@ impl Widget {
|
||||
match chars_left {
|
||||
Some(value) => {
|
||||
// Update color on chars left reached
|
||||
self.gobject
|
||||
self.label
|
||||
.set_css_classes(&[if value > 0 { "success" } else { "error" }]); // @TODO add warning step?
|
||||
|
||||
// Update text
|
||||
self.gobject.set_label(&value.to_string());
|
||||
self.label.set_label(&value.to_string());
|
||||
|
||||
// Toggle visibility on chars left provided
|
||||
self.gobject.set_visible(true);
|
||||
self.label.set_visible(true);
|
||||
}
|
||||
None => self.gobject.set_visible(false),
|
||||
None => self.label.set_visible(false),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Label {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
mod widget;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, Button};
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Send {
|
||||
widget: Rc<Widget>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Send {
|
||||
@ -22,9 +22,4 @@ impl Send {
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.widget.update(is_sensitive);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -5,36 +5,31 @@ use gtk::{
|
||||
};
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Button,
|
||||
pub button: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(action_send: SimpleAction) -> Self {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
//.css_classes(["accent"])
|
||||
.label("Send")
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
button.connect_clicked({
|
||||
move |_| {
|
||||
action_send.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { gobject }
|
||||
Self { button }
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.gobject.set_sensitive(is_sensitive);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.gobject
|
||||
self.button.set_sensitive(is_sensitive);
|
||||
}
|
||||
}
|
||||
|
@ -3,28 +3,23 @@ use gtk::{prelude::BoxExt, Align, Box, Button, Label, Orientation};
|
||||
const SPACING: i32 = 8;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Box,
|
||||
pub g_box: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(limit: &Label, send: &Button) -> Self {
|
||||
// Init gobject
|
||||
let gobject = Box::builder()
|
||||
// Init main widget
|
||||
let g_box = Box::builder()
|
||||
.halign(Align::End)
|
||||
.orientation(Orientation::Horizontal)
|
||||
.spacing(SPACING)
|
||||
.build();
|
||||
|
||||
gobject.append(limit);
|
||||
gobject.append(send);
|
||||
g_box.append(limit);
|
||||
g_box.append(send);
|
||||
|
||||
// Return new `Self`
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.gobject
|
||||
Self { g_box }
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, glib::GString, TextView};
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Form {
|
||||
widget: Rc<Widget>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Form {
|
||||
@ -16,18 +16,4 @@ impl Form {
|
||||
widget: Rc::new(Widget::new(action_update)),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn focus(&self) {
|
||||
self.widget.focus();
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn text(&self) -> GString {
|
||||
self.widget.text()
|
||||
}
|
||||
|
||||
pub fn gobject(&self) -> &TextView {
|
||||
self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::GString,
|
||||
prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
prelude::{ActionExt, TextBufferExt, TextViewExt},
|
||||
TextView, WrapMode,
|
||||
};
|
||||
|
||||
const MARGIN: i32 = 8;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: TextView,
|
||||
pub text_view: TextView,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(action_update: SimpleAction) -> Self {
|
||||
// Init gobject
|
||||
let gobject = TextView::builder()
|
||||
// Init main widget
|
||||
let text_view = TextView::builder()
|
||||
.bottom_margin(MARGIN)
|
||||
.left_margin(MARGIN)
|
||||
.right_margin(MARGIN)
|
||||
@ -24,26 +24,18 @@ impl Widget {
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.buffer().connect_changed(move |_| {
|
||||
text_view.buffer().connect_changed(move |_| {
|
||||
action_update.activate(None);
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn focus(&self) {
|
||||
self.gobject.grab_focus();
|
||||
Self { text_view }
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn text(&self) -> GString {
|
||||
let buffer = self.gobject.buffer();
|
||||
let buffer = self.text_view.buffer();
|
||||
buffer.text(&buffer.start_iter(), &buffer.end_iter(), true)
|
||||
}
|
||||
|
||||
pub fn gobject(&self) -> &TextView {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,10 @@ mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::Label;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Title {
|
||||
widget: Rc<Widget>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Title {
|
||||
@ -16,9 +15,4 @@ impl Title {
|
||||
widget: Rc::new(Widget::new(title)),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Label {
|
||||
self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
use gtk::{prelude::WidgetExt, Align, Label};
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Label,
|
||||
pub label: Label,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(title: Option<&str>) -> Self {
|
||||
let gobject = Label::builder()
|
||||
let label = Label::builder()
|
||||
.css_classes(["heading"])
|
||||
.halign(Align::Start)
|
||||
.margin_end(8)
|
||||
@ -15,18 +15,13 @@ impl Widget {
|
||||
.visible(false)
|
||||
.build();
|
||||
|
||||
if let Some(label) = title {
|
||||
if !label.is_empty() {
|
||||
gobject.set_label(label);
|
||||
gobject.set_visible(true)
|
||||
if let Some(value) = title {
|
||||
if !value.is_empty() {
|
||||
label.set_label(value);
|
||||
label.set_visible(true)
|
||||
}
|
||||
}
|
||||
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Label {
|
||||
&self.gobject
|
||||
Self { label }
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ const MARGIN: i32 = 6;
|
||||
const SPACING: i32 = 8;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Box,
|
||||
pub g_box: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(title: &Label, response: &TextView, control: &Box) -> Self {
|
||||
let gobject = Box::builder()
|
||||
let g_box = Box::builder()
|
||||
.margin_bottom(MARGIN)
|
||||
.margin_end(MARGIN)
|
||||
.margin_start(MARGIN)
|
||||
@ -19,15 +19,10 @@ impl Widget {
|
||||
.orientation(Orientation::Vertical)
|
||||
.build();
|
||||
|
||||
gobject.append(title);
|
||||
gobject.append(response);
|
||||
gobject.append(control);
|
||||
g_box.append(title);
|
||||
g_box.append(response);
|
||||
g_box.append(control);
|
||||
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.gobject
|
||||
Self { g_box }
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use crate::app::browser::window::tab::item::action::Action as TabAction;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, Uri, UriHideFlags},
|
||||
prelude::WidgetExt,
|
||||
prelude::{EditableExt, WidgetExt},
|
||||
Box,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
@ -38,7 +38,7 @@ impl Sensitive {
|
||||
));
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(form.gobject()));
|
||||
let widget = Rc::new(Widget::new(&form.widget.password_entry_row));
|
||||
|
||||
// Init events
|
||||
action_send.connect_activate({
|
||||
@ -48,14 +48,16 @@ impl Sensitive {
|
||||
Some(&format!(
|
||||
"{}?{}",
|
||||
base.to_string_partial(UriHideFlags::QUERY),
|
||||
Uri::escape_string(form.text().as_str(), None, false),
|
||||
Uri::escape_string(&form.widget.password_entry_row.text(), None, false),
|
||||
)),
|
||||
true,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
widget.gobject().connect_realize(move |_| form.focus());
|
||||
widget.gobject().connect_realize(move |_| {
|
||||
form.widget.password_entry_row.grab_focus();
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Self { widget }
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user