separate modules to submodule components

This commit is contained in:
yggverse 2024-09-22 20:58:23 +03:00
parent 2c389abdfd
commit e45b7f0a4a
13 changed files with 167 additions and 71 deletions

View file

@ -13,8 +13,12 @@ impl Description {
}
// Actions
pub fn update(&self, text: &str) {
self.widget.update(text);
pub fn set_text(&self, text: &str) {
self.widget.gtk().set_text(text);
}
pub fn update(&self) {
self.widget.update();
}
// Getters

View file

@ -11,20 +11,15 @@ impl Description {
.css_classes(["subtitle"])
.single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End)
.visible(false)
.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();
}
pub fn update(&self) {
self.gtk.set_visible(self.gtk.text().is_empty());
}
// Getters

View file

@ -1,3 +1,5 @@
const DEFAULT_TEXT: &str = "Yoda";
pub struct Title {
gtk: gtk::Label,
}
@ -9,6 +11,7 @@ impl Title {
.css_classes(["title"])
.single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End)
.label(DEFAULT_TEXT)
.build();
Self { gtk }
@ -16,12 +19,10 @@ impl Title {
// Actions
pub fn update(&self, text: &str) {
let default_text = "Yoda"; // @TODO
if text.is_empty() {
self.gtk.set_text(default_text);
self.gtk.set_text(DEFAULT_TEXT);
} else {
self.gtk.set_text(&format!("{} - {}", text, default_text));
self.gtk.set_text(&format!("{} - {}", text, DEFAULT_TEXT));
}
}

View file

@ -8,6 +8,7 @@ impl Subject {
pub fn new(title: &gtk::Label, description: &gtk::Label) -> Subject {
let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.valign(gtk::Align::Center)
.build();
gtk.append(title);