mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-10 18:34:14 +00:00
use separated widget mod
This commit is contained in:
parent
166f07aef8
commit
7d4cf5c1f3
@ -1,41 +1,31 @@
|
|||||||
mod pin;
|
mod pin;
|
||||||
mod title;
|
mod title;
|
||||||
|
mod widget;
|
||||||
|
|
||||||
use pin::Pin;
|
use pin::Pin;
|
||||||
use title::Title;
|
use title::Title;
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{glib::GString, Box};
|
||||||
glib::GString,
|
use std::sync::Arc;
|
||||||
prelude::{BoxExt, WidgetExt},
|
|
||||||
Align, Box, Orientation,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Label {
|
pub struct Label {
|
||||||
// Components
|
// Components
|
||||||
pin: Pin,
|
pin: Arc<Pin>,
|
||||||
title: Title,
|
title: Arc<Title>,
|
||||||
|
|
||||||
// GTK
|
// GTK
|
||||||
widget: Box,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(name: GString, is_pinned: bool) -> Label {
|
pub fn new(name: GString, is_pinned: bool) -> Label {
|
||||||
// Components
|
// Components
|
||||||
let pin = Pin::new(is_pinned);
|
let pin = Arc::new(Pin::new(is_pinned));
|
||||||
let title = Title::new();
|
let title = Arc::new(Title::new());
|
||||||
|
|
||||||
// GTK
|
// GTK
|
||||||
let widget = Box::builder()
|
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject()));
|
||||||
.orientation(Orientation::Horizontal)
|
|
||||||
.halign(Align::Center)
|
|
||||||
.name(name)
|
|
||||||
.tooltip_text(title.widget().text())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
widget.append(pin.widget());
|
|
||||||
widget.append(title.widget());
|
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Self { pin, title, widget }
|
Self { pin, title, widget }
|
||||||
@ -43,26 +33,22 @@ impl Label {
|
|||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, title: Option<&GString>) {
|
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);
|
self.title.update(title);
|
||||||
|
self.widget.update(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
pub fn pin(&self, is_pinned: bool) {
|
pub fn pin(&self, is_pinned: bool) {
|
||||||
self.pin.widget().set_visible(is_pinned);
|
self.pin.pin(is_pinned);
|
||||||
self.title.widget().set_visible(!is_pinned);
|
self.title.pin(is_pinned);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn is_pinned(&self) -> bool {
|
pub fn is_pinned(&self) -> bool {
|
||||||
self.pin.widget().is_visible()
|
self.pin.is_pinned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn widget(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,30 @@
|
|||||||
use gtk::Image;
|
use gtk::{prelude::WidgetExt, Image};
|
||||||
|
|
||||||
pub struct Pin {
|
pub struct Pin {
|
||||||
widget: Image,
|
gobject: Image,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pin {
|
impl Pin {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(visible: bool) -> Pin {
|
pub fn new(visible: bool) -> Pin {
|
||||||
let widget = Image::builder()
|
let gobject = Image::builder()
|
||||||
.icon_name("view-pin-symbolic")
|
.icon_name("view-pin-symbolic")
|
||||||
.visible(visible)
|
.visible(visible)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Self { widget }
|
Self { gobject }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pin(&self, is_pinned: bool) {
|
||||||
|
self.gobject().set_visible(is_pinned);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Image {
|
pub fn is_pinned(&self) -> bool {
|
||||||
&self.widget
|
self.gobject.is_visible()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn gobject(&self) -> &Image {
|
||||||
|
&self.gobject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
use gtk::{glib::GString, pango::EllipsizeMode, Label};
|
use gtk::{glib::GString, pango::EllipsizeMode, prelude::WidgetExt, Label};
|
||||||
|
|
||||||
const DEFAULT_LABEL_TEXT: &str = "New page";
|
const DEFAULT_LABEL_TEXT: &str = "New page";
|
||||||
|
|
||||||
pub struct Title {
|
pub struct Title {
|
||||||
widget: Label,
|
gobject: Label,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Title {
|
impl Title {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
widget: Label::builder()
|
gobject: Label::builder()
|
||||||
.label(DEFAULT_LABEL_TEXT)
|
.label(DEFAULT_LABEL_TEXT)
|
||||||
.ellipsize(EllipsizeMode::End)
|
.ellipsize(EllipsizeMode::End)
|
||||||
.width_chars(16)
|
.width_chars(16)
|
||||||
@ -22,13 +22,17 @@ impl Title {
|
|||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, title: Option<&GString>) {
|
pub fn update(&self, title: Option<&GString>) {
|
||||||
match title {
|
match title {
|
||||||
Some(title) => self.widget.set_text(title),
|
Some(title) => self.gobject.set_text(title),
|
||||||
None => self.widget.set_text(DEFAULT_LABEL_TEXT),
|
None => self.gobject.set_text(DEFAULT_LABEL_TEXT),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pin(&self, is_pinned: bool) {
|
||||||
|
self.gobject.set_visible(!is_pinned);
|
||||||
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Label {
|
pub fn gobject(&self) -> &Label {
|
||||||
&self.widget
|
&self.gobject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
src/app/browser/window/tab/label/widget.rs
Normal file
37
src/app/browser/window/tab/label/widget.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user