move new tab button into the tabs start widget

This commit is contained in:
yggverse 2024-10-31 16:16:02 +02:00
parent 1ffc5c1edb
commit 6aee2edd75
6 changed files with 12 additions and 21 deletions

View file

@ -0,0 +1,24 @@
mod widget;
use widget::Widget;
use gtk::{gio::SimpleAction, Button};
use std::sync::Arc;
pub struct Append {
pub widget: Arc<Widget>,
}
impl Append {
// Construct
pub fn new_arc(action_tab_append: SimpleAction) -> Arc<Self> {
Arc::new(Self {
widget: Widget::new_arc(action_tab_append),
})
}
// Getters
pub fn gobject(&self) -> &Button {
&self.widget.gobject()
}
}

View file

@ -0,0 +1,35 @@
use gtk::{
gio::SimpleAction,
prelude::{ActionExt, ButtonExt},
Align, Button,
};
use std::sync::Arc;
pub struct Widget {
gobject: Button,
}
impl Widget {
// Construct
pub fn new_arc(action_tab_append: SimpleAction) -> Arc<Self> {
// Init gobject
let gobject = Button::builder()
.icon_name("tab-new-symbolic")
.css_classes(["flat"])
.valign(Align::Center)
.tooltip_text("New tab")
.build();
// Init events
gobject.connect_clicked(move |_| {
action_tab_append.activate(None);
});
Arc::new(Self { gobject })
}
// Getters
pub fn gobject(&self) -> &Button {
&self.gobject
}
}

View file

@ -1,4 +1,5 @@
use adw::{TabBar, TabView};
use gtk::prelude::IsA;
use std::sync::Arc;
pub struct Widget {
@ -7,11 +8,12 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_arc(view: &TabView) -> Arc<Self> {
pub fn new_arc(view: &TabView, start_action_widget: &impl IsA<gtk::Widget>) -> Arc<Self> {
Arc::new(Self {
gobject: TabBar::builder()
.autohide(false)
.expand_tabs(false)
.start_action_widget(start_action_widget)
.view(&view)
.build(),
})