implement tab node as trait

This commit is contained in:
yggverse 2025-01-26 16:02:45 +02:00
parent 137a1c72b6
commit 680bf0f0aa
3 changed files with 14 additions and 40 deletions

View file

@ -7,7 +7,7 @@ use menu::Menu;
use tab::Tab;
use super::{BrowserAction, Profile, WindowAction};
use adw::TabView;
use adw::{TabBar, TabView};
use gtk::{prelude::BoxExt, Box, Orientation};
use std::rc::Rc;
@ -33,7 +33,7 @@ impl Bar for Box {
.spacing(8)
.build();
g_box.append(&Tab::new(window_action, view).widget.tab_bar);
g_box.append(&TabBar::tab(window_action, view));
g_box.append(&Menu::build((browser_action, window_action), profile).menu_button);
g_box.append(&Control::new().window_controls);
g_box

View file

@ -1,25 +1,21 @@
mod append;
mod widget;
use append::Append;
use widget::Widget;
use super::WindowAction;
use adw::TabView;
use adw::{TabBar, TabView};
use append::Append;
use std::rc::Rc;
pub struct Tab {
pub widget: Rc<Widget>,
pub trait Tab {
fn tab(window_action: &Rc<WindowAction>, view: &TabView) -> Self;
}
impl Tab {
// Construct
pub fn new(window_action: &Rc<WindowAction>, view: &TabView) -> Self {
Self {
widget: Rc::new(Widget::build(
view,
&Append::build(window_action).widget.button,
)),
}
impl Tab for TabBar {
fn tab(window_action: &Rc<WindowAction>, view: &TabView) -> Self {
TabBar::builder()
.autohide(false)
.expand_tabs(false)
.end_action_widget(&Append::build(window_action).widget.button) // @TODO find solution to append after tabs
.view(view)
.build()
}
}

View file

@ -1,22 +0,0 @@
use adw::{TabBar, TabView};
use gtk::prelude::IsA;
pub struct Widget {
pub tab_bar: TabBar,
}
impl Widget {
// Constructors
/// Build new `Self`
pub fn build(view: &TabView, start_action_widget: &impl IsA<gtk::Widget>) -> Self {
Self {
tab_bar: TabBar::builder()
.autohide(false)
.expand_tabs(false)
.end_action_widget(start_action_widget) // @TODO find solution to append after tabs
.view(view)
.build(),
}
}
}