mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
draft header update on page reload
This commit is contained in:
parent
8977adab77
commit
ca74a29ffa
6 changed files with 72 additions and 10 deletions
|
|
@ -4,11 +4,12 @@ mod tray;
|
||||||
use subject::Subject;
|
use subject::Subject;
|
||||||
use tray::Tray;
|
use tray::Tray;
|
||||||
|
|
||||||
use gtk::HeaderBar;
|
use gtk::{glib::GString, HeaderBar};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
widget: HeaderBar,
|
widget: HeaderBar,
|
||||||
|
subject: Subject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Header {
|
impl Header {
|
||||||
|
|
@ -21,7 +22,12 @@ impl Header {
|
||||||
widget.pack_start(tray.widget());
|
widget.pack_start(tray.widget());
|
||||||
widget.set_title_widget(Some(subject.widget()));
|
widget.set_title_widget(Some(subject.widget()));
|
||||||
|
|
||||||
Arc::new(Self { widget })
|
Arc::new(Self { widget, subject })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
pub fn update(&self, title: GString, description: GString) {
|
||||||
|
self.subject.update(title, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ impl Description {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self) {
|
pub fn update(&self, text: &str) {
|
||||||
self.widget.set_visible(self.widget.text().is_empty());
|
self.widget.set_text(text);
|
||||||
|
self.widget.set_visible(!text.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@ mod description;
|
||||||
mod title;
|
mod title;
|
||||||
|
|
||||||
use description::Description;
|
use description::Description;
|
||||||
use gtk::prelude::BoxExt;
|
|
||||||
use gtk::{Align, Box, Orientation};
|
|
||||||
use title::Title;
|
use title::Title;
|
||||||
|
|
||||||
|
use gtk::{glib::GString, prelude::BoxExt, Align, Box, Orientation};
|
||||||
|
|
||||||
pub struct Subject {
|
pub struct Subject {
|
||||||
widget: Box,
|
widget: Box,
|
||||||
|
title: Title,
|
||||||
|
description: Description,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subject {
|
impl Subject {
|
||||||
|
|
@ -24,7 +26,17 @@ impl Subject {
|
||||||
widget.append(title.widget());
|
widget.append(title.widget());
|
||||||
widget.append(description.widget());
|
widget.append(description.widget());
|
||||||
|
|
||||||
Self { widget }
|
Self {
|
||||||
|
widget,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
pub fn update(&self, title: GString, description: GString) {
|
||||||
|
self.title.update(&title);
|
||||||
|
self.description.update(&description);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ mod tab;
|
||||||
|
|
||||||
use tab::Tab;
|
use tab::Tab;
|
||||||
|
|
||||||
use gtk::{prelude::BoxExt, Box, Orientation};
|
use gtk::{glib::GString, prelude::BoxExt, Box, Orientation};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Main {
|
pub struct Main {
|
||||||
|
|
@ -51,6 +51,14 @@ impl Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
pub fn tab_page_title(&self) -> GString {
|
||||||
|
self.tab.page_title()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tab_page_description(&self) -> GString {
|
||||||
|
self.tab.page_description()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn widget(&self) -> &Box {
|
pub fn widget(&self) -> &Box {
|
||||||
&self.widget
|
&self.widget
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,40 @@ impl Tab {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
pub fn page_title(&self) -> GString {
|
||||||
|
// Get current page
|
||||||
|
if let Some(page_number) = self.widget.current_page() {
|
||||||
|
// Get default widget to extract it name as the ID for childs
|
||||||
|
if let Some(widget) = self.widget.nth_page(Some(page_number)) {
|
||||||
|
// Get widget ID
|
||||||
|
let id = &widget.widget_name();
|
||||||
|
// Get page by widget ID
|
||||||
|
if let Some(page) = self.pages.borrow().get(id) {
|
||||||
|
return page.title();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GString::new() // @TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn page_description(&self) -> GString {
|
||||||
|
// Get current page
|
||||||
|
if let Some(page_number) = self.widget.current_page() {
|
||||||
|
// Get default widget to extract it name as the ID for childs
|
||||||
|
if let Some(widget) = self.widget.nth_page(Some(page_number)) {
|
||||||
|
// Get widget ID
|
||||||
|
let id = &widget.widget_name();
|
||||||
|
// Get page by widget ID
|
||||||
|
if let Some(page) = self.pages.borrow().get(id) {
|
||||||
|
return page.description();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GString::new() // @TODO
|
||||||
|
}
|
||||||
|
|
||||||
pub fn widget(&self) -> &Notebook {
|
pub fn widget(&self) -> &Notebook {
|
||||||
self.widget.as_ref()
|
self.widget.as_ref()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,11 @@ impl Browser {
|
||||||
widget.add_action_entries([
|
widget.add_action_entries([
|
||||||
ActionEntry::builder("update")
|
ActionEntry::builder("update")
|
||||||
.activate({
|
.activate({
|
||||||
|
let header = header.clone();
|
||||||
let main = main.clone();
|
let main = main.clone();
|
||||||
move |this: &ApplicationWindow, _, _| {
|
move |_, _, _| {
|
||||||
// header.update(); @TODO
|
|
||||||
main.update();
|
main.update();
|
||||||
|
header.update(main.tab_page_title(), main.tab_page_description());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build(),
|
.build(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue