Add top bar UI

Users can specify UI that will be added to the top bar of a node via the
new top_bar_ui method in NodeDataTrait. A default definition is provided
because it's not core to the functionality and so as to avoid
unnecessarily breaking existing programs.
This commit is contained in:
Kamil Koczurek 2023-05-04 14:21:39 +02:00
parent 78fe0265dd
commit ba2a00ef76
2 changed files with 20 additions and 0 deletions

View File

@ -527,6 +527,12 @@ where
.text_style(TextStyle::Button)
.color(text_color),
));
responses.extend(
self.graph[self.node_id]
.user_data
.top_bar_ui(ui, self.node_id, self.graph, user_state)
.into_iter(),
);
ui.add_space(8.0); // The size of the little cross icon
});
ui.add_space(margin.y);

View File

@ -91,6 +91,20 @@ where
where
Self::Response: UserResponseTrait;
// UI to draw on the top bar of the node.
fn top_bar_ui(
&self,
_ui: &mut egui::Ui,
_node_id: NodeId,
_graph: &Graph<Self, Self::DataType, Self::ValueType>,
_user_state: &mut Self::UserState,
) -> Vec<NodeResponse<Self::Response, Self>>
where
Self::Response: UserResponseTrait,
{
Default::default()
}
/// Set background color on titlebar
/// If the return value is None, the default color is set.
fn titlebar_color(