From 7b2a110c126078b35eae3ae60308d9af5cbadfee Mon Sep 17 00:00:00 2001 From: mars Date: Tue, 15 Nov 2022 17:02:15 -0700 Subject: [PATCH] Resizeable sandbox panels --- apps/sandbox/src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/sandbox/src/main.rs b/apps/sandbox/src/main.rs index dbdd016..a51d56a 100644 --- a/apps/sandbox/src/main.rs +++ b/apps/sandbox/src/main.rs @@ -70,6 +70,7 @@ impl eframe::App for App { index, msg_buf: String::new(), show_msg: false, + current_size: Default::default(), }; self.panels.push(panel); @@ -91,6 +92,7 @@ pub struct PanelWindow { pub index: usize, pub msg_buf: String, pub show_msg: bool, + pub current_size: egui::Vec2, } impl PanelWindow { @@ -101,14 +103,24 @@ impl PanelWindow { ui.checkbox(&mut self.show_msg, "Show Message Editor"); }); - let size = egui::vec2(800.0, 800.0); let sense = egui::Sense { click: true, drag: true, focusable: true, }; - let (rect, response) = ui.allocate_at_least(size, sense); + let desired_size = ui.available_size(); + let response = ui.allocate_response(desired_size, sense); + let rect = response.rect; + + if rect.size() != self.current_size { + let size = rect.size(); + self.current_size = size; + + let size = canary::Vec2::new(size.x, size.y); + println!("resizing: {:?}", size); + self.panel.on_resize(size / PX_PER_MM); + } if let Some(hover_pos) = response.hover_pos() { let local = (hover_pos - rect.left_top()) * PX_PER_MM;