mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-10 18:34:14 +00:00
create separated structs for subject entity
This commit is contained in:
parent
6f3ad01c35
commit
2c389abdfd
@ -8,8 +8,10 @@ pub struct Header {
|
||||
|
||||
impl Header {
|
||||
pub fn new() -> Header {
|
||||
let subject = subject::Subject::new();
|
||||
let tray = tray::new();
|
||||
Self {
|
||||
widget: widget::Header::new(&tray::new(), &subject::new()),
|
||||
widget: widget::Header::new(&tray, subject.widget().gtk()), // @TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,24 @@
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::Label;
|
||||
mod widget;
|
||||
|
||||
pub fn new() -> Label {
|
||||
let description = Label::builder()
|
||||
.css_classes(["subtitle"])
|
||||
.single_line_mode(true)
|
||||
.ellipsize(gtk::pango::EllipsizeMode::End)
|
||||
.build();
|
||||
|
||||
update(
|
||||
&description,
|
||||
"", // @TODO
|
||||
);
|
||||
|
||||
description
|
||||
pub struct Description {
|
||||
widget: widget::Description,
|
||||
}
|
||||
|
||||
pub fn update(description: &Label, text: &str) {
|
||||
description.set_text(text);
|
||||
impl Description {
|
||||
// Construct
|
||||
pub fn new() -> Description {
|
||||
Self {
|
||||
widget: widget::Description::new(),
|
||||
}
|
||||
}
|
||||
|
||||
if text.is_empty() {
|
||||
description.hide();
|
||||
} else {
|
||||
description.show();
|
||||
// Actions
|
||||
pub fn update(&self, text: &str) {
|
||||
self.widget.update(text);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &widget::Description {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
34
src/browser/header/subject/description/widget.rs
Normal file
34
src/browser/header/subject/description/widget.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use gtk::prelude::WidgetExt;
|
||||
|
||||
pub struct Description {
|
||||
gtk: gtk::Label,
|
||||
}
|
||||
|
||||
impl Description {
|
||||
// Construct
|
||||
pub fn new() -> Description {
|
||||
let gtk = gtk::Label::builder()
|
||||
.css_classes(["subtitle"])
|
||||
.single_line_mode(true)
|
||||
.ellipsize(gtk::pango::EllipsizeMode::End)
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gtk(&self) -> >k::Label {
|
||||
&self.gtk
|
||||
}
|
||||
}
|
@ -1,20 +1,24 @@
|
||||
mod description;
|
||||
mod title;
|
||||
mod widget;
|
||||
|
||||
use gtk::prelude::BoxExt;
|
||||
use gtk::Box;
|
||||
|
||||
pub fn new() -> Box {
|
||||
let subject = Box::builder()
|
||||
// Tuneup
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.valign(gtk::Align::Center)
|
||||
.build();
|
||||
|
||||
// Compose childs
|
||||
subject.append(&title::new());
|
||||
subject.append(&description::new());
|
||||
|
||||
// Done
|
||||
subject
|
||||
pub struct Subject {
|
||||
widget: widget::Subject,
|
||||
}
|
||||
|
||||
impl Subject {
|
||||
// Construct
|
||||
pub fn new() -> Subject {
|
||||
Self {
|
||||
widget: widget::Subject::new(
|
||||
title::Title::new().widget().gtk(),
|
||||
description::Description::new().widget().gtk(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &widget::Subject {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
use gtk::Label;
|
||||
mod widget;
|
||||
|
||||
pub fn new() -> Label {
|
||||
let title = Label::builder()
|
||||
.css_classes(["title"])
|
||||
.single_line_mode(true)
|
||||
.ellipsize(gtk::pango::EllipsizeMode::End)
|
||||
.build();
|
||||
|
||||
update(&title, "Welcome");
|
||||
|
||||
return title;
|
||||
pub struct Title {
|
||||
widget: widget::Title,
|
||||
}
|
||||
|
||||
pub fn update(title: &Label, text: &str) {
|
||||
let default_text = "Yoda"; // @TODO
|
||||
impl Title {
|
||||
// Construct
|
||||
pub fn new() -> Title {
|
||||
Self {
|
||||
widget: widget::Title::new(),
|
||||
}
|
||||
}
|
||||
|
||||
if text.is_empty() {
|
||||
title.set_text(default_text);
|
||||
} else {
|
||||
title.set_text(&format!("{} - {}", text, default_text));
|
||||
// Actions
|
||||
pub fn update(&self, text: &str) {
|
||||
self.widget.update(text);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &widget::Title {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
32
src/browser/header/subject/title/widget.rs
Normal file
32
src/browser/header/subject/title/widget.rs
Normal file
@ -0,0 +1,32 @@
|
||||
pub struct Title {
|
||||
gtk: gtk::Label,
|
||||
}
|
||||
|
||||
impl Title {
|
||||
// Construct
|
||||
pub fn new() -> Title {
|
||||
let gtk = gtk::Label::builder()
|
||||
.css_classes(["title"])
|
||||
.single_line_mode(true)
|
||||
.ellipsize(gtk::pango::EllipsizeMode::End)
|
||||
.build();
|
||||
|
||||
Self { gtk }
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, text: &str) {
|
||||
let default_text = "Yoda"; // @TODO
|
||||
|
||||
if text.is_empty() {
|
||||
self.gtk.set_text(default_text);
|
||||
} else {
|
||||
self.gtk.set_text(&format!("{} - {}", text, default_text));
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gtk(&self) -> >k::Label {
|
||||
&self.gtk
|
||||
}
|
||||
}
|
22
src/browser/header/subject/widget.rs
Normal file
22
src/browser/header/subject/widget.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use gtk::prelude::BoxExt;
|
||||
|
||||
pub struct Subject {
|
||||
gtk: gtk::Box,
|
||||
}
|
||||
|
||||
impl Subject {
|
||||
pub fn new(title: >k::Label, description: >k::Label) -> Subject {
|
||||
let gtk = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.build();
|
||||
|
||||
gtk.append(title);
|
||||
gtk.append(description);
|
||||
|
||||
Self { gtk }
|
||||
}
|
||||
|
||||
pub fn gtk(&self) -> >k::Box {
|
||||
&self.gtk
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user