From 5217d0dd64153a0279f9427b4ea3e67655aa8af6 Mon Sep 17 00:00:00 2001 From: Tsuki Date: Wed, 17 Jan 2024 20:52:40 +0800 Subject: [PATCH] layout manager test --- .../render_panel/monitor/monitor.rs | 46 +++++++++++----- src/dynamic_col/custom_layout/imp.rs | 0 src/dynamic_col/custom_layout/mod.rs | 1 + src/dynamic_col/imp.rs | 38 ++++++++++++++ src/dynamic_col/mod.rs | 52 +++++++++++++++++++ src/main.rs | 7 ++- 6 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 src/dynamic_col/custom_layout/imp.rs create mode 100644 src/dynamic_col/custom_layout/mod.rs create mode 100644 src/dynamic_col/imp.rs create mode 100644 src/dynamic_col/mod.rs diff --git a/src/components/render_panel/monitor/monitor.rs b/src/components/render_panel/monitor/monitor.rs index 9d270fa..673f753 100644 --- a/src/components/render_panel/monitor/monitor.rs +++ b/src/components/render_panel/monitor/monitor.rs @@ -1,8 +1,10 @@ use crate::{ components::render_panel::messages::{MonitorInputMsg, MonitorOutputMsg}, data::Npz, + dynamic_col::DynamicCol, render::{predefined::color_mapper::BoundaryNorm, Layer, Render}, }; +use glib::clone; use std::sync::Arc; use super::sidebar::{sidebar::SideBarModel, Msg, SideBarOutputMsg}; @@ -39,22 +41,31 @@ impl AsyncComponent for MonitorModel { set_height_request: 500, set_width_request: 700, #[wrap(Some)] - set_child=>k::Paned{ - set_position: 1000, + #[name="test"] + set_child = &DynamicCol{ + set_ratio: 0.5, + set_hexpand: true, + set_vexpand: true, #[wrap(Some)] - #[name="render"] - set_start_child=>k::Box{ - add_css_class: "rb", - set_margin_all: 5, - Render{ + #[name="paned"] + set_child=>k::Paned{ + set_position: top_level_window_unwrap.default_width() - model.sidebar_width, + #[wrap(Some)] + #[name="render"] + set_start_child=>k::Frame{ add_css_class: "rb", - #[watch] - set_interior_layers: model.layers.clone(), - } - }, - #[wrap(Some)] - set_end_child=model.sidebar.widget(), - } + set_margin_all: 5, + Render{ + add_css_class: "rb", + #[watch] + set_interior_layers: model.layers.clone(), + } + }, + #[wrap(Some)] + set_end_child=model.sidebar.widget(), + } + }, + } } @@ -77,7 +88,14 @@ impl AsyncComponent for MonitorModel { sidebar, }; + let top_level_window = root.toplevel_window(); + let top_level_window_unwrap = top_level_window.unwrap(); + let widgets = view_output! {}; + top_level_window_unwrap.connect_width_request_notify(|w| { + println!("window width: {}", w.width_request()); + }); + println!("window width: {}", widgets.test.get_start_width()); AsyncComponentParts { model, widgets } } diff --git a/src/dynamic_col/custom_layout/imp.rs b/src/dynamic_col/custom_layout/imp.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/dynamic_col/custom_layout/mod.rs b/src/dynamic_col/custom_layout/mod.rs new file mode 100644 index 0000000..9194b24 --- /dev/null +++ b/src/dynamic_col/custom_layout/mod.rs @@ -0,0 +1 @@ +mod imp; diff --git a/src/dynamic_col/imp.rs b/src/dynamic_col/imp.rs new file mode 100644 index 0000000..b450b0c --- /dev/null +++ b/src/dynamic_col/imp.rs @@ -0,0 +1,38 @@ +use adw::subclass::bin::BinImpl; +use gtk::glib; +use gtk::subclass::prelude::*; +use std::cell::{Cell, RefCell}; +use std::num::NonZeroU32; + +pub struct DynamicCol { + pub(super) ratio: RefCell>, + width: Cell, + pub(super) start_width: Cell, + pub(super) end_width: Cell, +} + +impl Default for DynamicCol { + fn default() -> Self { + Self { + ratio: RefCell::new(None), + width: Cell::new(0), + start_width: Cell::new(0), + end_width: Cell::new(0), + } + } +} + +#[glib::object_subclass] +impl ObjectSubclass for DynamicCol { + const NAME: &'static str = "DynamicCol"; + type Type = super::DynamicCol; + type ParentType = gtk::Box; +} + +impl ObjectImpl for DynamicCol {} + +impl WidgetImpl for DynamicCol {} + +impl BoxImpl for DynamicCol {} + +impl WidgetImplExt for DynamicCol{} diff --git a/src/dynamic_col/mod.rs b/src/dynamic_col/mod.rs new file mode 100644 index 0000000..b6ba7ba --- /dev/null +++ b/src/dynamic_col/mod.rs @@ -0,0 +1,52 @@ +mod imp; +mod custom_layout; +use glib::clone; +pub use glib::subclass::prelude::*; +use gtk::traits::WidgetExt; +use std::cell::{Ref, RefCell, RefMut}; +use std::sync::{Arc, Mutex}; + +glib::wrapper! { + pub struct DynamicCol(ObjectSubclass) + @extends gtk::Box, gtk::Widget; +} + +impl Default for DynamicCol { + fn default() -> Self { + Self::new() + } +} + +impl DynamicCol { + pub fn new() -> Self { + let this: Self = glib::Object::new(); + this + } + + pub fn set_ratio(&self, ratio: f64) { + let self_ = imp::DynamicCol::from_instance(self); + self_.ratio.replace(Some(ratio)); + self.queue_resize(); + } + + pub fn get_ratio(&self) -> Option { + let self_ = imp::DynamicCol::from_instance(self); + *self_.ratio.borrow() + } + + pub fn get_start_width(&self) -> i32 { + let self_ = imp::DynamicCol::from_instance(self); + self_.start_width.get() + } + + pub fn get_end_width(&self) -> i32 { + let self_ = imp::DynamicCol::from_instance(self); + self_.end_width.get() + } + + fn test(&self) { + let imp = self.imp(); + + let manager = imp.layout_manager(); + } +} diff --git a/src/main.rs b/src/main.rs index b4a0018..952038d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,13 +3,14 @@ use gtk::prelude::*; use gtk::{gio, glib, Application, ApplicationWindow}; use relm4::menu; use relm4::RelmApp; -use tokio::runtime::Runtime; use std::ptr; +use tokio::runtime::Runtime; mod chart; mod components; mod coords; mod data; mod dealers; +mod dynamic_col; mod errors; mod pipeline; mod render; @@ -26,7 +27,9 @@ fn main() { // Load GL pointers from epoxy (GL context management library used by GTK). { #[cfg(target_os = "macos")] - let library = unsafe { libloading::os::unix::Library::new("libepoxy.0.dylib") }.unwrap(); + let library = + unsafe { libloading::os::unix::Library::new("/opt/homebrew/lib/libepoxy.0.dylib") } + .unwrap(); #[cfg(all(unix, not(target_os = "macos")))] let library = unsafe { libloading::os::unix::Library::new("libepoxy.so.0") }.unwrap(); #[cfg(windows)]