Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground: enhance inspector & display viewport coordinates #26

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 62 additions & 32 deletions examples/playground/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct App {
show_grid: bool,

#[serde(skip)]
editor_pos: Pos,
viewport_position: Pos,
#[serde(skip)]
cursor_pos: Option<Pos>,
}
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -173,27 +161,42 @@ 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(
egui::TextEdit::singleline(&mut socket.style.name)
.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| {
Expand All @@ -202,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.");

Expand Down Expand Up @@ -393,6 +396,33 @@ impl App {
if let Some((a, b)) = graph.connection {
self.graph.connections_mut().connect(a, b);
}

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);
});
},
);
}
}
}

Expand Down
Loading