mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
41 lines
867 B
Rust
41 lines
867 B
Rust
use gtk::{glib::GString, pango::EllipsizeMode, Label};
|
|
|
|
const DEFAULT_TEXT: &str = "Yoda"; // @TODO
|
|
|
|
pub struct Title {
|
|
gobject: Label,
|
|
}
|
|
|
|
impl Title {
|
|
// Construct
|
|
pub fn new() -> Self {
|
|
let gobject = gtk::Label::builder()
|
|
.css_classes(["title"])
|
|
.single_line_mode(true)
|
|
.ellipsize(EllipsizeMode::End)
|
|
.label(DEFAULT_TEXT)
|
|
.build();
|
|
|
|
Self { gobject }
|
|
}
|
|
|
|
// Actions
|
|
pub fn update(&self, text: Option<GString>) {
|
|
let mut name = Vec::new();
|
|
|
|
if let Some(value) = text {
|
|
if !value.is_empty() {
|
|
name.push(value);
|
|
}
|
|
}
|
|
|
|
name.push(GString::from(DEFAULT_TEXT));
|
|
|
|
self.gobject.set_text(&name.join(" - "));
|
|
}
|
|
|
|
// Getters
|
|
pub fn gobject(&self) -> &Label {
|
|
&self.gobject
|
|
}
|
|
}
|