mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
62 lines
1.2 KiB
Rust
62 lines
1.2 KiB
Rust
mod pin;
|
|
mod title;
|
|
|
|
use pin::Pin;
|
|
use title::Title;
|
|
|
|
use gtk::{
|
|
glib::GString,
|
|
prelude::{BoxExt, WidgetExt},
|
|
Align, Box, Orientation,
|
|
};
|
|
|
|
pub struct Label {
|
|
// Components
|
|
pin: Pin,
|
|
title: Title,
|
|
|
|
// GTK
|
|
widget: Box,
|
|
}
|
|
|
|
impl Label {
|
|
// Construct
|
|
pub fn new(name: GString, is_pinned: bool) -> Label {
|
|
// Components
|
|
let pin = Pin::new(is_pinned);
|
|
let title = Title::new();
|
|
|
|
// GTK
|
|
let widget = Box::builder()
|
|
.orientation(Orientation::Horizontal)
|
|
.halign(Align::Center)
|
|
.name(name)
|
|
.build();
|
|
|
|
widget.append(pin.widget());
|
|
widget.append(title.widget());
|
|
|
|
// Result
|
|
Self { pin, title, widget }
|
|
}
|
|
|
|
// Actions
|
|
pub fn update(&self, title: &GString) {
|
|
self.title.update(title);
|
|
}
|
|
|
|
// Setters
|
|
pub fn pin(&self, is_pinned: bool) {
|
|
self.pin.widget().set_visible(is_pinned);
|
|
self.title.widget().set_visible(!is_pinned);
|
|
}
|
|
|
|
// Getters
|
|
pub fn is_pinned(&self) -> bool {
|
|
self.pin.widget().is_visible()
|
|
}
|
|
|
|
pub fn widget(&self) -> &Box {
|
|
&self.widget
|
|
}
|
|
}
|