mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-10 18:34:14 +00:00
use is_pinned mutex as the struct option, begin use arc for new structs by default
This commit is contained in:
parent
41f0452e26
commit
793d179164
@ -49,7 +49,6 @@ Guide and protocol draft
|
|||||||
* contain main `struct` implementation:
|
* contain main `struct` implementation:
|
||||||
* at least one constructor that must:
|
* at least one constructor that must:
|
||||||
* have common for application name: `new`
|
* have common for application name: `new`
|
||||||
* return unwrapped (except `Option`, `Result`), activated new `Self` object
|
|
||||||
* grant ownership for new `Self` object created
|
* grant ownership for new `Self` object created
|
||||||
* public `activate` action if the new object can not be activated on construct
|
* public `activate` action if the new object can not be activated on construct
|
||||||
* public `link` getter for GTK `widget` (parental composition)
|
* public `link` getter for GTK `widget` (parental composition)
|
||||||
|
@ -43,7 +43,7 @@ impl Item {
|
|||||||
let id = uuid_string_random();
|
let id = uuid_string_random();
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let label = Arc::new(Label::new(id.clone(), false));
|
let label = Label::new(id.clone(), false);
|
||||||
|
|
||||||
let page = Arc::new(Page::new(
|
let page = Arc::new(Page::new(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
|
@ -10,7 +10,7 @@ use title::Title;
|
|||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{glib::GString, prelude::WidgetExt, Box, GestureClick};
|
use gtk::{glib::GString, prelude::WidgetExt, Box, GestureClick};
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
pub struct Label {
|
pub struct Label {
|
||||||
// Components
|
// Components
|
||||||
@ -18,39 +18,42 @@ pub struct Label {
|
|||||||
title: Arc<Title>,
|
title: Arc<Title>,
|
||||||
// GTK
|
// GTK
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
|
// Extras
|
||||||
|
is_pinned: Mutex<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(name: GString, is_pinned: bool) -> Label {
|
pub fn new(name: GString, is_pinned: bool) -> Arc<Self> {
|
||||||
// Init components
|
// Init components
|
||||||
let pin = Arc::new(Pin::new(is_pinned));
|
let pin = Pin::new(is_pinned);
|
||||||
let title = Arc::new(Title::new());
|
let title = Title::new();
|
||||||
|
let widget = Widget::new(name, pin.gobject(), title.gobject());
|
||||||
|
|
||||||
// Init GTK
|
// Init label struct
|
||||||
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject()));
|
let label = Arc::new(Self {
|
||||||
|
pin: pin.clone(),
|
||||||
|
title: title.clone(),
|
||||||
|
widget: widget.clone(),
|
||||||
|
is_pinned: Mutex::new(is_pinned),
|
||||||
|
});
|
||||||
|
|
||||||
// Init events:
|
// Init events:
|
||||||
|
|
||||||
// Await for widget realize to continue this feature
|
// Await for widget realize to continue this feature
|
||||||
widget.gobject().connect_realize({
|
widget.gobject().connect_realize({
|
||||||
let pin = pin.clone();
|
|
||||||
let title = title.clone();
|
|
||||||
let widget = widget.clone();
|
let widget = widget.clone();
|
||||||
|
let label = label.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
// Init GestureClick listener
|
// Init GestureClick listener
|
||||||
let controller = GestureClick::new();
|
let controller = GestureClick::new();
|
||||||
|
|
||||||
// Listen for double click
|
// Listen for double click
|
||||||
controller.connect_pressed({
|
controller.connect_pressed({
|
||||||
let pin = pin.clone();
|
let label = label.clone();
|
||||||
let title = title.clone();
|
|
||||||
move |_, count, _, _| {
|
move |_, count, _, _| {
|
||||||
if count == 2 {
|
if count == 2 {
|
||||||
// Toggle pin @TODO use action?
|
label.pin(!label.is_pinned());
|
||||||
let is_pinned = !pin.is_pinned();
|
|
||||||
pin.pin(is_pinned);
|
|
||||||
title.pin(is_pinned);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -73,7 +76,7 @@ impl Label {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Self { pin, title, widget }
|
label
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -143,13 +146,17 @@ impl Label {
|
|||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
pub fn pin(&self, is_pinned: bool) {
|
pub fn pin(&self, is_pinned: bool) {
|
||||||
|
// Update Self
|
||||||
|
*self.is_pinned.lock().unwrap() = is_pinned;
|
||||||
|
|
||||||
|
// Update child components
|
||||||
self.pin.pin(is_pinned);
|
self.pin.pin(is_pinned);
|
||||||
self.title.pin(is_pinned);
|
self.title.pin(is_pinned);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn is_pinned(&self) -> bool {
|
pub fn is_pinned(&self) -> bool {
|
||||||
self.pin.is_pinned() // @TODO
|
self.is_pinned.lock().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gobject(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::{prelude::WidgetExt, Image};
|
use gtk::{prelude::WidgetExt, Image};
|
||||||
|
|
||||||
pub struct Pin {
|
pub struct Pin {
|
||||||
@ -6,13 +8,13 @@ pub struct Pin {
|
|||||||
|
|
||||||
impl Pin {
|
impl Pin {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(visible: bool) -> Pin {
|
pub fn new(visible: bool) -> Arc<Pin> {
|
||||||
let gobject = Image::builder()
|
let gobject = Image::builder()
|
||||||
.icon_name("view-pin-symbolic")
|
.icon_name("view-pin-symbolic")
|
||||||
.visible(visible)
|
.visible(visible)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Self { gobject }
|
Arc::new(Self { gobject })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pin(&self, is_pinned: bool) {
|
pub fn pin(&self, is_pinned: bool) {
|
||||||
@ -20,10 +22,6 @@ impl Pin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn is_pinned(&self) -> bool {
|
|
||||||
self.gobject.is_visible()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn gobject(&self) -> &Image {
|
pub fn gobject(&self) -> &Image {
|
||||||
&self.gobject
|
&self.gobject
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::{glib::GString, pango::EllipsizeMode, prelude::WidgetExt, Label};
|
use gtk::{glib::GString, pango::EllipsizeMode, prelude::WidgetExt, Label};
|
||||||
|
|
||||||
const DEFAULT_LABEL_TEXT: &str = "New page";
|
const DEFAULT_LABEL_TEXT: &str = "New page";
|
||||||
@ -8,15 +10,15 @@ pub struct Title {
|
|||||||
|
|
||||||
impl Title {
|
impl Title {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Arc<Self> {
|
||||||
Self {
|
Arc::new(Self {
|
||||||
gobject: Label::builder()
|
gobject: Label::builder()
|
||||||
.label(DEFAULT_LABEL_TEXT)
|
.label(DEFAULT_LABEL_TEXT)
|
||||||
.ellipsize(EllipsizeMode::End)
|
.ellipsize(EllipsizeMode::End)
|
||||||
.width_chars(16)
|
.width_chars(16)
|
||||||
.single_line_mode(true)
|
.single_line_mode(true)
|
||||||
.build(),
|
.build(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
glib::GString, prelude::BoxExt, prelude::WidgetExt, Align, Box, Image, Label, Orientation,
|
glib::GString, prelude::BoxExt, prelude::WidgetExt, Align, Box, Image, Label, Orientation,
|
||||||
};
|
};
|
||||||
@ -8,7 +10,7 @@ pub struct Widget {
|
|||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(name: GString, pin: &Image, title: &Label) -> Self {
|
pub fn new(name: GString, pin: &Image, title: &Label) -> Arc<Self> {
|
||||||
let gobject = Box::builder()
|
let gobject = Box::builder()
|
||||||
.orientation(Orientation::Horizontal)
|
.orientation(Orientation::Horizontal)
|
||||||
.halign(Align::Center)
|
.halign(Align::Center)
|
||||||
@ -19,7 +21,7 @@ impl Widget {
|
|||||||
gobject.append(pin);
|
gobject.append(pin);
|
||||||
gobject.append(title);
|
gobject.append(title);
|
||||||
|
|
||||||
Self { gobject }
|
Arc::new(Self { gobject })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
|
Loading…
x
Reference in New Issue
Block a user