Skip to content

Commit ba33a4f

Browse files
committed
tree: context menu and selection painting again
1 parent 630c0ca commit ba33a4f

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

gui/src/tree.rs

+25-19
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,21 @@ impl NodeTree {
5858
DragDropPayload::WithNode(node_id),
5959
on_action,
6060
|ui| {
61-
ui.label("○");
62-
ui.label(node_name)
61+
Self::node_frame(ui, app.ui.selected_node == node_id).show(ui, |ui| {
62+
ui.label("○");
63+
ui.label(node_name);
64+
});
6365
},
6466
);
6567

6668
let response = ui.interact(ui.min_rect(), id2, egui::Sense::click());
6769
if response.clicked() {
6870
on_action(GuiAction::SelectNode { node: node_id });
6971
}
72+
73+
response.context_menu(|ui| {
74+
Self::context_menu(app, node, on_action, node_id, ui);
75+
});
7076
});
7177
});
7278

@@ -181,23 +187,6 @@ impl NodeTree {
181187
}
182188
}
183189

184-
response.context_menu(|ui| {
185-
if ui.button("Add child node").clicked() {
186-
on_action(GuiAction::AddNode {
187-
parent: node_id,
188-
index: node.children.len(),
189-
});
190-
ui.close_menu()
191-
}
192-
if ui.button("Delete").clicked() {
193-
on_action(GuiAction::RemoveNode { node: node_id });
194-
ui.close_menu()
195-
}
196-
for tag in node.tags.iter() {
197-
ui.label(app.document.tag_name(*tag));
198-
}
199-
});
200-
201190
// Check for drags:
202191
let dnd_response = ui
203192
.interact(response.rect.clone(), id, Sense::drag())
@@ -207,6 +196,23 @@ impl NodeTree {
207196
}
208197
}
209198

199+
fn context_menu(app: &Application, node: &Node, on_action: &mut impl FnMut(GuiAction), node_id: NodeId, ui: &mut Ui) {
200+
if ui.button("Add child node").clicked() {
201+
on_action(GuiAction::AddNode {
202+
parent: node_id,
203+
index: node.children.len(),
204+
});
205+
ui.close_menu()
206+
}
207+
if ui.button("Delete").clicked() {
208+
on_action(GuiAction::RemoveNode { node: node_id });
209+
ui.close_menu()
210+
}
211+
for tag in node.tags.iter() {
212+
ui.label(app.document.tag_name(*tag));
213+
}
214+
}
215+
210216
fn is_ancestor(&self, app: &Application, node_id: NodeId, assumed_ancestor: NodeId) -> bool {
211217
let node = app.document.nodes.get(node_id).expect("");
212218

0 commit comments

Comments
 (0)