create separated structs for subject entity

This commit is contained in:
yggverse 2024-09-22 19:51:06 +03:00
parent 6f3ad01c35
commit 2c389abdfd
7 changed files with 147 additions and 55 deletions

View File

@ -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
}
}

View File

@ -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
}
}

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

View File

@ -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
}
}

View File

@ -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
}
}

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

View File

@ -0,0 +1,22 @@
use gtk::prelude::BoxExt;
pub struct Subject {
gtk: gtk::Box,
}
impl Subject {
pub fn new(title: &gtk::Label, description: &gtk::Label) -> Subject {
let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
gtk.append(title);
gtk.append(description);
Self { gtk }
}
pub fn gtk(&self) -> &gtk::Box {
&self.gtk
}
}