mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-10 05:18:27 +00:00
Expose UserState and the node id to value_widget
This commit is contained in:
parent
b65a780f35
commit
79fbe31482
@ -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(¶m_name, ui)
|
||||
.value_widget(¶m_name, self.node_id, ui, user_state)
|
||||
.into_iter()
|
||||
.map(NodeResponse::User),
|
||||
);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user