implement bar box as trait

This commit is contained in:
yggverse 2025-01-26 15:58:12 +02:00
parent 8b4d184ad7
commit 137a1c72b6
3 changed files with 24 additions and 55 deletions

View file

@ -6,6 +6,7 @@ use widget::Widget;
use super::{Action as WindowAction, BrowserAction, Profile};
use adw::TabView;
use gtk::Box;
use std::rc::Rc;
pub struct Header {
@ -21,16 +22,12 @@ impl Header {
profile: &Rc<Profile>,
tab_view: &TabView,
) -> Self {
// Init components
let bar = Rc::new(Bar::build(
(browser_action, window_action),
profile,
tab_view,
));
// Return new struct
Self {
widget: Rc::new(Widget::build(&bar.widget.g_box)),
widget: Rc::new(Widget::build(&Box::bar(
(browser_action, window_action),
profile,
tab_view,
))),
}
}
}

View file

@ -1,39 +1,41 @@
mod control;
mod menu;
mod tab;
mod widget;
use control::Control;
use menu::Menu;
use tab::Tab;
use widget::Widget;
use super::{BrowserAction, Profile, WindowAction};
use adw::TabView;
use gtk::{prelude::BoxExt, Box, Orientation};
use std::rc::Rc;
pub struct Bar {
pub widget: Rc<Widget>,
pub trait Bar {
fn bar(
action: (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>,
view: &TabView,
) -> Self;
}
impl Bar {
impl Bar for Box {
// Constructors
/// Build new `Self`
pub fn build(
fn bar(
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>,
view: &TabView,
) -> Self {
let control = Control::new();
let tab = Tab::new(window_action, view);
let menu = Rc::new(Menu::build((browser_action, window_action), profile));
Self {
widget: Rc::new(Widget::build(
&control.window_controls,
&menu.menu_button,
&tab.widget.tab_bar,
)),
}
let g_box = Box::builder()
.orientation(Orientation::Horizontal)
.spacing(8)
.build();
g_box.append(&Tab::new(window_action, view).widget.tab_bar);
g_box.append(&Menu::build((browser_action, window_action), profile).menu_button);
g_box.append(&Control::new().window_controls);
g_box
}
}

View file

@ -1,30 +0,0 @@
use gtk::{
prelude::{BoxExt, IsA},
Box, Orientation,
};
pub struct Widget {
pub g_box: Box,
}
impl Widget {
// Constructors
/// Build new `Self`
pub fn build(
control: &impl IsA<gtk::Widget>,
menu: &impl IsA<gtk::Widget>,
tab: &impl IsA<gtk::Widget>,
) -> Self {
let g_box = Box::builder()
.orientation(Orientation::Horizontal)
.spacing(8)
.build();
g_box.append(tab);
g_box.append(menu);
g_box.append(control);
Self { g_box }
}
}