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

@ -11,10 +11,10 @@ pub struct Bookmark {
impl Bookmark {
// Construct
pub fn new_rc() -> Rc<Self> {
Rc::new(Self {
widget: Widget::new_rc(),
})
pub fn new() -> Self {
Self {
widget: Rc::new(Widget::new()),
}
}
// Actions

View file

@ -1,5 +1,4 @@
use gtk::Button;
use std::rc::Rc;
pub struct Widget {
gobject: Button,
@ -7,14 +6,14 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc() -> Rc<Self> {
Rc::new(Self {
pub fn new() -> Self {
Self {
gobject: Button::builder()
.icon_name("starred-symbolic")
.tooltip_text("Bookmark")
.sensitive(false)
.build(),
})
}
}
// Getters

View file

@ -28,13 +28,13 @@ pub struct History {
impl History {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
pub fn new(window_action: Rc<WindowAction>) -> Self {
// init components
let back = Back::new_rc(window_action.clone());
let forward = Forward::new_rc(window_action);
let back = Rc::new(Back::new(window_action.clone()));
let forward = Rc::new(Forward::new(window_action));
// Init widget
let widget = Widget::new_rc(back.gobject(), forward.gobject());
let widget = Rc::new(Widget::new(back.gobject(), forward.gobject()));
// Init memory
let memory = RefCell::new(Vec::new());
@ -42,13 +42,13 @@ impl History {
// Init index
let index = RefCell::new(None);
Rc::new(Self {
Self {
back,
forward,
memory,
index,
widget,
})
}
}
// Actions

View file

@ -13,12 +13,11 @@ pub struct Back {
impl Back {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// Return activated struct
Rc::new(Self {
pub fn new(window_action: Rc<WindowAction>) -> Self {
Self {
window_action: window_action.clone(),
widget: Widget::new_rc(window_action),
})
widget: Rc::new(Widget::new(window_action)),
}
}
// Actions

View file

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject
let gobject = Button::builder()
.icon_name("go-previous-symbolic")
@ -20,15 +20,10 @@ impl Widget {
.build();
// Init events
gobject.connect_clicked({
let window_action = window_action.clone();
move |_| {
window_action.history_back().activate();
}
});
gobject.connect_clicked(move |_| window_action.history_back().activate());
// Return activated struct
Rc::new(Self { gobject })
// Return activated `Self`
Self { gobject }
}
// Actions

View file

@ -13,12 +13,11 @@ pub struct Forward {
impl Forward {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// Return activated struct
Rc::new(Self {
pub fn new(window_action: Rc<WindowAction>) -> Self {
Self {
window_action: window_action.clone(),
widget: Widget::new_rc(window_action),
})
widget: Rc::new(Widget::new(window_action)),
}
}
// Actions

View file

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject
let gobject = Button::builder()
.icon_name("go-next-symbolic")
@ -20,15 +20,10 @@ impl Widget {
.build();
// Init events
gobject.connect_clicked({
let window_action = window_action.clone();
move |_| {
window_action.history_forward().activate();
}
});
gobject.connect_clicked(move |_| window_action.history_forward().activate());
// Return activated struct
Rc::new(Self { gobject })
// Return activated `Self`
Self { gobject }
}
// Actions

View file

@ -2,7 +2,6 @@ use gtk::{
prelude::{BoxExt, IsA},
Box, Orientation,
};
use std::rc::Rc;
pub struct Widget {
gobject: Box,
@ -10,7 +9,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(back: &impl IsA<gtk::Widget>, forward: &impl IsA<gtk::Widget>) -> Rc<Self> {
pub fn new(back: &impl IsA<gtk::Widget>, forward: &impl IsA<gtk::Widget>) -> Self {
// Init widget
let gobject = Box::builder()
.orientation(Orientation::Horizontal)
@ -23,8 +22,8 @@ impl Widget {
gobject.append(back);
gobject.append(forward);
// Return activated struct
Rc::new(Self { gobject })
// Return activated `Self`
Self { gobject }
}
// Getters

View file

@ -17,12 +17,12 @@ pub struct Home {
impl Home {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
Rc::new(Self {
pub fn new(window_action: Rc<WindowAction>) -> Self {
Self {
window_action: window_action.clone(),
uri: RefCell::new(None),
widget: Widget::new_rc(window_action),
})
widget: Rc::new(Widget::new(window_action)),
}
}
// Actions

View file

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject
let gobject = Button::builder()
.icon_name("go-home-symbolic")
@ -22,8 +22,8 @@ impl Widget {
// Init events
gobject.connect_clicked(move |_| window_action.home().activate());
// Return activated struct
Rc::new(Self { gobject })
// Return activated `Self`
Self { gobject }
}
// Actions

View file

@ -13,11 +13,11 @@ pub struct Reload {
impl Reload {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
Rc::new(Self {
pub fn new(window_action: Rc<WindowAction>) -> Self {
Self {
window_action: window_action.clone(),
widget: Widget::new_rc(window_action),
})
widget: Rc::new(Widget::new(window_action)),
}
}
// Actions

View file

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject
let gobject = Button::builder()
.icon_name("view-refresh-symbolic")
@ -22,8 +22,8 @@ impl Widget {
// Init events
gobject.connect_clicked(move |_| window_action.reload().activate());
// Return activated struct
Rc::new(Self { gobject })
// Return activated `Self`
Self { gobject }
}
// Actions

View file

@ -20,14 +20,14 @@ pub struct Request {
impl Request {
// Construct
pub fn new_rc(
pub fn new(
// Actions
browser_action: Rc<BrowserAction>,
action_page_reload: SimpleAction, // @TODO local `action_page_open`?
) -> Rc<Self> {
Rc::new(Self {
widget: Widget::new_rc(browser_action, action_page_reload),
})
) -> Self {
Self {
widget: Rc::new(Widget::new(browser_action, action_page_reload)),
}
}
// Actions

View file

@ -30,7 +30,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(browser_action: Rc<BrowserAction>, action_page_open: SimpleAction) -> Rc<Self> {
pub fn new(browser_action: Rc<BrowserAction>, action_page_open: SimpleAction) -> Self {
// Init animated progress bar state
let progress = Rc::new(Progress {
fraction: RefCell::new(0.0),
@ -73,8 +73,8 @@ impl Widget {
}
});
// Return activated struct
Rc::new(Self { gobject, progress })
// Return activated `Self`
Self { gobject, progress }
}
// Actions

View file

@ -2,7 +2,6 @@ use gtk::{
prelude::{BoxExt, IsA},
Box, Orientation,
};
use std::rc::Rc;
const MARGIN: i32 = 6;
const SPACING: i32 = 6;
@ -13,13 +12,13 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(
pub fn new(
base: &impl IsA<gtk::Widget>,
history: &impl IsA<gtk::Widget>,
reload: &impl IsA<gtk::Widget>,
request: &impl IsA<gtk::Widget>,
bookmark: &impl IsA<gtk::Widget>,
) -> Rc<Self> {
) -> Self {
let gobject = Box::builder()
.orientation(Orientation::Horizontal)
.spacing(SPACING)
@ -34,7 +33,7 @@ impl Widget {
gobject.append(request);
gobject.append(bookmark);
Rc::new(Self { gobject })
Self { gobject }
}
// Getters