Browse Source

use libadwaita WindowTitle

master
yggverse 2 months ago
parent
commit
3106844cc6
  1. 16
      src/app/browser.rs
  2. 18
      src/app/browser/header.rs
  3. 46
      src/app/browser/header/subject.rs
  4. 35
      src/app/browser/header/subject/description.rs
  5. 41
      src/app/browser/header/subject/title.rs
  6. 44
      src/app/browser/header/title.rs
  7. 4
      src/app/browser/header/widget.rs

16
src/app/browser.rs

@ -10,6 +10,7 @@ use window::Window; @@ -10,6 +10,7 @@ use window::Window;
use gtk::{
gio::{AppInfo, AppLaunchContext, SimpleAction},
glib::GString,
prelude::{ActionMapExt, GtkWindowExt},
ApplicationWindow,
};
@ -121,8 +122,21 @@ impl Browser { @@ -121,8 +122,21 @@ impl Browser {
let header = header.clone();
let window = window.clone();
move |_, _| {
// Update window first
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()));
}
});

18
src/app/browser/header.rs

@ -1,17 +1,17 @@ @@ -1,17 +1,17 @@
mod subject;
mod title;
mod tray;
mod widget;
use subject::Subject;
use title::Title;
use tray::Tray;
use widget::Widget;
use adw::HeaderBar;
use gtk::{gio::SimpleAction, glib::GString};
use gtk::gio::SimpleAction;
use std::sync::Arc;
pub struct Header {
subject: Arc<Subject>,
title: Arc<Title>,
// tray: Arc<Subject>,
widget: Arc<Widget>,
}
@ -46,18 +46,18 @@ impl Header { @@ -46,18 +46,18 @@ impl Header {
action_tab_pin,
);
let subject = Arc::new(Subject::new());
let title = Arc::new(Title::new());
// 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
Self { subject, widget }
Self { title, widget }
}
// Actions
pub fn update(&self, title: Option<GString>, description: Option<GString>) {
self.subject.update(title, description);
pub fn update(&self, title: Option<&str>, description: Option<&str>) {
self.title.update(title, description);
}
// Getters

46
src/app/browser/header/subject.rs

@ -1,46 +0,0 @@ @@ -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
}
}

35
src/app/browser/header/subject/description.rs

@ -1,35 +0,0 @@ @@ -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
}
}

41
src/app/browser/header/subject/title.rs

@ -1,41 +0,0 @@ @@ -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

@ -0,0 +1,44 @@ @@ -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
}
}

4
src/app/browser/header/widget.rs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
use adw::HeaderBar;
use adw::{HeaderBar, WindowTitle};
use gtk::Box;
pub struct Widget {
@ -7,7 +7,7 @@ pub struct Widget { @@ -7,7 +7,7 @@ pub struct Widget {
impl Widget {
// 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();
gobject.pack_start(pack_start);

Loading…
Cancel
Save