mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-11 13:58:28 +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,
|
ValueType = ValueType,
|
||||||
>,
|
>,
|
||||||
UserResponse: UserResponseTrait,
|
UserResponse: UserResponseTrait,
|
||||||
ValueType: WidgetValueTrait<Response = UserResponse>,
|
ValueType: WidgetValueTrait<Response = UserResponse, UserState = UserState>,
|
||||||
NodeTemplate: NodeTemplateTrait<
|
NodeTemplate: NodeTemplateTrait<
|
||||||
NodeData = NodeData,
|
NodeData = NodeData,
|
||||||
DataType = DataType,
|
DataType = DataType,
|
||||||
@ -391,7 +391,7 @@ where
|
|||||||
ValueType = ValueType,
|
ValueType = ValueType,
|
||||||
>,
|
>,
|
||||||
UserResponse: UserResponseTrait,
|
UserResponse: UserResponseTrait,
|
||||||
ValueType: WidgetValueTrait<Response = UserResponse>,
|
ValueType: WidgetValueTrait<Response = UserResponse, UserState = UserState>,
|
||||||
DataType: DataTypeTrait<UserState>,
|
DataType: DataTypeTrait<UserState>,
|
||||||
{
|
{
|
||||||
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
|
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
|
||||||
@ -472,7 +472,7 @@ where
|
|||||||
responses.extend(
|
responses.extend(
|
||||||
self.graph[param_id]
|
self.graph[param_id]
|
||||||
.value
|
.value
|
||||||
.value_widget(¶m_name, ui)
|
.value_widget(¶m_name, self.node_id, ui, user_state)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(NodeResponse::User),
|
.map(NodeResponse::User),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,11 +5,18 @@ use super::*;
|
|||||||
/// types of the node graph.
|
/// types of the node graph.
|
||||||
pub trait WidgetValueTrait {
|
pub trait WidgetValueTrait {
|
||||||
type Response;
|
type Response;
|
||||||
|
type UserState;
|
||||||
/// This method will be called for each input parameter with a widget. The
|
/// 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
|
/// 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
|
/// to implement handling of side effects. If unsure, the response Vec can
|
||||||
/// be empty.
|
/// 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
|
/// This trait must be implemented by the `DataType` generic parameter of the
|
||||||
|
|||||||
@ -258,7 +258,14 @@ impl NodeTemplateIter for AllMyNodeTemplates {
|
|||||||
|
|
||||||
impl WidgetValueTrait for MyValueType {
|
impl WidgetValueTrait for MyValueType {
|
||||||
type Response = MyResponse;
|
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
|
// This trait is used to tell the library which UI to display for the
|
||||||
// inline parameter widgets.
|
// inline parameter widgets.
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user