-
I want to build a small "inspect.exe like" application that is quite simple, composed of 2 panels. One on the left side showing the tree of UI elements and then if a UI element is selected, display the details of that UI element in the panel on the right side. I got a first bit of it working thanks to the great example of @dbalsom, which looks as follows for now: The relevant code is as follows:
However, if I want to update this code to set the
Borrow checker error:
Any sugestion how to properly handle this scenario with egui? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
hello, glad you've had some success with my tree! the easiest thing to do is have render_ui_tree_recursive() return an Option representing your selection. This will bubble it back up the stack to the root call where you can then set it. You can see example of selecting items in a tree here: this is a slightly different tree implementation as it is generic for a filesystem not UI display, but the concept should be the same. in this particular case, since this is a directory listing, there are only CollapsingHeaders present and so that is all that is clickable. It looks like you might want to change that, but you can see where I set new_event to be returned at the end: // Draw a directory node
let header_response = CollapsingHeader::new(text)
.default_open(root)
.icon(dir_icon)
.show_background(is_selected)
.open(open_control)
.show(ui, |ui| {
// Draw children recursively
children.iter().for_each(|child| {
if let Some(event) = self.tree_ui(ui, child, selected_path, false) {
// Cascade event down from children
new_event = Some(event)
}
});
})
.header_response; This works because we can only really have one click per frame (I am not sure if egui supports multitouch!) |
Beta Was this translation helpful? Give feedback.
It's also possible, if you dislike this pattern, to pass a mutable reference to a state struct to render_ui_tree_recursive which can be modified in-place and then examined after rendering is complete.