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

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 }

View File

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

View File

@ -1,30 +1,30 @@
pub struct Tab {
gtk: gtk::Notebook,
tab: gtk::Notebook,
}
impl Tab {
// Construct new object
pub fn new() -> Tab {
Self {
gtk: gtk::Notebook::builder().scrollable(true).build(),
tab: gtk::Notebook::builder().scrollable(true).build(),
}
}
// Actions
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 {
self.gtk.set_current_page(Some(page_number));
self.tab.set_current_page(Some(page_number));
}
page_number
}
// Getters
pub fn gtk(&self) -> &gtk::Notebook {
&self.gtk
pub fn tab(&self) -> &gtk::Notebook {
&self.tab
}
}

View File

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

View File

@ -15,6 +15,7 @@ fn main() -> glib::ExitCode {
// Init accels
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.debug", &["<Ctrl>i"]);
app.set_accels_for_action("win.quit", &["<Ctrl>Escape"]);