mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
use libadwaita WindowTitle
This commit is contained in:
parent
4ba2698cee
commit
3106844cc6
7 changed files with 70 additions and 134 deletions
|
|
@ -10,6 +10,7 @@ use window::Window;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{AppInfo, AppLaunchContext, SimpleAction},
|
gio::{AppInfo, AppLaunchContext, SimpleAction},
|
||||||
|
glib::GString,
|
||||||
prelude::{ActionMapExt, GtkWindowExt},
|
prelude::{ActionMapExt, GtkWindowExt},
|
||||||
ApplicationWindow,
|
ApplicationWindow,
|
||||||
};
|
};
|
||||||
|
|
@ -121,8 +122,21 @@ impl Browser {
|
||||||
let header = header.clone();
|
let header = header.clone();
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
|
// Update window first
|
||||||
window.update();
|
window.update();
|
||||||
header.update(window.tab_page_title(), window.tab_page_description());
|
|
||||||
|
// Update header
|
||||||
|
let title = match window.tab_page_title() {
|
||||||
|
Some(value) => value,
|
||||||
|
None => GString::new(), // @TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
let subtitle = match window.tab_page_description() {
|
||||||
|
Some(value) => value,
|
||||||
|
None => GString::new(), // @TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
header.update(Some(title.as_str()), Some(subtitle.as_str()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
mod subject;
|
mod title;
|
||||||
mod tray;
|
mod tray;
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
use subject::Subject;
|
use title::Title;
|
||||||
use tray::Tray;
|
use tray::Tray;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use adw::HeaderBar;
|
use adw::HeaderBar;
|
||||||
use gtk::{gio::SimpleAction, glib::GString};
|
use gtk::gio::SimpleAction;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
subject: Arc<Subject>,
|
title: Arc<Title>,
|
||||||
// tray: Arc<Subject>,
|
// tray: Arc<Subject>,
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
@ -46,18 +46,18 @@ impl Header {
|
||||||
action_tab_pin,
|
action_tab_pin,
|
||||||
);
|
);
|
||||||
|
|
||||||
let subject = Arc::new(Subject::new());
|
let title = Arc::new(Title::new());
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Arc::new(Widget::new(tray.gobject(), Some(subject.gobject())));
|
let widget = Arc::new(Widget::new(tray.gobject(), Some(title.gobject())));
|
||||||
|
|
||||||
// Return new struct
|
// Return new struct
|
||||||
Self { subject, widget }
|
Self { title, widget }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, title: Option<GString>, description: Option<GString>) {
|
pub fn update(&self, title: Option<&str>, description: Option<&str>) {
|
||||||
self.subject.update(title, description);
|
self.title.update(title, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
mod description;
|
|
||||||
mod title;
|
|
||||||
|
|
||||||
use description::Description;
|
|
||||||
use title::Title;
|
|
||||||
|
|
||||||
use gtk::{glib::GString, prelude::BoxExt, Align, Box, Orientation};
|
|
||||||
|
|
||||||
pub struct Subject {
|
|
||||||
gobject: Box,
|
|
||||||
title: Title,
|
|
||||||
description: Description,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subject {
|
|
||||||
// Construct
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let title = Title::new();
|
|
||||||
let description = Description::new();
|
|
||||||
|
|
||||||
let gobject = Box::builder()
|
|
||||||
.orientation(Orientation::Vertical)
|
|
||||||
.valign(Align::Center)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
gobject.append(title.gobject());
|
|
||||||
gobject.append(description.gobject());
|
|
||||||
|
|
||||||
Self {
|
|
||||||
gobject,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
pub fn update(&self, title: Option<GString>, description: Option<GString>) {
|
|
||||||
self.title.update(title);
|
|
||||||
self.description.update(description);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
pub fn gobject(&self) -> &Box {
|
|
||||||
&self.gobject
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
use gtk::glib::GString;
|
|
||||||
use gtk::prelude::WidgetExt;
|
|
||||||
use gtk::{pango::EllipsizeMode, Label};
|
|
||||||
|
|
||||||
pub struct Description {
|
|
||||||
gobject: Label,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Description {
|
|
||||||
// Construct
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let gobject = Label::builder()
|
|
||||||
.css_classes(["subtitle"])
|
|
||||||
.single_line_mode(true)
|
|
||||||
.ellipsize(EllipsizeMode::End)
|
|
||||||
.visible(false)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Self { gobject }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
pub fn update(&self, text: Option<GString>) {
|
|
||||||
match text {
|
|
||||||
Some(value) => self.gobject.set_text(&value),
|
|
||||||
None => self.gobject.set_text(""), // @TODO
|
|
||||||
};
|
|
||||||
self.gobject.set_visible(!self.gobject.text().is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
pub fn gobject(&self) -> &Label {
|
|
||||||
&self.gobject
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
use gtk::{glib::GString, pango::EllipsizeMode, Label};
|
|
||||||
|
|
||||||
const DEFAULT_TEXT: &str = "Yoda"; // @TODO
|
|
||||||
|
|
||||||
pub struct Title {
|
|
||||||
gobject: Label,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Title {
|
|
||||||
// Construct
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let gobject = gtk::Label::builder()
|
|
||||||
.css_classes(["title"])
|
|
||||||
.single_line_mode(true)
|
|
||||||
.ellipsize(EllipsizeMode::End)
|
|
||||||
.label(DEFAULT_TEXT)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Self { gobject }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
pub fn update(&self, text: Option<GString>) {
|
|
||||||
let mut name = Vec::new();
|
|
||||||
|
|
||||||
if let Some(value) = text {
|
|
||||||
if !value.is_empty() {
|
|
||||||
name.push(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
name.push(GString::from(DEFAULT_TEXT));
|
|
||||||
|
|
||||||
self.gobject.set_text(&name.join(" - "));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
pub fn gobject(&self) -> &Label {
|
|
||||||
&self.gobject
|
|
||||||
}
|
|
||||||
}
|
|
||||||
44
src/app/browser/header/title.rs
Normal file
44
src/app/browser/header/title.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
use adw::WindowTitle;
|
||||||
|
|
||||||
|
const DEFAULT_TITLE: &str = "Yoda"; // @TODO
|
||||||
|
const DEFAULT_SUBTITLE: &str = "";
|
||||||
|
|
||||||
|
pub struct Title {
|
||||||
|
gobject: WindowTitle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Title {
|
||||||
|
// Construct
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
gobject: WindowTitle::new(DEFAULT_TITLE, DEFAULT_SUBTITLE),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
pub fn update(&self, title: Option<&str>, subtitle: Option<&str>) {
|
||||||
|
// Update title
|
||||||
|
let mut name = Vec::new();
|
||||||
|
|
||||||
|
if let Some(value) = title {
|
||||||
|
if !value.is_empty() {
|
||||||
|
name.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
name.push(DEFAULT_TITLE);
|
||||||
|
|
||||||
|
self.gobject.set_title(&name.join(" - "));
|
||||||
|
|
||||||
|
// Update subtitle
|
||||||
|
self.gobject.set_subtitle(&match subtitle {
|
||||||
|
Some(value) => value,
|
||||||
|
None => "", // @TODO
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &WindowTitle {
|
||||||
|
&self.gobject
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use adw::HeaderBar;
|
use adw::{HeaderBar, WindowTitle};
|
||||||
use gtk::Box;
|
use gtk::Box;
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
|
|
@ -7,7 +7,7 @@ pub struct Widget {
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(pack_start: &Box, title_widget: Option<&Box>) -> Self {
|
pub fn new(pack_start: &Box, title_widget: Option<&WindowTitle>) -> Self {
|
||||||
let gobject = HeaderBar::builder().build();
|
let gobject = HeaderBar::builder().build();
|
||||||
|
|
||||||
gobject.pack_start(pack_start);
|
gobject.pack_start(pack_start);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue