From 022082b7255733b375f2b42f8fb27717aaa669cc Mon Sep 17 00:00:00 2001 From: takotori Date: Sat, 18 Nov 2023 10:00:37 +0100 Subject: [PATCH] breadcrumb wip --- Cargo.toml | 1 + src/components/breadcrumb/breadcrumb.rs | 66 +++++++++++++++++ src/components/breadcrumb/breadcrumbImpl.rs | 61 ++++++++++++++++ src/components/breadcrumb/breadcrumbItem.rs | 21 ++++++ .../breadcrumb/breadcrumbItemImpl.rs | 40 +++++++++++ src/components/breadcrumb/mod.rs | 5 ++ src/components/mod.rs | 3 +- src/components/wifi/wifiBox.rs | 54 +++++++++++--- src/components/wifi/wifiBoxImpl.rs | 16 +++-- src/components/window/handleSidebarClick.rs | 70 ++++++++++++------- src/components/window/sidebarEntry.rs | 4 +- src/components/window/sidebarEntryImpl.rs | 4 +- src/components/window/window.rs | 29 +++++--- src/components/window/windowImpl.rs | 10 +-- src/resources/resetBreadcrumb.ui | 14 ++++ src/resources/resetBreadcrumbItem.ui | 15 ++++ src/resources/resetMainWindow.ui | 47 ++----------- src/resources/resetUI.cmb | 50 +++++++------ src/resources/resetWiFi.ui | 4 +- src/resources/resources.gresource.xml | 2 + 20 files changed, 391 insertions(+), 125 deletions(-) create mode 100644 src/components/breadcrumb/breadcrumb.rs create mode 100644 src/components/breadcrumb/breadcrumbImpl.rs create mode 100644 src/components/breadcrumb/breadcrumbItem.rs create mode 100644 src/components/breadcrumb/breadcrumbItemImpl.rs create mode 100644 src/components/breadcrumb/mod.rs create mode 100644 src/resources/resetBreadcrumb.ui create mode 100644 src/resources/resetBreadcrumbItem.ui diff --git a/Cargo.toml b/Cargo.toml index c6a2adb..d028a42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ tokio = { version = "1.33.0", features = [ "sync", ] } fork = "0.1.22" +once_cell = "1.18.0" [build-dependencies] glib-build-tools = "0.18.0" diff --git a/src/components/breadcrumb/breadcrumb.rs b/src/components/breadcrumb/breadcrumb.rs new file mode 100644 index 0000000..92bb6d0 --- /dev/null +++ b/src/components/breadcrumb/breadcrumb.rs @@ -0,0 +1,66 @@ +use adw::glib; +use adw::glib::Object; +use glib::{closure_local, ObjectExt, PropertyGet}; +use glib::subclass::prelude::ObjectSubclassIsExt; +use gtk::Label; +use gtk::prelude::{BoxExt, WidgetExt}; + +use crate::components::breadcrumb::{breadcrumbImpl, CustomButton}; +use crate::components::breadcrumb::breadcrumbItem::BreadcrumbItem; + +glib::wrapper! { + pub struct Breadcrumb(ObjectSubclass) + @extends gtk::Box, gtk::Widget, + @implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget; +} + +impl Breadcrumb { + pub fn new() -> Self { + Object::builder().build() + } + + pub fn resetAndSet(&self, name : &str) { + let selfImp = self.imp(); + loop { + let option = selfImp.resetBox.last_child(); + match option { + None => break, + Some(last) => selfImp.resetBox.remove(&last) + } + } + *selfImp.items.borrow_mut() = 0; + self.pushBreadcrumb(name); + } + + pub fn pushBreadcrumb(&self, name: &str) { + let selfImp = self.imp(); + + let button = CustomButton::new(); + button.connect_closure("max-number-reached", + false, + closure_local!(move |_button: CustomButton, number: i32| { + println!("The maximum number {} has been reached", number); + })); + + + let mut items = selfImp.items.borrow_mut(); + if *items != 0 { + selfImp.resetBox.append(&Label::new(Some(">"))); + }; + *items += 1; + + selfImp.resetBox.append(&BreadcrumbItem::new(name)); + selfImp.resetBox.append(&button); + } + + pub fn popBreadcrumb(&self) { + let selfImp = self.imp(); + for _ in 0..2 { + let option = selfImp.resetBox.last_child(); + match option { + None => break, + Some(last) => selfImp.resetBox.remove(&last) + } + } + } +} diff --git a/src/components/breadcrumb/breadcrumbImpl.rs b/src/components/breadcrumb/breadcrumbImpl.rs new file mode 100644 index 0000000..cd94983 --- /dev/null +++ b/src/components/breadcrumb/breadcrumbImpl.rs @@ -0,0 +1,61 @@ +use std::cell::{Cell, RefCell}; +use glib::{Properties, StaticType, StaticTypeExt}; +use glib::subclass::Signal; +use gtk::subclass::prelude::*; +use gtk::{glib, CompositeTemplate}; +use once_cell::sync::Lazy; +use gtk::prelude::*; +use crate::components::breadcrumb::breadcrumb; +use crate::components::breadcrumb::breadcrumbItem::BreadcrumbItem; + +#[allow(non_snake_case)] +#[derive(Properties, Default, CompositeTemplate)] +#[properties(wrapper_type = breadcrumb::Breadcrumb)] +#[template(resource = "/org/Xetibo/ReSet/resetBreadcrumb.ui")] +pub struct Breadcrumb { + #[template_child] + pub resetBox: TemplateChild, + pub items: RefCell, + #[property(get, set)] + number2: Cell, +} + +#[glib::object_subclass] +impl ObjectSubclass for Breadcrumb { + const NAME: &'static str = "resetBreadcrumb"; + type Type = breadcrumb::Breadcrumb; + type ParentType = gtk::Box; + + fn class_init(klass: &mut Self::Class) { + BreadcrumbItem::ensure_type(); + klass.bind_template(); + } + + fn instance_init(obj: &glib::subclass::InitializingObject) { + obj.init_template(); + } +} + +#[glib::derived_properties] +impl ObjectImpl for Breadcrumb { + fn signals () -> &'static [Signal] { + static SIGNALS: Lazy> = Lazy::new(|| { + vec![Signal::builder("max-number-reached") + .param_types([i32::static_type()]) + .build()] + }); + SIGNALS.as_ref() + } + + fn constructed(&self) { + self.parent_constructed(); + } +} + +impl BoxImpl for Breadcrumb {} + +impl WidgetImpl for Breadcrumb {} + +impl WindowImpl for Breadcrumb {} + +impl ApplicationWindowImpl for Breadcrumb {} diff --git a/src/components/breadcrumb/breadcrumbItem.rs b/src/components/breadcrumb/breadcrumbItem.rs new file mode 100644 index 0000000..a45a2f5 --- /dev/null +++ b/src/components/breadcrumb/breadcrumbItem.rs @@ -0,0 +1,21 @@ +use crate::components::breadcrumb::breadcrumbItemImpl; + +use adw::glib; +use adw::glib::Object; +use glib::subclass::prelude::ObjectSubclassIsExt; +use gtk::prelude::ButtonExt; + +glib::wrapper! { + pub struct BreadcrumbItem(ObjectSubclass) + @extends gtk::Box, gtk::Widget, + @implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget; +} + +impl BreadcrumbItem { + pub fn new(name : &str) -> Self { + let entry: BreadcrumbItem = Object::builder().build(); + let entryImp = entry.imp(); + entryImp.resetBreadcrumbButtonName.set_label(name); + entry + } +} diff --git a/src/components/breadcrumb/breadcrumbItemImpl.rs b/src/components/breadcrumb/breadcrumbItemImpl.rs new file mode 100644 index 0000000..734ae15 --- /dev/null +++ b/src/components/breadcrumb/breadcrumbItemImpl.rs @@ -0,0 +1,40 @@ +use gtk::subclass::prelude::*; +use gtk::{glib, CompositeTemplate, Button}; +use crate::components::breadcrumb::breadcrumbItem; + +#[allow(non_snake_case)] +#[derive(Default, CompositeTemplate)] +#[template(resource = "/org/Xetibo/ReSet/resetBreadcrumbItem.ui")] +pub struct BreadcrumbItem { + #[template_child] + pub resetBreadcrumbButtonName: TemplateChild