begin libadwaita headerbar tabs integration

This commit is contained in:
yggverse 2024-10-10 23:34:06 +03:00
parent 765a24f331
commit ce29a06dda
16 changed files with 269 additions and 156 deletions

View file

@ -1,23 +1,26 @@
mod append;
mod control;
mod menu;
mod tab;
mod widget;
use append::Append;
use control::Control;
use menu::Menu;
use tab::Tab;
use widget::Widget;
use gtk::{
gio::SimpleAction,
prelude::BoxExt,
{Box, Orientation},
};
use adw::TabView;
use gtk::{gio::SimpleAction, Box};
use std::sync::Arc;
pub struct Tray {
gobject: Box,
pub struct Bar {
widget: Arc<Widget>,
}
impl Tray {
pub fn new(
impl Bar {
// Construct
pub fn new_arc(
action_tool_debug: Arc<SimpleAction>,
action_tool_profile_directory: Arc<SimpleAction>,
action_quit: Arc<SimpleAction>,
@ -29,11 +32,13 @@ impl Tray {
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
action_tab_page_navigation_reload: Arc<SimpleAction>,
action_tab_pin: Arc<SimpleAction>,
) -> Self {
view: &TabView,
) -> Arc<Self> {
// Init components
let tab = Tab::new(action_tab_append.clone());
let menu = Menu::new(
let control = Control::new_arc();
let tab = Tab::new_arc(view);
let append = Append::new_arc(action_tab_append.clone());
let menu = Menu::new_arc(
action_tool_debug,
action_tool_profile_directory,
action_quit,
@ -47,21 +52,19 @@ impl Tray {
action_tab_pin,
);
// Init widget
let gobject = Box::builder()
.orientation(Orientation::Horizontal)
.spacing(8)
.build();
gobject.append(menu.gobject());
gobject.append(tab.gobject());
// Return new struct
Self { gobject }
// Build result
Arc::new(Self {
widget: Widget::new_arc(
control.gobject(),
append.gobject(),
menu.gobject(),
tab.gobject(),
),
})
}
// Getters
pub fn gobject(&self) -> &Box {
&self.gobject
&self.widget.gobject()
}
}

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: Arc<SimpleAction>) -> Arc<Self> {
Arc::new(Self {
widget: Widget::new_arc(action_tab_append),
})
}
// Getters
pub fn gobject(&self) -> &Button {
&self.widget.gobject()
}
}

View file

@ -1,16 +1,22 @@
use gtk::{gio::SimpleAction, prelude::ActionExt, prelude::ButtonExt, Button};
use gtk::{
gio::SimpleAction,
prelude::{ActionExt, ButtonExt},
Align, Button,
};
use std::sync::Arc;
pub struct Tab {
pub gobject: Button,
pub struct Widget {
gobject: Button,
}
impl Tab {
impl Widget {
// Construct
pub fn new(action_tab_append: Arc<SimpleAction>) -> Self {
// Init widget
pub fn new_arc(action_tab_append: Arc<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();
@ -19,8 +25,7 @@ impl Tab {
action_tab_append.activate(None);
});
// Return activated struct
Self { gobject }
Arc::new(Self { gobject })
}
// Getters

View file

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

View file

@ -0,0 +1,20 @@
use gtk::{PackType, WindowControls};
use std::sync::Arc;
pub struct Widget {
gobject: WindowControls,
}
impl Widget {
// Construct
pub fn new_arc() -> Arc<Self> {
Arc::new(Self {
gobject: WindowControls::new(PackType::End),
})
}
// Getters
pub fn gobject(&self) -> &WindowControls {
&self.gobject
}
}

View file

@ -1,3 +1,7 @@
mod widget;
use widget::Widget;
use gtk::{
gio::{self, SimpleAction},
glib::{gformat, GString},
@ -8,11 +12,11 @@ use gtk::{
use std::sync::Arc;
pub struct Menu {
gobject: MenuButton,
widget: Arc<Widget>,
}
#[rustfmt::skip] // @TODO template builder?
impl Menu {
pub fn new(
pub fn new_arc(
action_tool_debug: Arc<SimpleAction>,
action_tool_profile_directory: Arc<SimpleAction>,
action_quit: Arc<SimpleAction>,
@ -24,7 +28,7 @@ impl Menu {
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
action_tab_page_navigation_reload: Arc<SimpleAction>,
action_tab_pin: Arc<SimpleAction>,
) -> Self {
) -> Arc<Self> {
// Init model
let model = gio::Menu::new();
@ -65,17 +69,13 @@ impl Menu {
model.append(Some("Quit"), Some(&detailed_action_name(action_quit)));
// Init widget
let gobject = MenuButton::builder().tooltip_text("Menu").build();
gobject.set_menu_model(Some(&model));
// Result
Self { gobject }
Arc::new(Self { widget:Widget::new_arc(&model) })
}
// Getters
pub fn gobject(&self) -> &MenuButton {
&self.gobject
&self.widget.gobject()
}
}

View file

@ -0,0 +1,26 @@
use gtk::{gio::Menu, Align, MenuButton};
use std::sync::Arc;
pub struct Widget {
gobject: MenuButton,
}
impl Widget {
// Construct
pub fn new_arc(model: &Menu) -> Arc<Self> {
Arc::new(Self {
gobject: MenuButton::builder()
.css_classes(["flat"])
.icon_name("open-menu-symbolic")
.menu_model(model)
.tooltip_text("Menu")
.valign(Align::Center)
.build(),
})
}
// Getters
pub fn gobject(&self) -> &MenuButton {
&self.gobject
}
}

View file

@ -0,0 +1,24 @@
mod widget;
use widget::Widget;
use adw::{TabBar, TabView};
use std::sync::Arc;
pub struct Tab {
widget: Arc<Widget>,
}
impl Tab {
// Construct
pub fn new_arc(view: &TabView) -> Arc<Self> {
Arc::new(Self {
widget: Widget::new_arc(view),
})
}
// Getters
pub fn gobject(&self) -> &TabBar {
&self.widget.gobject()
}
}

View file

@ -0,0 +1,20 @@
use adw::{TabBar, TabView};
use std::sync::Arc;
pub struct Widget {
gobject: TabBar,
}
impl Widget {
// Construct
pub fn new_arc(view: &TabView) -> Arc<Self> {
Arc::new(Self {
gobject: TabBar::builder().view(&view).build(),
})
}
// Getters
pub fn gobject(&self) -> &TabBar {
&self.gobject
}
}

View file

@ -0,0 +1,34 @@
use adw::TabBar;
use gtk::{prelude::BoxExt, Box, Button, MenuButton, Orientation, WindowControls};
use std::sync::Arc;
pub struct Widget {
gobject: Box,
}
impl Widget {
// Construct
pub fn new_arc(
control: &WindowControls,
append: &Button,
menu: &MenuButton,
tab: &TabBar,
) -> Arc<Self> {
let gobject = Box::builder()
.orientation(Orientation::Horizontal)
.spacing(8)
.build();
gobject.append(tab);
gobject.append(append);
gobject.append(menu);
gobject.append(control);
Arc::new(Self { gobject })
}
// Getters
pub fn gobject(&self) -> &Box {
&self.gobject
}
}

View file

@ -1,39 +0,0 @@
use adw::WindowTitle;
const DEFAULT_TITLE: &str = "Yoda"; // @TODO
const DEFAULT_SUBTITLE: &str = "";
pub struct Title {
gobject: WindowTitle,
}
impl Title {
// Construct
pub fn new() -> Self {
Self {
gobject: WindowTitle::new(DEFAULT_TITLE, DEFAULT_SUBTITLE),
}
}
// Actions
pub fn update(&self, title: &str, subtitle: &str) {
// Update title
let mut parts = Vec::new();
if !title.is_empty() {
parts.push(title);
}
parts.push(DEFAULT_TITLE);
self.gobject.set_title(&parts.join(" - "));
// Update subtitle
self.gobject.set_subtitle(subtitle);
}
// Getters
pub fn gobject(&self) -> &WindowTitle {
&self.gobject
}
}

View file

@ -1,23 +1,23 @@
use adw::{HeaderBar, WindowTitle};
use adw::ToolbarView;
use gtk::Box;
use std::sync::Arc;
pub struct Widget {
gobject: HeaderBar,
gobject: ToolbarView,
}
impl Widget {
// Construct
pub fn new(pack_start: &Box, title_widget: Option<&WindowTitle>) -> Self {
let gobject = HeaderBar::builder().build();
pub fn new_arc(top_bar: &Box) -> Arc<Self> {
let gobject = ToolbarView::builder().build();
gobject.pack_start(pack_start);
gobject.set_title_widget(title_widget);
gobject.add_top_bar(top_bar);
Self { gobject }
Arc::new(Self { gobject })
}
// Getters
pub fn gobject(&self) -> &HeaderBar {
pub fn gobject(&self) -> &ToolbarView {
&self.gobject
}
}