mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
reorganize widget modules
This commit is contained in:
parent
b9b226cc54
commit
4903968309
47 changed files with 352 additions and 786 deletions
|
|
@ -1,46 +1,47 @@
|
|||
mod pin;
|
||||
mod title;
|
||||
mod widget;
|
||||
|
||||
use std::sync::Arc;
|
||||
use gtk::prelude::{BoxExt, WidgetExt};
|
||||
use gtk::{Box, Orientation};
|
||||
use pin::Pin;
|
||||
use title::Title;
|
||||
|
||||
pub struct Label {
|
||||
// Components
|
||||
pin: Arc<pin::Pin>,
|
||||
title: Arc<title::Title>,
|
||||
pin: Pin,
|
||||
title: Title,
|
||||
|
||||
// Extras
|
||||
is_pinned: bool,
|
||||
widget: widget::Label,
|
||||
// GTK
|
||||
widget: Box,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
// Construct
|
||||
pub fn new(is_pinned: bool) -> Arc<Label> {
|
||||
pub fn new(is_pinned: bool) -> Label {
|
||||
// Components
|
||||
let pin = pin::Pin::new(is_pinned);
|
||||
let title = title::Title::new();
|
||||
let pin = Pin::new(is_pinned);
|
||||
let title = Title::new();
|
||||
|
||||
// Extras
|
||||
let widget = widget::Label::new(pin.widget().image(), title.widget().label());
|
||||
// GTK
|
||||
let widget = Box::builder().orientation(Orientation::Horizontal).build();
|
||||
|
||||
widget.append(pin.widget());
|
||||
widget.append(title.widget());
|
||||
|
||||
// Result
|
||||
Arc::new(Self {
|
||||
pin,
|
||||
title,
|
||||
is_pinned,
|
||||
widget,
|
||||
})
|
||||
Self { pin, title, widget }
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn pin(&mut self) {
|
||||
self.is_pinned = !self.is_pinned; // toggle
|
||||
// @TODO
|
||||
pub fn pin(&self) -> bool {
|
||||
self.pin
|
||||
.widget()
|
||||
.set_visible(!self.pin.widget().is_visible());
|
||||
self.pin.widget().is_visible()
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &widget::Label {
|
||||
pub fn widget(&self) -> &Box {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,22 @@
|
|||
mod widget;
|
||||
|
||||
use gtk::prelude::WidgetExt;
|
||||
use std::sync::Arc;
|
||||
use gtk::Image;
|
||||
|
||||
pub struct Pin {
|
||||
// Extras
|
||||
is_pinned: bool,
|
||||
widget: widget::Pin,
|
||||
widget: Image,
|
||||
}
|
||||
|
||||
impl Pin {
|
||||
// Construct
|
||||
pub fn new(is_pinned: bool) -> Arc<Pin> {
|
||||
Arc::new(Self {
|
||||
is_pinned,
|
||||
widget: widget::Pin::new(is_pinned),
|
||||
})
|
||||
}
|
||||
pub fn new(visible: bool) -> Pin {
|
||||
let widget = Image::builder()
|
||||
.icon_name("view-pin-symbolic")
|
||||
.visible(visible)
|
||||
.build();
|
||||
|
||||
// Actions
|
||||
pub fn toggle(&mut self) -> bool {
|
||||
// Toggle state
|
||||
self.is_pinned = !self.widget().image().is_visible();
|
||||
|
||||
// Update widget
|
||||
self.widget().image().set_visible(self.is_pinned); // @TODO delegate?
|
||||
|
||||
// Return state
|
||||
self.is_pinned
|
||||
Self { widget }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &widget::Pin {
|
||||
pub fn widget(&self) -> &Image {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
pub struct Pin {
|
||||
image: gtk::Image,
|
||||
}
|
||||
|
||||
impl Pin {
|
||||
// Construct
|
||||
pub fn new(is_pinned: bool) -> Pin {
|
||||
let image = gtk::Image::builder()
|
||||
.icon_name("view-pin-symbolic")
|
||||
.visible(is_pinned)
|
||||
.build();
|
||||
|
||||
Self { image }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn image(&self) -> >k::Image {
|
||||
&self.image
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,24 @@
|
|||
mod widget;
|
||||
|
||||
use std::sync::Arc;
|
||||
use gtk::{pango::EllipsizeMode, Label};
|
||||
|
||||
pub struct Title {
|
||||
widget: widget::Title,
|
||||
widget: Label,
|
||||
}
|
||||
|
||||
impl Title {
|
||||
// Construct
|
||||
pub fn new() -> Arc<Title> {
|
||||
Arc::new(Self {
|
||||
widget: widget::Title::new(),
|
||||
})
|
||||
pub fn new() -> Title {
|
||||
Self {
|
||||
widget: Label::builder()
|
||||
.label("New page")
|
||||
.ellipsize(EllipsizeMode::End)
|
||||
.width_chars(16)
|
||||
.single_line_mode(true)
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &widget::Title {
|
||||
pub fn widget(&self) -> &Label {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
pub struct Title {
|
||||
label: gtk::Label,
|
||||
}
|
||||
|
||||
impl Title {
|
||||
// Construct
|
||||
pub fn new() -> Title {
|
||||
let label = gtk::Label::builder()
|
||||
.label("New page")
|
||||
.ellipsize(gtk::pango::EllipsizeMode::End)
|
||||
.width_chars(16)
|
||||
.single_line_mode(true)
|
||||
.build();
|
||||
|
||||
Self { label }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn label(&self) -> >k::Label {
|
||||
&self.label
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
use gtk::prelude::BoxExt;
|
||||
|
||||
pub struct Label {
|
||||
container: gtk::Box,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
// Construct new object
|
||||
pub fn new(pin: >k::Image, title: >k::Label) -> Label {
|
||||
let container = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
|
||||
container.append(pin);
|
||||
container.append(title);
|
||||
|
||||
Self { container }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn container(&self) -> >k::Box {
|
||||
&self.container
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue