mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
create parental app mod
This commit is contained in:
parent
2461f2a0fb
commit
b2aa3af46a
37 changed files with 176 additions and 111 deletions
68
src/app/browser/main/tab/label.rs
Normal file
68
src/app/browser/main/tab/label.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
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)
|
||||
.tooltip_text(title.widget().text())
|
||||
.build();
|
||||
|
||||
widget.append(pin.widget());
|
||||
widget.append(title.widget());
|
||||
|
||||
// Result
|
||||
Self { pin, title, widget }
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, title: Option<&GString>) {
|
||||
match title {
|
||||
Some(tooltip_text) => self.widget.set_tooltip_text(Some(tooltip_text)),
|
||||
None => self.widget.set_tooltip_text(None),
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue