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

@ -16,7 +16,7 @@ impl Main {
// Init struct // Init struct
Arc::new(Self { Arc::new(Self {
widget: widget::Main::new(tab.widget().gtk()), // @TODO widget: widget::Main::new(tab.widget().tab()), // @TODO
tab, tab,
}) })
} }
@ -26,6 +26,10 @@ impl Main {
self.tab.append(true); self.tab.append(true);
} }
pub fn tab_pin(&self) {
self.tab.pin();
}
// Getters // Getters
pub fn widget(&self) -> &widget::Main { pub fn widget(&self) -> &widget::Main {
&self.widget &self.widget

View file

@ -10,21 +10,33 @@ pub struct Label {
title: Arc<title::Title>, title: Arc<title::Title>,
// Extras // Extras
is_pinned: bool,
widget: widget::Label, widget: widget::Label,
} }
impl Label { impl Label {
// Construct // Construct
pub fn new() -> Arc<Label> { pub fn new(is_pinned: bool) -> Arc<Label> {
// Init components // Components
let pin = pin::Pin::new(); let pin = pin::Pin::new(is_pinned);
let title = title::Title::new(); let title = title::Title::new();
// Init extras // Extras
let widget = widget::Label::new(pin.widget().image(), title.widget().label()); let widget = widget::Label::new(pin.widget().image(), title.widget().label());
// Result // 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 // Getters

View file

@ -1,19 +1,34 @@
mod widget; mod widget;
use gtk::prelude::WidgetExt;
use std::sync::Arc; use std::sync::Arc;
pub struct Pin { pub struct Pin {
is_pinned: bool,
widget: widget::Pin, widget: widget::Pin,
} }
impl Pin { impl Pin {
// Construct // Construct
pub fn new() -> Arc<Pin> { pub fn new(is_pinned: bool) -> Arc<Pin> {
Arc::new(Self { 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 // Getters
pub fn widget(&self) -> &widget::Pin { pub fn widget(&self) -> &widget::Pin {
&self.widget &self.widget

View file

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

View file

@ -15,14 +15,18 @@ impl Tab {
} }
// Actions // Actions
pub fn append(&self, current: bool) -> u32 { pub fn append(&self, is_active: bool) -> u32 {
self.widget.append( self.widget.append(
label::Label::new().widget().container(), label::Label::new(false).widget().container(),
page::Page::new().widget().container(), page::Page::new().widget().container(),
current, is_active,
) )
} }
pub fn pin(&self) -> bool {
false // @TODO
}
// Getters // Getters
pub fn widget(&self) -> &widget::Tab { pub fn widget(&self) -> &widget::Tab {
&self.widget &self.widget

View file

@ -1,30 +1,30 @@
pub struct Tab { pub struct Tab {
gtk: gtk::Notebook, tab: gtk::Notebook,
} }
impl Tab { impl Tab {
// Construct new object // Construct new object
pub fn new() -> Tab { pub fn new() -> Tab {
Self { Self {
gtk: gtk::Notebook::builder().scrollable(true).build(), tab: gtk::Notebook::builder().scrollable(true).build(),
} }
} }
// Actions // Actions
pub fn append(&self, label: &gtk::Box, page: &gtk::Box, current: bool) -> u32 { pub fn append(&self, label: &gtk::Box, page: &gtk::Box, current: bool) -> u32 {
let page_number = self.gtk.append_page(page, Some(label)); let page_number = self.tab.append_page(page, Some(label));
self.gtk.set_tab_reorderable(page, true); self.tab.set_tab_reorderable(page, true);
if current { if current {
self.gtk.set_current_page(Some(page_number)); self.tab.set_current_page(Some(page_number));
} }
page_number page_number
} }
// Getters // Getters
pub fn gtk(&self) -> &gtk::Notebook { pub fn tab(&self) -> &gtk::Notebook {
&self.gtk &self.tab
} }
} }

View file

@ -59,6 +59,14 @@ impl Browser {
} }
}) })
.build(), .build(),
ActionEntry::builder("tab_pin")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_pin();
}
})
.build(),
]); ]);
// Return // Return

View file

@ -15,6 +15,7 @@ fn main() -> glib::ExitCode {
// Init accels // Init accels
app.set_accels_for_action("win.tab_append", &["<Ctrl>t"]); app.set_accels_for_action("win.tab_append", &["<Ctrl>t"]);
app.set_accels_for_action("win.tab_pin", &["<Ctrl>p"]);
app.set_accels_for_action("win.tab_close", &["<Ctrl>q"]); app.set_accels_for_action("win.tab_close", &["<Ctrl>q"]);
app.set_accels_for_action("win.debug", &["<Ctrl>i"]); app.set_accels_for_action("win.debug", &["<Ctrl>i"]);
app.set_accels_for_action("win.quit", &["<Ctrl>Escape"]); app.set_accels_for_action("win.quit", &["<Ctrl>Escape"]);