Add templates for box and listboxrow

kekw
This commit is contained in:
takotori 2023-11-07 15:08:22 +01:00
parent 7e15201c85
commit af7776d62a
24 changed files with 333 additions and 205 deletions

View file

@ -5,6 +5,7 @@ use adw::subclass::prelude::ObjectSubclassIsExt;
use crate::components::bluetooth::bluetoothBoxImpl;
use crate::components::bluetooth::bluetoothEntry::BluetoothEntry;
use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes;
use crate::components::temp::listEntry::ListEntry;
glib::wrapper! {
pub struct BluetoothBox(ObjectSubclass<bluetoothBoxImpl::BluetoothBox>)
@ -12,7 +13,6 @@ glib::wrapper! {
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
}
impl BluetoothBox {
pub fn new() -> Self {
Object::builder().build()
@ -21,10 +21,10 @@ impl BluetoothBox {
pub fn scanForDevices(&self) {
let selfImp = self.imp();
let mut wifiEntries = selfImp.availableDevices.borrow_mut();
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Mouse, "ina mouse"));
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Keyboard, "inaboard"));
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Controller, "ina controller"));
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Controller, "ina best waifu"));
wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Mouse, "ina mouse")));
wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Keyboard, "inaboard")));
wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Controller, "ina controller")));
wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Controller, "ina best waifu")));
for wifiEntry in wifiEntries.iter() {
selfImp.resetBluetoothAvailableDevices.append(wifiEntry);
@ -34,8 +34,8 @@ impl BluetoothBox {
pub fn addConnectedDevices(&self) {
let selfImp = self.imp();
let mut wifiEntries = selfImp.connectedDevices.borrow_mut();
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Mouse, "why are we still here?"));
wifiEntries.push(BluetoothEntry::new(DeviceTypes::Keyboard, "just to suffer?"));
wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Mouse, "why are we still here?")));
wifiEntries.push(ListEntry::new(&BluetoothEntry::new(DeviceTypes::Keyboard, "just to suffer?")));
for wifiEntry in wifiEntries.iter() {
selfImp.resetBluetoothConnectedDevices.append(wifiEntry);

View file

@ -5,6 +5,7 @@ use gtk::subclass::prelude::*;
use crate::components::bluetooth::bluetoothBox;
use crate::components::bluetooth::bluetoothEntry::BluetoothEntry;
use crate::components::temp::listEntry::ListEntry;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
@ -16,8 +17,8 @@ pub struct BluetoothBox {
pub resetBluetoothAvailableDevices: TemplateChild<ListBox>,
#[template_child]
pub resetBluetoothConnectedDevices: TemplateChild<ListBox>,
pub availableDevices: RefCell<Vec<BluetoothEntry>>,
pub connectedDevices: RefCell<Vec<BluetoothEntry>>,
pub availableDevices: RefCell<Vec<ListEntry>>,
pub connectedDevices: RefCell<Vec<ListEntry>>,
}
#[glib::object_subclass]
@ -28,6 +29,7 @@ impl ObjectSubclass for BluetoothBox {
fn class_init(klass: &mut Self::Class) {
BluetoothEntry::ensure_type();
ListEntry::ensure_type();
klass.bind_template();
}

View file

@ -6,7 +6,7 @@ use crate::components::bluetooth::bluetoothEntryImpl::DeviceTypes;
glib::wrapper! {
pub struct BluetoothEntry(ObjectSubclass<bluetoothEntryImpl::BluetoothEntry>)
@extends gtk::Widget,
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
}

View file

@ -29,7 +29,7 @@ pub struct BluetoothEntry {
impl ObjectSubclass for BluetoothEntry {
const NAME: &'static str = "resetBluetoothEntry";
type Type = bluetoothEntry::BluetoothEntry;
type ParentType = gtk::ListBoxRow;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
@ -46,7 +46,7 @@ impl ObjectImpl for BluetoothEntry {
}
}
impl ListBoxRowImpl for BluetoothEntry {}
impl BoxImpl for BluetoothEntry {}
impl WidgetImpl for BluetoothEntry {}

View file

@ -1,4 +1,5 @@
pub mod window;
pub mod wifi;
pub mod bluetooth;
pub mod audio;
pub mod audio;
mod temp;

View file

@ -0,0 +1,19 @@
use crate::components::temp::listEntryImpl;
use adw::glib;
use adw::glib::{IsA, Object};
use gtk::prelude::ListBoxRowExt;
use gtk::Widget;
glib::wrapper! {
pub struct ListEntry(ObjectSubclass<listEntryImpl::ListEntry>)
@extends gtk::ListBoxRow, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Actionable;
}
impl ListEntry {
pub fn new(child: &impl IsA<Widget>) -> Self {
let entry: ListEntry = Object::builder().build();
entry.set_child(Some(child));
entry
}
}

View file

@ -0,0 +1,38 @@
use gtk::{CompositeTemplate, glib};
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use crate::components::temp::listEntry;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetListBoxRow.ui")]
pub struct ListEntry {}
#[glib::object_subclass]
impl ObjectSubclass for ListEntry {
const NAME: &'static str = "resetListBoxRow";
type Type = listEntry::ListEntry;
type ParentType = gtk::ListBoxRow;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for ListEntry {
fn constructed(&self) {
self.parent_constructed();
}
}
impl ListBoxRowImpl for ListEntry {}
impl WidgetImpl for ListEntry {}
impl WindowImpl for ListEntry {}
impl ApplicationWindowImpl for ListEntry {}

View file

@ -0,0 +1,4 @@
pub mod settingBox;
pub mod settingBoxImpl;
pub mod listEntry;
pub mod listEntryImpl;

View file

@ -0,0 +1,19 @@
use crate::components::temp::settingBoxImpl;
use adw::glib;
use adw::glib::{IsA, Object};
use gtk::prelude::BoxExt;
use gtk::Widget;
glib::wrapper! {
pub struct SettingBox(ObjectSubclass<settingBoxImpl::SettingBox>)
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
}
impl SettingBox {
pub fn new(child: &impl IsA<Widget>) -> Self {
let entry: SettingBox = Object::builder().build();
entry.append(child);
entry
}
}

View file

@ -0,0 +1,39 @@
use adw::NavigationView;
use gtk::{CompositeTemplate, glib};
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use crate::components::temp::settingBox;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
#[template(resource = "/org/Xetibo/ReSet/resetSetting.ui")]
pub struct SettingBox {}
#[glib::object_subclass]
impl ObjectSubclass for SettingBox {
const NAME: &'static str = "resetSetting";
type Type = settingBox::SettingBox;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for SettingBox {
fn constructed(&self) {
self.parent_constructed();
}
}
impl BoxImpl for SettingBox {}
impl WidgetImpl for SettingBox {}
impl WindowImpl for SettingBox {}
impl ApplicationWindowImpl for SettingBox {}

View file

@ -2,12 +2,13 @@ use std::thread;
use std::time::Duration;
use adw::glib;
use adw::glib::clone;
use adw::glib::Object;
use adw::subclass::prelude::ObjectSubclassIsExt;
use dbus::blocking::Connection;
use dbus::Error;
use gtk::prelude::ButtonExt;
use gtk::glib::Variant;
use gtk::prelude::ActionableExt;
use crate::components::temp::listEntry::ListEntry;
use crate::components::wifi::wifiBoxImpl;
use crate::components::wifi::wifiEntry::WifiEntry;
@ -27,18 +28,17 @@ impl WifiBox {
pub fn setupCallbacks(&self) {
let selfImp = self.imp();
selfImp.resetWifiDetails.connect_row_activated(clone!(@ weak selfImp as window => move |_, _y| {
// let result = y.downcast_ref()::<WifiEntry>().unwrap(); no worky smh
}));
selfImp.resetSavedNetworks.set_action_name(Some("navigation.push"));
selfImp.resetSavedNetworks.set_action_target_value(Some(&Variant::from("saved")));
}
pub fn scanForWifi(&self) {
let selfImp = self.imp();
let mut wifiEntries = selfImp.wifiEntries.borrow_mut();
wifiEntries.push(WifiEntry::new(WifiStrength::Excellent, "ina internet", true));
wifiEntries.push(WifiEntry::new(WifiStrength::Excellent, "watch ina", true));
wifiEntries.push(WifiEntry::new(WifiStrength::Ok, "INANET", true));
wifiEntries.push(WifiEntry::new(WifiStrength::Weak, "ina best waifu", false));
wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Excellent, "ina internet", true)));
wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Excellent, "watch ina", true)));
wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Ok, "INANET", true)));
wifiEntries.push(ListEntry::new(&WifiEntry::new(WifiStrength::Weak, "ina best waifu", false)));
for wifiEntry in wifiEntries.iter() {
selfImp.resetWifiList.append(wifiEntry);

View file

@ -1,10 +1,11 @@
use std::cell::RefCell;
use gtk::{Button, CompositeTemplate, glib, ListBox, ListBoxRow, Revealer, Switch};
use gtk::{Button, CompositeTemplate, glib, ListBox, Switch};
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use crate::components::wifi::wifiBox;
use crate::components::wifi::wifiEntry::WifiEntry;
use crate::components::temp::listEntry::ListEntry;
#[allow(non_snake_case)]
#[derive(Default, CompositeTemplate)]
@ -13,14 +14,16 @@ pub struct WifiBox {
#[template_child]
pub resetWifiDetails: TemplateChild<ListBox>,
#[template_child]
pub resetWifiSwitchRow: TemplateChild<ListBoxRow>,
pub resetWifiSwitchRow: TemplateChild<ListEntry>,
#[template_child]
pub resetSavedNetworks: TemplateChild<ListEntry>,
#[template_child]
pub resetWifiSwitch: TemplateChild<Switch>,
#[template_child]
pub resetWifiList: TemplateChild<ListBox>,
#[template_child]
pub resetWifiAdvanced: TemplateChild<Button>,
pub wifiEntries: RefCell<Vec<WifiEntry>>,
pub wifiEntries: RefCell<Vec<ListEntry>>,
}
#[glib::object_subclass]
@ -31,6 +34,7 @@ impl ObjectSubclass for WifiBox {
fn class_init(klass: &mut Self::Class) {
WifiEntry::ensure_type();
ListEntry::ensure_type();
klass.bind_template();
}

View file

@ -7,7 +7,7 @@ use crate::components::wifi::wifiEntryImpl::WifiStrength;
glib::wrapper! {
pub struct WifiEntry(ObjectSubclass<wifiEntryImpl::WifiEntry>)
@extends gtk::ListBoxRow, gtk::Widget,
@extends gtk::Box, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::Actionable, gtk::ConstraintTarget;
}

View file

@ -1,6 +1,7 @@
use std::cell::RefCell;
use gtk::{Button, CompositeTemplate, glib, Image, Label};
use gtk::subclass::prelude::*;
use crate::components::temp::listEntry::ListEntry;
use crate::components::wifi::wifiEntry;
#[derive(Default, Copy, Clone)]
@ -32,7 +33,7 @@ pub struct WifiEntry {
impl ObjectSubclass for WifiEntry {
const NAME: &'static str = "resetWifiEntry";
type Type = wifiEntry::WifiEntry;
type ParentType = gtk::ListBoxRow;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
@ -49,7 +50,7 @@ impl ObjectImpl for WifiEntry {
}
}
impl ListBoxRowImpl for WifiEntry {}
impl BoxImpl for WifiEntry {}
impl WidgetImpl for WifiEntry {}

View file

@ -1,30 +1,32 @@
use gtk::{FlowBox, FlowBoxChild, Label};
use gtk::prelude::FlowBoxChildExt;
use gtk::{FlowBox, Label};
use gtk::prelude::WidgetExt;
use crate::components::audio::audioBox::AudioBox;
use crate::components::bluetooth::bluetoothBox::BluetoothBox;
use crate::components::temp::settingBox::SettingBox;
use crate::components::wifi::wifiBox::WifiBox;
pub const HANDLE_CONNECTIVITY_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let wifiBox = WifiBox::new();
let bluetoothBox = BluetoothBox::new();
let wifiBox = SettingBox::new(&WifiBox::new());
let bluetoothBox = SettingBox::new(&BluetoothBox::new());
wifiBox.set_width_request(500); // todo why not working from ui file
bluetoothBox.set_width_request(500); // todo why not working from ui file
resetMain.remove_all();
resetMain.insert(&wifiBox, -1);
resetMain.insert(&bluetoothBox, -1);
// todo center flowbox children
resetMain.set_max_children_per_line(2);
};
pub const HANDLE_WIFI_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let wifibox = WifiBox::new();
let wifiBox = SettingBox::new(&WifiBox::new());
wifiBox.set_width_request(500); // todo why not working from ui file
resetMain.remove_all();
let child = FlowBoxChild::new();
child.set_child(Some(&wifibox));
resetMain.insert(&child, -1);
resetMain.insert(&wifiBox, -1);
resetMain.set_max_children_per_line(1);
};
pub const HANDLE_BLUETOOTH_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
let bluetoothBox = BluetoothBox::new();
let bluetoothBox = SettingBox::new(&BluetoothBox::new());
bluetoothBox.set_width_request(500); // todo why not working from ui file
resetMain.remove_all();
resetMain.insert(&bluetoothBox, -1);
resetMain.set_max_children_per_line(1);

View file

@ -54,7 +54,7 @@ impl Window {
pub fn handleDynamicSidebar(&self) {
let selfImp = self.imp();
selfImp.resetSidebarBreakpoint.set_condition(BreakpointCondition::parse("max-width: 600sp").as_ref().ok());
selfImp.resetSidebarBreakpoint.set_condition(BreakpointCondition::parse("max-width: 700sp").as_ref().ok());
selfImp.resetSidebarBreakpoint.add_setter(
&Object::from(selfImp.resetOverlaySplitView.get()),
"collapsed",