test css
This commit is contained in:
parent
5217d0dd64
commit
4041190f57
@ -43,13 +43,12 @@ impl AsyncComponent for MonitorModel {
|
||||
#[wrap(Some)]
|
||||
#[name="test"]
|
||||
set_child = &DynamicCol{
|
||||
set_ratio: 0.5,
|
||||
set_end_width: 300,
|
||||
set_hexpand: true,
|
||||
set_vexpand: true,
|
||||
#[wrap(Some)]
|
||||
#[name="paned"]
|
||||
set_child=>k::Paned{
|
||||
set_position: top_level_window_unwrap.default_width() - model.sidebar_width,
|
||||
set_child_paned=>k::Paned{
|
||||
#[wrap(Some)]
|
||||
#[name="render"]
|
||||
set_start_child=>k::Frame{
|
||||
@ -88,14 +87,7 @@ 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 }
|
||||
}
|
||||
|
||||
|
||||
@ -52,8 +52,11 @@ impl SimpleComponent for SideBarModel {
|
||||
set_start_child = >k::Box{
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_spacing: 5,
|
||||
#[local]
|
||||
top_panel -> gtk::Notebook{},
|
||||
gtk::Frame{
|
||||
add_css_class: "rb",
|
||||
#[local]
|
||||
top_panel -> gtk::Notebook{}
|
||||
},
|
||||
gtk::Button {
|
||||
set_label: "Add Layers",
|
||||
connect_clicked[sender] => move |_| {
|
||||
@ -124,7 +127,7 @@ impl SimpleComponent for SideBarModel {
|
||||
};
|
||||
|
||||
let my_view = &model.list_view_wrapper.view;
|
||||
let top_panel = gtk::Notebook::builder().vexpand(true).build();
|
||||
let top_panel = gtk::Notebook::builder().vexpand(true).hexpand(true).build();
|
||||
top_panel.append_page(&Chart::new(), Some(>k::Label::new(Some("Chart"))));
|
||||
|
||||
let bottom_panel = gtk::Notebook::builder().vexpand(true).build();
|
||||
|
||||
@ -1,23 +1,26 @@
|
||||
use adw::subclass::bin::BinImpl;
|
||||
use gtk::glib;
|
||||
use gtk::glib::prelude::*;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
pub struct DynamicCol {
|
||||
pub(super) child: RefCell<Option<gtk::Paned>>,
|
||||
pub(super) ratio: RefCell<Option<f64>>,
|
||||
width: Cell<i32>,
|
||||
pub(super) start_width: Cell<i32>,
|
||||
pub(super) end_width: Cell<i32>,
|
||||
pub(super) start_width: Cell<Option<i32>>,
|
||||
pub(super) end_width: Cell<Option<i32>>,
|
||||
}
|
||||
|
||||
impl Default for DynamicCol {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
child: RefCell::new(None),
|
||||
ratio: RefCell::new(None),
|
||||
width: Cell::new(0),
|
||||
start_width: Cell::new(0),
|
||||
end_width: Cell::new(0),
|
||||
start_width: Cell::new(None),
|
||||
end_width: Cell::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,13 +29,48 @@ impl Default for DynamicCol {
|
||||
impl ObjectSubclass for DynamicCol {
|
||||
const NAME: &'static str = "DynamicCol";
|
||||
type Type = super::DynamicCol;
|
||||
type ParentType = gtk::Box;
|
||||
type ParentType = gtk::Widget;
|
||||
}
|
||||
|
||||
impl ObjectImpl for DynamicCol {}
|
||||
impl ObjectImpl for DynamicCol {
|
||||
fn dispose(&self) {
|
||||
if let Some(child) = self.child.borrow_mut().take() {
|
||||
child.unparent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for DynamicCol {}
|
||||
impl WidgetImpl for DynamicCol {
|
||||
fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) {
|
||||
let widget = self.obj();
|
||||
let child = self.child.borrow();
|
||||
let child = match child.as_ref() {
|
||||
Some(child) => child,
|
||||
None => return (0, 0, -1, -1),
|
||||
};
|
||||
|
||||
impl BoxImpl for DynamicCol {}
|
||||
child.measure(orientation, for_size)
|
||||
}
|
||||
|
||||
impl WidgetImplExt for DynamicCol{}
|
||||
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
|
||||
let widget = self.obj();
|
||||
let child = self.child.borrow();
|
||||
|
||||
let child = match child.as_ref() {
|
||||
Some(child) => child,
|
||||
None => return,
|
||||
};
|
||||
child.size_allocate(>k::Allocation::new(0, 0, width, height), baseline);
|
||||
|
||||
let ratio = self.ratio.borrow();
|
||||
|
||||
let position = if let Some(ratio) = *ratio {
|
||||
(width as f64 * ratio) as i32
|
||||
} else {
|
||||
self.start_width.get().or(Some(width - self.end_width.get().unwrap())).unwrap()
|
||||
};
|
||||
|
||||
child.set_position(position);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
mod imp;
|
||||
mod custom_layout;
|
||||
use glib::clone;
|
||||
pub use glib::subclass::prelude::*;
|
||||
use gtk::traits::WidgetExt;
|
||||
mod imp;
|
||||
use gtk::{glib, prelude::*, subclass::prelude::*};
|
||||
use std::cell::{Ref, RefCell, RefMut};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct DynamicCol(ObjectSubclass<imp::DynamicCol>)
|
||||
@extends gtk::Box, gtk::Widget;
|
||||
@extends gtk::Widget;
|
||||
}
|
||||
|
||||
impl Default for DynamicCol {
|
||||
@ -24,29 +22,69 @@ impl DynamicCol {
|
||||
}
|
||||
|
||||
pub fn set_ratio(&self, ratio: f64) {
|
||||
let self_ = imp::DynamicCol::from_instance(self);
|
||||
let self_ = self.imp();
|
||||
self_.ratio.replace(Some(ratio));
|
||||
self.queue_resize();
|
||||
}
|
||||
|
||||
pub fn set_start_width(&self, ratio: i32) {
|
||||
let self_ = self.imp();
|
||||
self_.start_width.replace(Some(ratio));
|
||||
self.queue_resize();
|
||||
}
|
||||
|
||||
pub fn set_end_width(&self, ratio: i32) {
|
||||
let self_ = self.imp();
|
||||
self_.end_width.replace(Some(ratio));
|
||||
self.queue_resize();
|
||||
}
|
||||
|
||||
pub fn get_ratio(&self) -> Option<f64> {
|
||||
let self_ = imp::DynamicCol::from_instance(self);
|
||||
let self_ = self.imp();
|
||||
*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) {
|
||||
pub fn set_child_paned(&self, widget: Option<>k::Paned>) {
|
||||
let imp = self.imp();
|
||||
let widget = widget.map(|w| w.upcast_ref());
|
||||
|
||||
let manager = imp.layout_manager();
|
||||
if widget == imp.child.borrow().as_ref() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(child) = imp.child.borrow_mut().take() {
|
||||
child.unparent();
|
||||
}
|
||||
|
||||
if let Some(w) = widget {
|
||||
imp.child.replace(Some(w.clone()));
|
||||
w.set_parent(self);
|
||||
}
|
||||
|
||||
self.queue_resize();
|
||||
self.notify("child")
|
||||
}
|
||||
|
||||
// pub fn set_child(&self, widget: Option<&impl IsA<gtk::Widget>>) {
|
||||
|
||||
// let imp = self.imp();
|
||||
// let widget = widget.map(|w| w.upcast_ref());
|
||||
|
||||
// if widget == imp.child.borrow().as_ref() {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if let Some(child) = imp.child.borrow_mut().take() {
|
||||
// child.unparent();
|
||||
// }
|
||||
|
||||
// if let Some(w) = widget {
|
||||
// imp.child.replace(Some(w.clone()));
|
||||
// w.set_parent(self);
|
||||
// }
|
||||
|
||||
// self.queue_resize();
|
||||
// self.notify("child")
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -28,8 +28,10 @@ fn main() {
|
||||
{
|
||||
#[cfg(target_os = "macos")]
|
||||
let library =
|
||||
unsafe { libloading::os::unix::Library::new("/opt/homebrew/lib/libepoxy.0.dylib") }
|
||||
.unwrap();
|
||||
unsafe { libloading::os::unix::Library::new("/opt/homebrew/lib/libepoxy.0.dylib") }.or(unsafe{
|
||||
libloading::os::unix::Library::new("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)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user