Browse Source

separate modules to submodule components

master
yggverse 2 months ago
parent
commit
e45b7f0a4a
  1. 7
      src/browser/header/mod.rs
  2. 8
      src/browser/header/subject/description/mod.rs
  3. 11
      src/browser/header/subject/description/widget.rs
  4. 9
      src/browser/header/subject/title/widget.rs
  5. 1
      src/browser/header/subject/widget.rs
  6. 28
      src/browser/header/tray/menu/mod.rs
  7. 25
      src/browser/header/tray/menu/model.rs
  8. 21
      src/browser/header/tray/menu/widget.rs
  9. 33
      src/browser/header/tray/mod.rs
  10. 40
      src/browser/header/tray/tab/mod.rs
  11. 20
      src/browser/header/tray/tab/widget.rs
  12. 25
      src/browser/header/tray/widget.rs
  13. 2
      src/browser/main/widget.rs

7
src/browser/header/mod.rs

@ -8,10 +8,11 @@ pub struct Header { @@ -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(),
),
}
}

8
src/browser/header/subject/description/mod.rs

@ -13,8 +13,12 @@ impl Description { @@ -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

11
src/browser/header/subject/description/widget.rs

@ -11,20 +11,15 @@ impl Description { @@ -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

9
src/browser/header/subject/title/widget.rs

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
const DEFAULT_TEXT: &str = "Yoda";
pub struct Title {
gtk: gtk::Label,
}
@ -9,6 +11,7 @@ impl Title { @@ -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 { @@ -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));
}
}

1
src/browser/header/subject/widget.rs

@ -8,6 +8,7 @@ impl Subject { @@ -8,6 +8,7 @@ impl Subject {
pub fn new(title: &gtk::Label, description: &gtk::Label) -> Subject {
let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.valign(gtk::Align::Center)
.build();
gtk.append(title);

28
src/browser/header/tray/menu/mod.rs

@ -1,17 +1,19 @@ @@ -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
}
}

25
src/browser/header/tray/menu/model.rs

@ -0,0 +1,25 @@ @@ -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
}
}

21
src/browser/header/tray/menu/widget.rs

@ -0,0 +1,21 @@ @@ -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) -> &gtk::MenuButton {
&self.gtk
}
}

33
src/browser/header/tray/mod.rs

@ -1,22 +1,23 @@ @@ -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
}
}

40
src/browser/header/tray/tab/mod.rs

@ -1,27 +1,27 @@ @@ -1,27 +1,27 @@
use std::sync::Arc;
use gtk::prelude::{ButtonExt, WidgetExt};
use gtk::Button;
mod widget;
pub struct Tab {
pub widget: Arc<gtk::Button>,
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
}
}

20
src/browser/header/tray/tab/widget.rs

@ -0,0 +1,20 @@ @@ -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) -> &gtk::Button {
&self.gtk
}
}

25
src/browser/header/tray/widget.rs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
use gtk::prelude::BoxExt;
pub struct Tray {
gtk: gtk::Box,
}
impl Tray {
// Construct
pub fn new(menu: &gtk::MenuButton, tab: &gtk::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) -> &gtk::Box {
&self.gtk
}
}

2
src/browser/main/widget.rs

@ -5,7 +5,7 @@ pub struct Main { @@ -5,7 +5,7 @@ pub struct Main {
}
impl Main {
// Construct
// Construct new object
pub fn new(tab: &gtk::Notebook) -> Main {
let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)

Loading…
Cancel
Save