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. 28
      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 {
impl Header { impl Header {
pub fn new() -> Header { pub fn new() -> Header {
let subject = subject::Subject::new();
let tray = tray::new();
Self { 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 {
} }
// Actions // Actions
pub fn update(&self, text: &str) { pub fn set_text(&self, text: &str) {
self.widget.update(text); self.widget.gtk().set_text(text);
}
pub fn update(&self) {
self.widget.update();
} }
// Getters // Getters

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

@ -11,20 +11,15 @@ impl Description {
.css_classes(["subtitle"]) .css_classes(["subtitle"])
.single_line_mode(true) .single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End) .ellipsize(gtk::pango::EllipsizeMode::End)
.visible(false)
.build(); .build();
Self { gtk } Self { gtk }
} }
// Actions // Actions
pub fn update(&self, text: &str) { pub fn update(&self) {
self.gtk.set_text(text); self.gtk.set_visible(self.gtk.text().is_empty());
if text.is_empty() {
self.gtk.hide();
} else {
self.gtk.show();
}
} }
// Getters // Getters

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

@ -1,3 +1,5 @@
const DEFAULT_TEXT: &str = "Yoda";
pub struct Title { pub struct Title {
gtk: gtk::Label, gtk: gtk::Label,
} }
@ -9,6 +11,7 @@ impl Title {
.css_classes(["title"]) .css_classes(["title"])
.single_line_mode(true) .single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End) .ellipsize(gtk::pango::EllipsizeMode::End)
.label(DEFAULT_TEXT)
.build(); .build();
Self { gtk } Self { gtk }
@ -16,12 +19,10 @@ impl Title {
// Actions // Actions
pub fn update(&self, text: &str) { pub fn update(&self, text: &str) {
let default_text = "Yoda"; // @TODO
if text.is_empty() { if text.is_empty() {
self.gtk.set_text(default_text); self.gtk.set_text(DEFAULT_TEXT);
} else { } 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 {
pub fn new(title: &gtk::Label, description: &gtk::Label) -> Subject { pub fn new(title: &gtk::Label, description: &gtk::Label) -> Subject {
let gtk = gtk::Box::builder() let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)
.valign(gtk::Align::Center)
.build(); .build();
gtk.append(title); gtk.append(title);

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

@ -1,17 +1,19 @@
use gtk::{gio, MenuButton}; mod model;
mod widget;
pub fn new() -> MenuButton { pub struct Menu {
let menu = MenuButton::builder().tooltip_text("Menu").build(); widget: widget::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"));
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 @@
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 @@
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 @@
mod menu; mod menu;
mod tab; mod tab;
mod widget;
use gtk::prelude::BoxExt; pub struct Tray {
use gtk::Box; widget: widget::Tray,
}
pub fn new() -> Box {
// Init components
let tab = tab::new();
// Init widget
let tray = Box::builder()
.orientation(gtk::Orientation::Horizontal)
.spacing(8)
.build();
// Compose childs impl Tray {
tray.append(&menu::new()); // @TODO pub fn new() -> Tray {
tray.append(tab.widget.as_ref()); 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
}
} }

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

@ -1,27 +1,27 @@
use std::sync::Arc; mod widget;
use gtk::prelude::{ButtonExt, WidgetExt};
use gtk::Button;
pub struct Tab { pub struct Tab {
pub widget: Arc<gtk::Button>, pub widget: widget::Tab,
} }
pub fn new() -> Tab { impl Tab {
pub fn new() -> Tab {
// Init widget // Init widget
let widget = Arc::new( let widget = widget::Tab::new();
Button::builder()
.icon_name("tab-new-symbolic")
.tooltip_text("New tab")
.build(),
);
// Init events // Init events
/* @TODO
widget.connect_clicked(|this| { widget.connect_clicked(|this| {
this.activate_action("win.tab_append", None) this.activate_action("win.tab_append", None)
.expect("The action does not exist"); .expect("The action does not exist");
}); }); */
// Result // Result
Tab { widget } Self { widget }
}
// Getters
pub fn widget(&self) -> &widget::Tab {
&self.widget
}
} }

20
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) -> &gtk::Button {
&self.gtk
}
}

25
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: &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 {
} }
impl Main { impl Main {
// Construct // Construct new object
pub fn new(tab: &gtk::Notebook) -> Main { pub fn new(tab: &gtk::Notebook) -> Main {
let gtk = gtk::Box::builder() let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)

Loading…
Cancel
Save