use separated widget mod

This commit is contained in:
yggverse 2024-10-06 16:17:53 +03:00
parent 166f07aef8
commit 7d4cf5c1f3
4 changed files with 78 additions and 43 deletions

View file

@ -0,0 +1,37 @@
use gtk::{
glib::GString, prelude::BoxExt, prelude::WidgetExt, Align, Box, Image, Label, Orientation,
};
pub struct Widget {
gobject: Box,
}
impl Widget {
// Construct
pub fn new(name: GString, pin: &Image, title: &Label) -> Self {
let gobject = Box::builder()
.orientation(Orientation::Horizontal)
.halign(Align::Center)
.name(name)
.tooltip_text(title.text())
.build();
gobject.append(pin);
gobject.append(title);
Self { gobject }
}
// Action
pub fn update(&self, title: Option<&GString>) {
match title {
Some(tooltip_text) => self.gobject.set_tooltip_text(Some(tooltip_text)),
None => self.gobject.set_tooltip_text(None),
}
}
// Getters
pub fn gobject(&self) -> &Box {
&self.gobject
}
}