Expose UserState and the node id to value_widget

This commit is contained in:
Setzer22 2022-10-29 15:43:55 +02:00
parent b65a780f35
commit 79fbe31482
3 changed files with 19 additions and 5 deletions

View File

@ -76,7 +76,7 @@ where
ValueType = ValueType,
>,
UserResponse: UserResponseTrait,
ValueType: WidgetValueTrait<Response = UserResponse>,
ValueType: WidgetValueTrait<Response = UserResponse, UserState = UserState>,
NodeTemplate: NodeTemplateTrait<
NodeData = NodeData,
DataType = DataType,
@ -391,7 +391,7 @@ where
ValueType = ValueType,
>,
UserResponse: UserResponseTrait,
ValueType: WidgetValueTrait<Response = UserResponse>,
ValueType: WidgetValueTrait<Response = UserResponse, UserState = UserState>,
DataType: DataTypeTrait<UserState>,
{
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
@ -472,7 +472,7 @@ where
responses.extend(
self.graph[param_id]
.value
.value_widget(&param_name, ui)
.value_widget(&param_name, self.node_id, ui, user_state)
.into_iter()
.map(NodeResponse::User),
);

View File

@ -5,11 +5,18 @@ use super::*;
/// types of the node graph.
pub trait WidgetValueTrait {
type Response;
type UserState;
/// 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>;
fn value_widget(
&mut self,
param_name: &str,
node_id: NodeId,
ui: &mut egui::Ui,
user_state: &mut Self::UserState,
) -> Vec<Self::Response>;
}
/// This trait must be implemented by the `DataType` generic parameter of the

View File

@ -258,7 +258,14 @@ impl NodeTemplateIter for AllMyNodeTemplates {
impl WidgetValueTrait for MyValueType {
type Response = MyResponse;
fn value_widget(&mut self, param_name: &str, ui: &mut egui::Ui) -> Vec<MyResponse> {
type UserState = MyGraphState;
fn value_widget(
&mut self,
param_name: &str,
_node_id: NodeId,
ui: &mut egui::Ui,
_user_state: &mut MyGraphState,
) -> Vec<MyResponse> {
// This trait is used to tell the library which UI to display for the
// inline parameter widgets.
match self {