From 137a1c72b6151e0a1e419cf0e41d2a340b469217 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 26 Jan 2025 15:58:12 +0200 Subject: [PATCH] implement bar box as trait --- src/app/browser/window/header.rs | 15 ++++----- src/app/browser/window/header/bar.rs | 34 +++++++++++---------- src/app/browser/window/header/bar/widget.rs | 30 ------------------ 3 files changed, 24 insertions(+), 55 deletions(-) delete mode 100644 src/app/browser/window/header/bar/widget.rs diff --git a/src/app/browser/window/header.rs b/src/app/browser/window/header.rs index ca6a847d..f173fa6b 100644 --- a/src/app/browser/window/header.rs +++ b/src/app/browser/window/header.rs @@ -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, 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, + ))), } } } diff --git a/src/app/browser/window/header/bar.rs b/src/app/browser/window/header/bar.rs index 54ab1879..a3d9186b 100644 --- a/src/app/browser/window/header/bar.rs +++ b/src/app/browser/window/header/bar.rs @@ -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, +pub trait Bar { + fn bar( + action: (&Rc, &Rc), + profile: &Rc, + view: &TabView, + ) -> Self; } -impl Bar { +impl Bar for Box { // Constructors /// Build new `Self` - pub fn build( + fn bar( (browser_action, window_action): (&Rc, &Rc), profile: &Rc, 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 } } diff --git a/src/app/browser/window/header/bar/widget.rs b/src/app/browser/window/header/bar/widget.rs deleted file mode 100644 index 16dd8bde..00000000 --- a/src/app/browser/window/header/bar/widget.rs +++ /dev/null @@ -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, - menu: &impl IsA, - tab: &impl IsA, - ) -> 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 } - } -}