feat: Add dynamic window expansion

This commit is contained in:
Fabio Lenherr / DashieTM 2023-12-06 11:47:47 +01:00
parent e03dad964b
commit 4836f1d8c2
10 changed files with 61 additions and 49 deletions

View file

@ -13,7 +13,7 @@ use crate::components::wifi::wifi_box::{
scan_for_wifi, show_stored_connections, start_event_listener, WifiBox,
};
use gtk::prelude::WidgetExt;
use gtk::{FlowBox, Frame};
use gtk::{Align, FlowBox, FlowBoxChild, Frame};
pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
|listeners: Arc<Listeners>, reset_main: FlowBox| {
@ -22,11 +22,11 @@ pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
start_event_listener(listeners.clone(), wifi_box.clone());
show_stored_connections(wifi_box.clone());
scan_for_wifi(wifi_box.clone());
let wifi_frame = wrap_in_frame(SettingBox::new(&*wifi_box));
let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
let bluetooth_box = BluetoothBox::new(listeners.clone());
populate_conntected_bluetooth_devices(bluetooth_box.clone());
start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
let bluetooth_frame = wrap_in_frame(SettingBox::new(&*bluetooth_box));
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
reset_main.remove_all();
reset_main.insert(&wifi_frame, -1);
reset_main.insert(&bluetooth_frame, -1);
@ -41,7 +41,7 @@ pub const HANDLE_WIFI_CLICK: fn(Arc<Listeners>, FlowBox) =
start_event_listener(listeners.clone(), wifi_box.clone());
show_stored_connections(wifi_box.clone());
scan_for_wifi(wifi_box.clone());
let wifi_frame = wrap_in_frame(SettingBox::new(&*wifi_box));
let wifi_frame = wrap_in_flow_box_child(SettingBox::new(&*wifi_box));
reset_main.remove_all();
reset_main.insert(&wifi_frame, -1);
reset_main.set_max_children_per_line(1);
@ -54,7 +54,7 @@ pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox) =
let bluetooth_box = BluetoothBox::new(listeners.clone());
start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
populate_conntected_bluetooth_devices(bluetooth_box.clone());
let bluetooth_frame = wrap_in_frame(SettingBox::new(&*bluetooth_box));
let bluetooth_frame = wrap_in_flow_box_child(SettingBox::new(&*bluetooth_box));
reset_main.remove_all();
reset_main.insert(&bluetooth_frame, -1);
reset_main.set_max_children_per_line(1);
@ -72,9 +72,9 @@ pub const HANDLE_AUDIO_CLICK: fn(Arc<Listeners>, FlowBox) =
Some(audio_input.clone()),
);
populate_sinks(audio_output.clone());
let audio_frame = wrap_in_frame(SettingBox::new(&*audio_output));
let audio_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_output));
populate_sources(audio_input.clone());
let source_frame = wrap_in_frame(SettingBox::new(&*audio_input));
let source_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_input));
reset_main.remove_all();
reset_main.insert(&audio_frame, -1);
reset_main.insert(&source_frame, -1);
@ -91,7 +91,7 @@ pub const HANDLE_VOLUME_CLICK: fn(Arc<Listeners>, FlowBox) =
std::hint::spin_loop()
}
populate_sinks(audio_output.clone());
let audio_frame = wrap_in_frame(SettingBox::new(&*audio_output));
let audio_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_output));
reset_main.remove_all();
reset_main.insert(&audio_frame, -1);
reset_main.set_max_children_per_line(1);
@ -104,7 +104,7 @@ pub const HANDLE_MICROPHONE_CLICK: fn(Arc<Listeners>, FlowBox) =
let audio_input = Arc::new(SourceBox::new());
start_audio_listener(listeners.clone(), None, Some(audio_input.clone()));
populate_sources(audio_input.clone());
let source_frame = wrap_in_frame(SettingBox::new(&*audio_input));
let source_frame = wrap_in_flow_box_child(SettingBox::new(&*audio_input));
reset_main.remove_all();
reset_main.insert(&source_frame, -1);
reset_main.set_max_children_per_line(1);
@ -118,11 +118,15 @@ pub const HANDLE_HOME: fn(Arc<Listeners>, FlowBox) =
reset_main.remove_all();
};
fn wrap_in_frame(widget: SettingBox) -> Frame {
fn wrap_in_flow_box_child(widget: SettingBox) -> FlowBoxChild {
let frame = Frame::new(None);
frame.set_child(Some(&widget));
frame.add_css_class("resetSettingFrame");
frame
FlowBoxChild::builder()
.child(&frame)
.halign(Align::Fill)
.valign(Align::Start)
.build()
}
// for future implementations

View file

@ -1,7 +1,7 @@
use adw::glib::clone;
use adw::subclass::prelude::ObjectSubclassIsExt;
use adw::BreakpointCondition;
use glib::Object;
use adw::{ApplicationWindow, BreakpointCondition};
use glib::{closure_local, Object};
use gtk::prelude::*;
use gtk::{gio, glib, Application, ListBoxRow, Orientation};
@ -12,7 +12,7 @@ use crate::components::window::sidebar_entry_impl::Categories;
glib::wrapper! {
pub struct ReSetWindow(ObjectSubclass<reset_window_impl::ReSetWindow>)
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
@extends adw::ApplicationWindow, gtk::Window, gtk::Widget,
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
}
@ -54,18 +54,13 @@ impl ReSetWindow {
.connect_clicked(clone!(@ weak self as window => move |_| {
window.close();
}));
// selfImp.resetMenu.connect_clicked(|_| {
// WifiBox::donotdisturb();
//
// });
}
pub fn handle_dynamic_sidebar(&self) {
let self_imp = self.imp();
self_imp
.reset_sidebar_breakpoint
.set_condition(BreakpointCondition::parse("max-width: 700sp").as_ref().ok());
.set_condition(BreakpointCondition::parse("max-width: 950sp").as_ref().ok());
self_imp.reset_sidebar_breakpoint.add_setter(
&Object::from(self_imp.reset_overlay_split_view.get()),
"collapsed",
@ -143,6 +138,7 @@ impl ReSetWindow {
true,
HANDLE_BLUETOOTH_CLICK,
),
// uncommented when VPN is implemented
// SidebarEntry::new(
// "VPN",
// "network-vpn-symbolic",
@ -191,6 +187,7 @@ impl ReSetWindow {
audio_list,
));
// uncommented when implemented
// let peripheralsList = vec![
// SidebarEntry::new(
// "Displays",

View file

@ -5,6 +5,7 @@ use adw::glib::StaticTypeExt;
use adw::subclass::prelude::AdwApplicationWindowImpl;
use adw::{Breakpoint, OverlaySplitView};
use glib::subclass::InitializingObject;
use gtk::prelude::WidgetExt;
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, FlowBox, ListBox, PopoverMenu, SearchEntry};
@ -74,7 +75,24 @@ impl ObjectImpl for ReSetWindow {
}
}
impl WidgetImpl for ReSetWindow {}
impl WidgetImpl for ReSetWindow {
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
// felixusan, use "the force" for debugging
// aka this variable
// println!("{width}");
self.parent_size_allocate(width, height, baseline);
if width > 738 {
self.reset_main.set_margin_start(100);
self.reset_main.set_margin_end(100);
} else if width > 600 {
self.reset_main.set_margin_start((width - 600)/2);
self.reset_main.set_margin_end((width - 600)/2);
} else {
self.reset_main.set_margin_start(0);
self.reset_main.set_margin_end(0);
}
}
}
impl WindowImpl for ReSetWindow {}