mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-11 02:44:15 +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 {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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