mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-10 21:38:27 +00:00
Merge pull request #35 from IsseW/widget-response
Add user response to WidgetValueTrait
This commit is contained in:
commit
6ebb4995c4
@ -52,7 +52,7 @@ where
|
||||
ValueType = ValueType,
|
||||
>,
|
||||
UserResponse: UserResponseTrait,
|
||||
ValueType: WidgetValueTrait,
|
||||
ValueType: WidgetValueTrait<Response = UserResponse>,
|
||||
NodeTemplate:
|
||||
NodeTemplateTrait<NodeData = NodeData, DataType = DataType, ValueType = ValueType>,
|
||||
DataType: DataTypeTrait<UserState>,
|
||||
@ -298,7 +298,7 @@ where
|
||||
ValueType = ValueType,
|
||||
>,
|
||||
UserResponse: UserResponseTrait,
|
||||
ValueType: WidgetValueTrait,
|
||||
ValueType: WidgetValueTrait<Response = UserResponse>,
|
||||
DataType: DataTypeTrait<UserState>,
|
||||
{
|
||||
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
|
||||
@ -374,7 +374,13 @@ where
|
||||
if self.graph.connection(param_id).is_some() {
|
||||
ui.label(param_name);
|
||||
} else {
|
||||
self.graph[param_id].value.value_widget(¶m_name, ui);
|
||||
responses.extend(
|
||||
self.graph[param_id]
|
||||
.value
|
||||
.value_widget(¶m_name, ui)
|
||||
.into_iter()
|
||||
.map(NodeResponse::User),
|
||||
);
|
||||
}
|
||||
let height_after = ui.min_rect().bottom();
|
||||
input_port_heights.push((height_before + height_after) / 2.0);
|
||||
|
||||
@ -4,7 +4,12 @@ use super::*;
|
||||
/// [`Graph`]. The trait allows drawing custom inline widgets for the different
|
||||
/// types of the node graph.
|
||||
pub trait WidgetValueTrait {
|
||||
fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui);
|
||||
type Response;
|
||||
/// This method will be called for each input parameter with a widget. The
|
||||
/// return value is a vector of custom response objects which can be used
|
||||
/// to implement handling of side effects. If unsure, the response Vec can
|
||||
/// be empty.
|
||||
fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec<Self::Response>;
|
||||
}
|
||||
|
||||
/// This trait must be implemented by the `DataType` generic parameter of the
|
||||
|
||||
@ -250,7 +250,8 @@ impl NodeTemplateIter for AllMyNodeTemplates {
|
||||
}
|
||||
|
||||
impl WidgetValueTrait for MyValueType {
|
||||
fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) {
|
||||
type Response = MyResponse;
|
||||
fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec<MyResponse> {
|
||||
// This trait is used to tell the library which UI to display for the
|
||||
// inline parameter widgets.
|
||||
match self {
|
||||
@ -270,6 +271,8 @@ impl WidgetValueTrait for MyValueType {
|
||||
});
|
||||
}
|
||||
}
|
||||
// This allows you to return your responses from the inline widgets.
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user