|
|
@ -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
|
|
|
|
|
|
|
|
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject())); |
|
|
|
// Init label struct
|
|
|
|
|
|
|
|
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 { |
|
|
|