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 { 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::new(), &subject::new()), widget: widget::Header::new(&tray, subject.widget().gtk()), // @TODO
} }
} }

View File

@ -1,27 +1,24 @@
use gtk::prelude::WidgetExt; mod widget;
use gtk::Label;
pub fn new() -> Label { pub struct Description {
let description = Label::builder() widget: widget::Description,
.css_classes(["subtitle"])
.single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End)
.build();
update(
&description,
"", // @TODO
);
description
} }
pub fn update(description: &Label, text: &str) { impl Description {
description.set_text(text); // Construct
pub fn new() -> Description {
Self {
widget: widget::Description::new(),
}
}
if text.is_empty() { // Actions
description.hide(); pub fn update(&self, text: &str) {
} else { self.widget.update(text);
description.show(); }
// 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 description;
mod title; mod title;
mod widget;
use gtk::prelude::BoxExt; pub struct Subject {
use gtk::Box; widget: widget::Subject,
}
pub fn new() -> Box {
let subject = Box::builder() impl Subject {
// Tuneup // Construct
.orientation(gtk::Orientation::Vertical) pub fn new() -> Subject {
.valign(gtk::Align::Center) Self {
.build(); widget: widget::Subject::new(
title::Title::new().widget().gtk(),
// Compose childs description::Description::new().widget().gtk(),
subject.append(&title::new()); ),
subject.append(&description::new()); }
}
// Done
subject // Getters
pub fn widget(&self) -> &widget::Subject {
&self.widget
}
} }

View File

@ -1,23 +1,24 @@
use gtk::Label; mod widget;
pub fn new() -> Label { pub struct Title {
let title = Label::builder() widget: widget::Title,
.css_classes(["title"])
.single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End)
.build();
update(&title, "Welcome");
return title;
} }
pub fn update(title: &Label, text: &str) { impl Title {
let default_text = "Yoda"; // @TODO // Construct
pub fn new() -> Title {
Self {
widget: widget::Title::new(),
}
}
if text.is_empty() { // Actions
title.set_text(default_text); pub fn update(&self, text: &str) {
} else { self.widget.update(text);
title.set_text(&format!("{} - {}", text, default_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
}
}