draft pin tab feature

This commit is contained in:
yggverse 2024-09-23 15:44:33 +03:00
parent 4b78ccb779
commit f2427c453e
8 changed files with 64 additions and 20 deletions

View file

@ -10,21 +10,33 @@ pub struct Label {
title: Arc<title::Title>,
// Extras
is_pinned: bool,
widget: widget::Label,
}
impl Label {
// Construct
pub fn new() -> Arc<Label> {
// Init components
let pin = pin::Pin::new();
pub fn new(is_pinned: bool) -> Arc<Label> {
// Components
let pin = pin::Pin::new(is_pinned);
let title = title::Title::new();
// Init extras
// Extras
let widget = widget::Label::new(pin.widget().image(), title.widget().label());
// Result
Arc::new(Self { pin, title, widget })
Arc::new(Self {
pin,
title,
is_pinned,
widget,
})
}
// Actions
pub fn pin(&mut self) {
self.is_pinned = !self.is_pinned; // toggle
// @TODO
}
// Getters

View file

@ -1,19 +1,34 @@
mod widget;
use gtk::prelude::WidgetExt;
use std::sync::Arc;
pub struct Pin {
is_pinned: bool,
widget: widget::Pin,
}
impl Pin {
// Construct
pub fn new() -> Arc<Pin> {
pub fn new(is_pinned: bool) -> Arc<Pin> {
Arc::new(Self {
widget: widget::Pin::new(),
is_pinned,
widget: widget::Pin::new(is_pinned),
})
}
// Actions
pub fn toggle(&mut self) -> bool {
// Toggle state
self.is_pinned = !self.widget().image().is_visible();
// Update widget
self.widget().image().set_visible(self.is_pinned); // @TODO delegate?
// Return state
self.is_pinned
}
// Getters
pub fn widget(&self) -> &widget::Pin {
&self.widget

View file

@ -4,10 +4,10 @@ pub struct Pin {
impl Pin {
// Construct
pub fn new() -> Pin {
pub fn new(is_pinned: bool) -> Pin {
let image = gtk::Image::builder()
.icon_name("view-pin-symbolic")
.visible(false) //@TODO
.visible(is_pinned)
.build();
Self { image }