diff --git a/src/browser/header/mod.rs b/src/browser/header/mod.rs index 2704570b..dc96671b 100644 --- a/src/browser/header/mod.rs +++ b/src/browser/header/mod.rs @@ -8,10 +8,11 @@ pub struct Header { impl Header { pub fn new() -> Header { - let subject = subject::Subject::new(); - let tray = tray::new(); Self { - widget: widget::Header::new(&tray, subject.widget().gtk()), // @TODO + widget: widget::Header::new( + tray::Tray::new().widget().gtk(), + subject::Subject::new().widget().gtk(), + ), } } diff --git a/src/browser/header/subject/description/mod.rs b/src/browser/header/subject/description/mod.rs index 8be2ae29..66ba83b5 100644 --- a/src/browser/header/subject/description/mod.rs +++ b/src/browser/header/subject/description/mod.rs @@ -13,8 +13,12 @@ impl Description { } // Actions - pub fn update(&self, text: &str) { - self.widget.update(text); + pub fn set_text(&self, text: &str) { + self.widget.gtk().set_text(text); + } + + pub fn update(&self) { + self.widget.update(); } // Getters diff --git a/src/browser/header/subject/description/widget.rs b/src/browser/header/subject/description/widget.rs index 9e7f065b..9b75dff3 100644 --- a/src/browser/header/subject/description/widget.rs +++ b/src/browser/header/subject/description/widget.rs @@ -11,20 +11,15 @@ impl Description { .css_classes(["subtitle"]) .single_line_mode(true) .ellipsize(gtk::pango::EllipsizeMode::End) + .visible(false) .build(); Self { gtk } } // Actions - pub fn update(&self, text: &str) { - self.gtk.set_text(text); - - if text.is_empty() { - self.gtk.hide(); - } else { - self.gtk.show(); - } + pub fn update(&self) { + self.gtk.set_visible(self.gtk.text().is_empty()); } // Getters diff --git a/src/browser/header/subject/title/widget.rs b/src/browser/header/subject/title/widget.rs index e57af1f2..a0f154f6 100644 --- a/src/browser/header/subject/title/widget.rs +++ b/src/browser/header/subject/title/widget.rs @@ -1,3 +1,5 @@ +const DEFAULT_TEXT: &str = "Yoda"; + pub struct Title { gtk: gtk::Label, } @@ -9,6 +11,7 @@ impl Title { .css_classes(["title"]) .single_line_mode(true) .ellipsize(gtk::pango::EllipsizeMode::End) + .label(DEFAULT_TEXT) .build(); Self { gtk } @@ -16,12 +19,10 @@ impl Title { // Actions pub fn update(&self, text: &str) { - let default_text = "Yoda"; // @TODO - if text.is_empty() { - self.gtk.set_text(default_text); + self.gtk.set_text(DEFAULT_TEXT); } else { - self.gtk.set_text(&format!("{} - {}", text, default_text)); + self.gtk.set_text(&format!("{} - {}", text, DEFAULT_TEXT)); } } diff --git a/src/browser/header/subject/widget.rs b/src/browser/header/subject/widget.rs index dd6f6bf8..10fa58ee 100644 --- a/src/browser/header/subject/widget.rs +++ b/src/browser/header/subject/widget.rs @@ -8,6 +8,7 @@ impl Subject { pub fn new(title: >k::Label, description: >k::Label) -> Subject { let gtk = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) + .valign(gtk::Align::Center) .build(); gtk.append(title); diff --git a/src/browser/header/tray/menu/mod.rs b/src/browser/header/tray/menu/mod.rs index 81845360..9bcac4b7 100644 --- a/src/browser/header/tray/menu/mod.rs +++ b/src/browser/header/tray/menu/mod.rs @@ -1,17 +1,19 @@ -use gtk::{gio, MenuButton}; +mod model; +mod widget; -pub fn new() -> MenuButton { - let menu = MenuButton::builder().tooltip_text("Menu").build(); - - let model = gio::Menu::new(); - let model_tab = gio::Menu::new(); - - model_tab.append(Some("Append"), Some("win.tab_append")); - model.append_submenu(Some("Tab"), &model_tab); - model.append(Some("Debug"), Some("win.debug")); - model.append(Some("Quit"), Some("win.quit")); +pub struct Menu { + widget: widget::Menu, +} - menu.set_menu_model(Some(&model)); +impl Menu { + pub fn new() -> Menu { + Self { + widget: widget::Menu::new(model::Menu::new().model()), + } + } - menu + // Getters + pub fn widget(&self) -> &widget::Menu { + &self.widget + } } diff --git a/src/browser/header/tray/menu/model.rs b/src/browser/header/tray/menu/model.rs new file mode 100644 index 00000000..9b561692 --- /dev/null +++ b/src/browser/header/tray/menu/model.rs @@ -0,0 +1,25 @@ +use gtk::gio; + +pub struct Menu { + model: gio::Menu, +} + +impl Menu { + // Construct + pub fn new() -> Menu { + let model = gio::Menu::new(); + let model_tab = gio::Menu::new(); + + model_tab.append(Some("Append"), Some("win.tab_append")); + model.append_submenu(Some("Tab"), &model_tab); + model.append(Some("Debug"), Some("win.debug")); + model.append(Some("Quit"), Some("win.quit")); + + Self { model } + } + + // Getters + pub fn model(&self) -> &gio::Menu { + &self.model + } +} diff --git a/src/browser/header/tray/menu/widget.rs b/src/browser/header/tray/menu/widget.rs new file mode 100644 index 00000000..29c621cb --- /dev/null +++ b/src/browser/header/tray/menu/widget.rs @@ -0,0 +1,21 @@ +use gtk::gio; + +pub struct Menu { + gtk: gtk::MenuButton, +} + +impl Menu { + // Construct + pub fn new(model: &gio::Menu) -> Menu { + let gtk = gtk::MenuButton::builder().tooltip_text("Menu").build(); + + gtk.set_menu_model(Some(model)); + + Self { gtk } + } + + // Getters + pub fn gtk(&self) -> >k::MenuButton { + &self.gtk + } +} diff --git a/src/browser/header/tray/mod.rs b/src/browser/header/tray/mod.rs index 88a4d165..90c0274a 100644 --- a/src/browser/header/tray/mod.rs +++ b/src/browser/header/tray/mod.rs @@ -1,22 +1,23 @@ mod menu; mod tab; +mod widget; -use gtk::prelude::BoxExt; -use gtk::Box; - -pub fn new() -> Box { - // Init components - let tab = tab::new(); - - // Init widget - let tray = Box::builder() - .orientation(gtk::Orientation::Horizontal) - .spacing(8) - .build(); +pub struct Tray { + widget: widget::Tray, +} - // Compose childs - tray.append(&menu::new()); // @TODO - tray.append(tab.widget.as_ref()); +impl Tray { + pub fn new() -> Tray { + Self { + widget: widget::Tray::new( + menu::Menu::new().widget().gtk(), + tab::Tab::new().widget().gtk(), + ), + } + } - tray // @TODO struct + // Getters + pub fn widget(&self) -> &widget::Tray { + &self.widget + } } diff --git a/src/browser/header/tray/tab/mod.rs b/src/browser/header/tray/tab/mod.rs index 18ec5e7f..788b47e3 100644 --- a/src/browser/header/tray/tab/mod.rs +++ b/src/browser/header/tray/tab/mod.rs @@ -1,27 +1,27 @@ -use std::sync::Arc; - -use gtk::prelude::{ButtonExt, WidgetExt}; -use gtk::Button; +mod widget; pub struct Tab { - pub widget: Arc, + pub widget: widget::Tab, } -pub fn new() -> Tab { - // Init widget - let widget = Arc::new( - Button::builder() - .icon_name("tab-new-symbolic") - .tooltip_text("New tab") - .build(), - ); +impl Tab { + pub fn new() -> Tab { + // Init widget + let widget = widget::Tab::new(); + + // Init events + /* @TODO + widget.connect_clicked(|this| { + this.activate_action("win.tab_append", None) + .expect("The action does not exist"); + }); */ - // Init events - widget.connect_clicked(|this| { - this.activate_action("win.tab_append", None) - .expect("The action does not exist"); - }); + // Result + Self { widget } + } - // Result - Tab { widget } + // Getters + pub fn widget(&self) -> &widget::Tab { + &self.widget + } } diff --git a/src/browser/header/tray/tab/widget.rs b/src/browser/header/tray/tab/widget.rs new file mode 100644 index 00000000..362e0549 --- /dev/null +++ b/src/browser/header/tray/tab/widget.rs @@ -0,0 +1,20 @@ +pub struct Tab { + gtk: gtk::Button, +} + +impl Tab { + // Construct + pub fn new() -> Tab { + let gtk = gtk::Button::builder() + .icon_name("tab-new-symbolic") + .tooltip_text("New tab") + .build(); + + Self { gtk } + } + + // Getters + pub fn gtk(&self) -> >k::Button { + &self.gtk + } +} diff --git a/src/browser/header/tray/widget.rs b/src/browser/header/tray/widget.rs new file mode 100644 index 00000000..d38e8e1a --- /dev/null +++ b/src/browser/header/tray/widget.rs @@ -0,0 +1,25 @@ +use gtk::prelude::BoxExt; + +pub struct Tray { + gtk: gtk::Box, +} + +impl Tray { + // Construct + pub fn new(menu: >k::MenuButton, tab: >k::Button) -> Tray { + let gtk = gtk::Box::builder() + .orientation(gtk::Orientation::Horizontal) + .spacing(8) + .build(); + + gtk.append(menu); + gtk.append(tab); + + Self { gtk } + } + + // Getters + pub fn gtk(&self) -> >k::Box { + &self.gtk + } +} diff --git a/src/browser/main/widget.rs b/src/browser/main/widget.rs index cb87ff4d..46661b9e 100644 --- a/src/browser/main/widget.rs +++ b/src/browser/main/widget.rs @@ -5,7 +5,7 @@ pub struct Main { } impl Main { - // Construct + // Construct new object pub fn new(tab: >k::Notebook) -> Main { let gtk = gtk::Box::builder() .orientation(gtk::Orientation::Vertical)