From 3f62264bc68bd320acbaf8b7bf34703597bd5e4c Mon Sep 17 00:00:00 2001 From: Tristan Guichaoua Date: Wed, 11 Dec 2024 12:33:04 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=84=20use=20better=20layout=20for?= =?UTF-8?q?=20sockets=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/playground/src/app/mod.rs | 61 ++++++++++++++++-------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/examples/playground/src/app/mod.rs b/examples/playground/src/app/mod.rs index 4eaae86..3eeaee5 100644 --- a/examples/playground/src/app/mod.rs +++ b/examples/playground/src/app/mod.rs @@ -135,27 +135,15 @@ impl App { if ui.button("➕").clicked() { node.add_socket(); } + egui::ScrollArea::vertical().show(ui, |ui| { - egui::Grid::new(ui.id().with("socket node inspector grid")) - .num_columns(8) - .min_col_width(0.0) - .show(ui, |ui| { - ui.horizontal(|_| {}); - ui.horizontal(|_| {}); - ui.horizontal(|_| {}); - ui.label("Id"); - ui.label("Color"); - ui.label("Side"); - ui.label("Shape"); - ui.label("Name"); - ui.end_row(); - - let len = node.sockets().len(); - - for (i, socket) in node.sockets_mut().iter_mut().enumerate() { - let is_first = i == 0; - let is_last = i == len - 1; + let len = node.sockets().len(); + for (i, socket) in node.sockets_mut().iter_mut().enumerate() { + let is_first = i == 0; + let is_last = i == len - 1; + egui::Frame::group(ui.style()).show(ui, |ui| { + ui.horizontal(|ui| { if ui.button("🗙").clicked() { socket_action = SocketAction::Remove(socket.id()); } @@ -173,16 +161,17 @@ impl App { }); ui.add(egui::Label::new(socket.id().to_string()).truncate()); + }); - ui.add(widget::maybe_color(&mut socket.style.color)); - - ui.add(widget::node_side(&mut socket.style.side)); - - ui.add(widget::socket_shape( - ui.id().with(socket.id()), - &mut socket.style.shape, - )); - + egui::Grid::new( + ui.id().with("socket node inspector grid").with(socket.id()), + ) + .striped(true) + .num_columns(2) + .min_col_width(0.0) + .min_row_height(25.0) + .show(ui, |ui| { + ui.label("Name"); ui.horizontal(|ui| { ui.add(widget::maybe_color(&mut socket.style.name_color)); ui.add( @@ -190,10 +179,24 @@ impl App { .desired_width(f32::INFINITY), ); }); + ui.end_row(); + + ui.label("Shape"); + ui.horizontal(|ui| { + ui.add(widget::maybe_color(&mut socket.style.color)); + ui.add(widget::socket_shape( + ui.id().with(socket.id()), + &mut socket.style.shape, + )); + }); + ui.end_row(); + ui.label("Side"); + ui.add(widget::node_side(&mut socket.style.side)); ui.end_row(); - } + }); }); + } }); } else { egui::Frame::group(ui.style()).show(ui, |ui| { From fc4fa0dd70361bfd89c00d3ea424510d56accb6e Mon Sep 17 00:00:00 2001 From: Tristan Guichaoua Date: Wed, 11 Dec 2024 12:35:05 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20update=20the=20viewport=5Fpo?= =?UTF-8?q?sition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/playground/src/app/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/playground/src/app/mod.rs b/examples/playground/src/app/mod.rs index 3eeaee5..20fbe81 100644 --- a/examples/playground/src/app/mod.rs +++ b/examples/playground/src/app/mod.rs @@ -14,7 +14,7 @@ pub struct App { show_grid: bool, #[serde(skip)] - editor_pos: Pos, + viewport_position: Pos, #[serde(skip)] cursor_pos: Option, } @@ -25,7 +25,7 @@ impl Default for App { Self { graph: GraphApp::default(), show_grid: false, - editor_pos: Pos::default(), + viewport_position: Pos::default(), cursor_pos: None, } } @@ -205,7 +205,7 @@ impl App { ui.label("Click on a node or "); if ui.link("create one").clicked() { - self.graph.new_node(self.editor_pos); + self.graph.new_node(self.viewport_position); } ui.label(" to edit it."); @@ -396,6 +396,8 @@ impl App { if let Some((a, b)) = graph.connection { self.graph.connections_mut().connect(a, b); } + + self.viewport_position = graph.position; } } From a4522d0273f8a83c15ad81034973a24c85c03fa2 Mon Sep 17 00:00:00 2001 From: Tristan Guichaoua Date: Wed, 11 Dec 2024 13:10:24 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20show=20current=20coordinates=20?= =?UTF-8?q?of=20the=20viewport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/playground/src/app/mod.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/examples/playground/src/app/mod.rs b/examples/playground/src/app/mod.rs index 20fbe81..3987ab9 100644 --- a/examples/playground/src/app/mod.rs +++ b/examples/playground/src/app/mod.rs @@ -398,6 +398,31 @@ impl App { } self.viewport_position = graph.position; + + { + let mut ui = ui.new_child( + egui::UiBuilder::new() + .max_rect(graph.response.rect) + .layout(egui::Layout::bottom_up(egui::Align::Min)), + ); + + ui.with_layer_id( + egui::LayerId::new(egui::Order::Tooltip, graph.response.id), + |ui| { + egui::Frame::group(ui.style()) + .rounding(egui::Rounding::ZERO) + .fill(ui.visuals().extreme_bg_color) + .show(ui, |ui| { + ui.add(egui::Label::new(format!( + "{}, {}", + self.viewport_position.x, self.viewport_position.y + ))); + + ui.set_min_width(50.0); + }); + }, + ); + } } }