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

@ -26,9 +26,8 @@ impl Gemini {
action_page_open: SimpleAction,
) -> Self {
// Init components
let reader = Reader::new_rc(gemtext, base, tab_action, action_page_open);
let widget = Widget::new_rc(reader.gobject());
let reader = Rc::new(Reader::new(gemtext, base, tab_action, action_page_open));
let widget = Rc::new(Widget::new(reader.gobject()));
// Result
Self { reader, widget }

View file

@ -30,12 +30,12 @@ pub struct Reader {
impl Reader {
// Construct
pub fn new_rc(
pub fn new(
gemtext: &str,
base: &Uri,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
) -> Rc<Self> {
) -> Self {
// Init default values
let mut title = None;
@ -223,12 +223,12 @@ impl Reader {
let motion_controller = EventControllerMotion::new();
// Init widget
let widget = Widget::new_rc(
let widget = Rc::new(Widget::new(
&buffer,
primary_button_controller.clone(),
middle_button_controller.clone(),
motion_controller.clone(),
);
));
// Init events
primary_button_controller.connect_released({
@ -346,7 +346,7 @@ impl Reader {
}); // @TODO may be expensive for CPU, add timeout?
// Result
Rc::new(Self { title, widget })
Self { title, widget }
}
// Getters

View file

@ -1,7 +1,6 @@
use gtk::{
prelude::WidgetExt, EventControllerMotion, GestureClick, TextBuffer, TextView, WrapMode,
};
use std::rc::Rc;
const MARGIN: i32 = 8;
@ -11,12 +10,12 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(
pub fn new(
buffer: &TextBuffer,
primary_button_controller: GestureClick,
middle_button_controller: GestureClick,
motion_controller: EventControllerMotion,
) -> Rc<Self> {
) -> Self {
let gobject = TextView::builder()
.bottom_margin(MARGIN)
.buffer(buffer)
@ -33,7 +32,7 @@ impl Widget {
gobject.add_controller(middle_button_controller);
gobject.add_controller(motion_controller);
Rc::new(Self { gobject })
Self { gobject }
}
// Getters

View file

@ -1,6 +1,5 @@
use adw::ClampScrollable;
use gtk::TextView;
use std::rc::Rc;
pub struct Widget {
gobject: ClampScrollable,
@ -8,14 +7,14 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(child: &TextView) -> Rc<Self> {
Rc::new(Self {
pub fn new(child: &TextView) -> Self {
Self {
gobject: ClampScrollable::builder()
.child(child)
.css_classes(["view"])
.maximum_size(800)
.build(),
})
}
}
// Getters