mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-11 13:11:08 +00:00
separate modules to submodule components
This commit is contained in:
parent
2c389abdfd
commit
e45b7f0a4a
@ -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(),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,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
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ impl Subject {
|
|||||||
pub fn new(title: >k::Label, description: >k::Label) -> Subject {
|
pub fn new(title: >k::Label, description: >k::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);
|
||||||
|
@ -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();
|
impl Menu {
|
||||||
|
pub fn new() -> Menu {
|
||||||
model_tab.append(Some("Append"), Some("win.tab_append"));
|
Self {
|
||||||
model.append_submenu(Some("Tab"), &model_tab);
|
widget: widget::Menu::new(model::Menu::new().model()),
|
||||||
model.append(Some("Debug"), Some("win.debug"));
|
}
|
||||||
model.append(Some("Quit"), Some("win.quit"));
|
}
|
||||||
|
|
||||||
menu.set_menu_model(Some(&model));
|
// Getters
|
||||||
|
pub fn widget(&self) -> &widget::Menu {
|
||||||
menu
|
&self.widget
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
25
src/browser/header/tray/menu/model.rs
Normal file
25
src/browser/header/tray/menu/model.rs
Normal file
@ -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
Normal file
21
src/browser/header/tray/menu/widget.rs
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
impl Tray {
|
||||||
let tab = tab::new();
|
pub fn new() -> Tray {
|
||||||
|
Self {
|
||||||
// Init widget
|
widget: widget::Tray::new(
|
||||||
let tray = Box::builder()
|
menu::Menu::new().widget().gtk(),
|
||||||
.orientation(gtk::Orientation::Horizontal)
|
tab::Tab::new().widget().gtk(),
|
||||||
.spacing(8)
|
),
|
||||||
.build();
|
}
|
||||||
|
}
|
||||||
// Compose childs
|
|
||||||
tray.append(&menu::new()); // @TODO
|
// Getters
|
||||||
tray.append(tab.widget.as_ref());
|
pub fn widget(&self) -> &widget::Tray {
|
||||||
|
&self.widget
|
||||||
tray // @TODO struct
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
// Init widget
|
pub fn new() -> Tab {
|
||||||
let widget = Arc::new(
|
// Init widget
|
||||||
Button::builder()
|
let widget = widget::Tab::new();
|
||||||
.icon_name("tab-new-symbolic")
|
|
||||||
.tooltip_text("New tab")
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
widget.connect_clicked(|this| {
|
/* @TODO
|
||||||
this.activate_action("win.tab_append", None)
|
widget.connect_clicked(|this| {
|
||||||
.expect("The action does not exist");
|
this.activate_action("win.tab_append", None)
|
||||||
});
|
.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
Normal file
20
src/browser/header/tray/tab/widget.rs
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
25
src/browser/header/tray/widget.rs
Normal file
25
src/browser/header/tray/widget.rs
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ pub struct Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Main {
|
impl Main {
|
||||||
// Construct
|
// Construct new object
|
||||||
pub fn new(tab: >k::Notebook) -> Main {
|
pub fn new(tab: >k::Notebook) -> Main {
|
||||||
let gtk = gtk::Box::builder()
|
let gtk = gtk::Box::builder()
|
||||||
.orientation(gtk::Orientation::Vertical)
|
.orientation(gtk::Orientation::Vertical)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user