define ptr container outside

This commit is contained in:
yggverse 2024-11-11 01:14:09 +02:00
parent 7b2c07ac45
commit a5fc2a7475
58 changed files with 230 additions and 272 deletions

View file

@ -24,23 +24,27 @@ pub struct Response {
impl Response {
// Construct
pub fn new_rc(
pub fn new(
tab_action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
size_limit: Option<usize>,
) -> Rc<Self> {
) -> Self {
// Init local actions
let action_update = SimpleAction::new(&uuid_string_random(), None);
let action_send = SimpleAction::new(&uuid_string_random(), None);
// Init components
let control = Control::new_rc(action_send.clone());
let form = Form::new_rc(action_update.clone());
let title = Title::new_rc(title);
let control = Rc::new(Control::new(action_send.clone()));
let form = Rc::new(Form::new(action_update.clone()));
let title = Rc::new(Title::new(title));
// Init widget
let widget = Widget::new_rc(title.gobject(), form.gobject(), control.gobject());
let widget = Rc::new(Widget::new(
title.gobject(),
form.gobject(),
control.gobject(),
));
// Init events
action_update.connect_activate({
@ -70,7 +74,7 @@ impl Response {
widget.gobject().connect_realize(move |_| form.focus());
// Return activated struct
Rc::new(Self { widget })
Self { widget }
}
// Getters

View file

@ -17,20 +17,20 @@ pub struct Control {
impl Control {
// Construct
pub fn new_rc(action_send: SimpleAction) -> Rc<Self> {
pub fn new(action_send: SimpleAction) -> Self {
// Init components
let counter = Counter::new_rc();
let send = Send::new_rc(action_send);
let counter = Rc::new(Counter::new());
let send = Rc::new(Send::new(action_send));
// Init widget
let widget = Widget::new_rc(counter.gobject(), send.gobject());
let widget = Rc::new(Widget::new(counter.gobject(), send.gobject()));
// Return activated struct
Rc::new(Self {
Self {
counter,
send,
widget,
})
}
}
// Actions

View file

@ -11,12 +11,10 @@ pub struct Counter {
impl Counter {
// Construct
pub fn new_rc() -> Rc<Self> {
// Init widget
let widget = Widget::new_rc();
// Result
Rc::new(Self { widget })
pub fn new() -> Self {
Self {
widget: Rc::new(Widget::new()),
}
}
// Actions

View file

@ -1,5 +1,4 @@
use gtk::{prelude::WidgetExt, Label};
use std::rc::Rc;
pub struct Widget {
gobject: Label,
@ -7,10 +6,10 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc() -> Rc<Self> {
let gobject = Label::builder().build();
Rc::new(Self { gobject })
pub fn new() -> Self {
Self {
gobject: Label::builder().build(),
}
}
// Actions

View file

@ -1,5 +1,4 @@
mod widget;
use widget::Widget;
use gtk::{gio::SimpleAction, Button};
@ -11,12 +10,12 @@ pub struct Send {
impl Send {
// Construct
pub fn new_rc(action_send: SimpleAction) -> Rc<Self> {
pub fn new(action_send: SimpleAction) -> Self {
// Init widget
let widget = Widget::new_rc(action_send);
let widget = Rc::new(Widget::new(action_send));
// Result
Rc::new(Self { widget })
Self { widget }
}
// Actions

View file

@ -3,7 +3,6 @@ use gtk::{
prelude::{ActionExt, ButtonExt, WidgetExt},
Button,
};
use std::rc::Rc;
pub struct Widget {
gobject: Button,
@ -11,7 +10,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(action_send: SimpleAction) -> Rc<Self> {
pub fn new(action_send: SimpleAction) -> Self {
// Init gobject
let gobject = Button::builder()
//.css_classes(["accent"])
@ -25,8 +24,8 @@ impl Widget {
}
});
// Return activated struct
Rc::new(Self { gobject })
// Return activated `Self`
Self { gobject }
}
// Actions

View file

@ -1,5 +1,4 @@
use gtk::{prelude::BoxExt, Align, Box, Button, Label, Orientation};
use std::rc::Rc;
const SPACING: i32 = 8;
@ -9,7 +8,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(limit: &Label, send: &Button) -> Rc<Self> {
pub fn new(limit: &Label, send: &Button) -> Self {
// Init gobject
let gobject = Box::builder()
.halign(Align::End)
@ -20,8 +19,8 @@ impl Widget {
gobject.append(limit);
gobject.append(send);
// Return new struct
Rc::new(Self { gobject })
// Return new `Self`
Self { gobject }
}
// Getters

View file

@ -11,12 +11,10 @@ pub struct Form {
impl Form {
// Construct
pub fn new_rc(action_update: SimpleAction) -> Rc<Self> {
// Init widget
let widget = Widget::new_rc(action_update);
// Result
Rc::new(Self { widget })
pub fn new(action_update: SimpleAction) -> Self {
Self {
widget: Rc::new(Widget::new(action_update)),
}
}
// Actions

View file

@ -4,7 +4,6 @@ use gtk::{
prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
TextView, WrapMode,
};
use std::rc::Rc;
const MARGIN: i32 = 8;
@ -14,7 +13,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(action_update: SimpleAction) -> Rc<Self> {
pub fn new(action_update: SimpleAction) -> Self {
// Init gobject
let gobject = TextView::builder()
.bottom_margin(MARGIN)
@ -29,8 +28,8 @@ impl Widget {
action_update.activate(None);
});
// Return activated struct
Rc::new(Self { gobject })
// Return activated `Self`
Self { gobject }
}
// Actions

View file

@ -11,12 +11,10 @@ pub struct Title {
impl Title {
// Construct
pub fn new_rc(title: Option<&str>) -> Rc<Self> {
// Init widget
let widget = Widget::new_rc(title);
// Result
Rc::new(Self { widget })
pub fn new(title: Option<&str>) -> Self {
Self {
widget: Rc::new(Widget::new(title)),
}
}
// Getters

View file

@ -1,5 +1,4 @@
use gtk::{prelude::WidgetExt, Align, Label};
use std::rc::Rc;
pub struct Widget {
gobject: Label,
@ -7,7 +6,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(title: Option<&str>) -> Rc<Self> {
pub fn new(title: Option<&str>) -> Self {
let gobject = Label::builder()
.css_classes(["heading"])
.halign(Align::Start)
@ -23,7 +22,7 @@ impl Widget {
}
}
Rc::new(Self { gobject })
Self { gobject }
}
// Getters

View file

@ -1,5 +1,4 @@
use gtk::{prelude::BoxExt, Box, Label, Orientation, TextView};
use std::rc::Rc;
const MARGIN: i32 = 6;
const SPACING: i32 = 8;
@ -10,7 +9,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(title: &Label, response: &TextView, control: &Box) -> Rc<Self> {
pub fn new(title: &Label, response: &TextView, control: &Box) -> Self {
let gobject = Box::builder()
.margin_bottom(MARGIN)
.margin_end(MARGIN)
@ -24,7 +23,7 @@ impl Widget {
gobject.append(response);
gobject.append(control);
Rc::new(Self { gobject })
Self { gobject }
}
// Getters

View file

@ -20,25 +20,25 @@ pub struct Sensitive {
impl Sensitive {
// Construct
pub fn new_rc(
pub fn new(
tab_action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
max_length: Option<i32>,
) -> Rc<Self> {
) -> Self {
// Init local actions
let action_send = SimpleAction::new(&uuid_string_random(), None);
// Init components
let form = Form::new_rc(
let form = Rc::new(Form::new(
action_send.clone(),
title,
max_length
.map(|value| value - base.to_string_partial(UriHideFlags::QUERY).len() as i32),
);
));
// Init widget
let widget = Widget::new_rc(form.gobject());
let widget = Rc::new(Widget::new(form.gobject()));
// Init events
action_send.connect_activate({
@ -55,7 +55,7 @@ impl Sensitive {
widget.gobject().connect_realize(move |_| form.focus());
// Return activated struct
Rc::new(Self { widget })
Self { widget }
}
// Getters

View file

@ -12,16 +12,12 @@ pub struct Form {
impl Form {
// Construct
pub fn new_rc(
action_send: SimpleAction,
title: Option<&str>,
max_length: Option<i32>,
) -> Rc<Self> {
pub fn new(action_send: SimpleAction, title: Option<&str>, max_length: Option<i32>) -> Self {
// Init widget
let widget = Widget::new_rc(action_send, title, max_length);
let widget = Rc::new(Widget::new(action_send, title, max_length));
// Result
Rc::new(Self { widget })
Self { widget }
}
// Actions

View file

@ -7,7 +7,6 @@ use gtk::{
glib::GString,
prelude::{ActionExt, EditableExt, WidgetExt},
};
use std::rc::Rc;
pub struct Widget {
gobject: PasswordEntryRow,
@ -15,11 +14,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(
action_send: SimpleAction,
title: Option<&str>,
max_length: Option<i32>,
) -> Rc<Self> {
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();
@ -37,7 +32,7 @@ impl Widget {
});
// Return activated struct
Rc::new(Self { gobject })
Self { gobject }
}
// Actions

View file

@ -1,6 +1,5 @@
use adw::PasswordEntryRow;
use gtk::{prelude::BoxExt, Box, Orientation};
use std::rc::Rc;
const MARGIN: i32 = 6;
const SPACING: i32 = 8;
@ -11,7 +10,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(response: &PasswordEntryRow) -> Rc<Self> {
pub fn new(response: &PasswordEntryRow) -> Self {
let gobject = Box::builder()
.margin_bottom(MARGIN)
.margin_end(MARGIN)
@ -23,7 +22,7 @@ impl Widget {
gobject.append(response);
Rc::new(Self { gobject })
Self { gobject }
}
// Getters

View file

@ -1,6 +1,5 @@
use adw::Clamp;
use gtk::{prelude::WidgetExt, Box};
use std::rc::Rc;
pub struct Widget {
gobject: Clamp,
@ -8,14 +7,14 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc() -> Rc<Self> {
pub fn new() -> Self {
let gobject = Clamp::builder()
.css_classes(["app-notification"])
.maximum_size(800)
.visible(false)
.build();
Rc::new(Self { gobject })
Self { gobject }
}
// Actions