mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-22 02:58:28 +00:00
Move generic parameters to associated types in NodeDataTrait
This commit is contained in:
parent
e16968256a
commit
4804b859c1
@ -44,10 +44,16 @@ pub struct GraphNodeWidget<'a, NodeData, DataType, ValueType> {
|
|||||||
impl<NodeData, DataType, ValueType, NodeTemplate, UserResponse, UserState>
|
impl<NodeData, DataType, ValueType, NodeTemplate, UserResponse, UserState>
|
||||||
GraphEditorState<NodeData, DataType, ValueType, NodeTemplate, UserState>
|
GraphEditorState<NodeData, DataType, ValueType, NodeTemplate, UserState>
|
||||||
where
|
where
|
||||||
NodeData: NodeDataTrait<Response = UserResponse, UserState = UserState>,
|
NodeData: NodeDataTrait<
|
||||||
|
Response = UserResponse,
|
||||||
|
UserState = UserState,
|
||||||
|
DataType = DataType,
|
||||||
|
ValueType = ValueType,
|
||||||
|
>,
|
||||||
UserResponse: UserResponseTrait,
|
UserResponse: UserResponseTrait,
|
||||||
ValueType: WidgetValueTrait,
|
ValueType: WidgetValueTrait,
|
||||||
NodeTemplate: NodeTemplateTrait<NodeData = NodeData, DataType = DataType, ValueType = ValueType>,
|
NodeTemplate:
|
||||||
|
NodeTemplateTrait<NodeData = NodeData, DataType = DataType, ValueType = ValueType>,
|
||||||
DataType: DataTypeTrait,
|
DataType: DataTypeTrait,
|
||||||
{
|
{
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@ -241,18 +247,19 @@ where
|
|||||||
impl<'a, NodeData, DataType, ValueType, UserResponse, UserState>
|
impl<'a, NodeData, DataType, ValueType, UserResponse, UserState>
|
||||||
GraphNodeWidget<'a, NodeData, DataType, ValueType>
|
GraphNodeWidget<'a, NodeData, DataType, ValueType>
|
||||||
where
|
where
|
||||||
NodeData: NodeDataTrait<Response = UserResponse, UserState = UserState>,
|
NodeData: NodeDataTrait<
|
||||||
|
Response = UserResponse,
|
||||||
|
UserState = UserState,
|
||||||
|
DataType = DataType,
|
||||||
|
ValueType = ValueType,
|
||||||
|
>,
|
||||||
UserResponse: UserResponseTrait,
|
UserResponse: UserResponseTrait,
|
||||||
ValueType: WidgetValueTrait,
|
ValueType: WidgetValueTrait,
|
||||||
DataType: DataTypeTrait,
|
DataType: DataTypeTrait,
|
||||||
{
|
{
|
||||||
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
|
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
|
||||||
|
|
||||||
pub fn show(
|
pub fn show(self, ui: &mut Ui, user_state: &UserState) -> Vec<NodeResponse<UserResponse>> {
|
||||||
self,
|
|
||||||
ui: &mut Ui,
|
|
||||||
user_state: &UserState,
|
|
||||||
) -> Vec<NodeResponse<UserResponse>> {
|
|
||||||
let mut child_ui = ui.child_ui_with_id_source(
|
let mut child_ui = ui.child_ui_with_id_source(
|
||||||
Rect::from_min_size(*self.position + self.pan, Self::MAX_NODE_SIZE.into()),
|
Rect::from_min_size(*self.position + self.pan, Self::MAX_NODE_SIZE.into()),
|
||||||
Layout::default(),
|
Layout::default(),
|
||||||
@ -264,7 +271,11 @@ where
|
|||||||
|
|
||||||
/// Draws this node. Also fills in the list of port locations with all of its ports.
|
/// Draws this node. Also fills in the list of port locations with all of its ports.
|
||||||
/// Returns responses indicating multiple events.
|
/// Returns responses indicating multiple events.
|
||||||
fn show_graph_node(self, ui: &mut Ui, user_state: &UserState) -> Vec<NodeResponse<UserResponse>> {
|
fn show_graph_node(
|
||||||
|
self,
|
||||||
|
ui: &mut Ui,
|
||||||
|
user_state: &UserState,
|
||||||
|
) -> Vec<NodeResponse<UserResponse>> {
|
||||||
let margin = egui::vec2(15.0, 5.0);
|
let margin = egui::vec2(15.0, 5.0);
|
||||||
let mut responses = Vec::new();
|
let mut responses = Vec::new();
|
||||||
|
|
||||||
|
|||||||
@ -28,13 +28,17 @@ where
|
|||||||
type Response;
|
type Response;
|
||||||
/// Must be set to the custom user `UserState` type
|
/// Must be set to the custom user `UserState` type
|
||||||
type UserState;
|
type UserState;
|
||||||
|
/// Must be set to the custom user `DataType` type
|
||||||
|
type DataType;
|
||||||
|
/// Must be set to the custom user `ValueType` type
|
||||||
|
type ValueType;
|
||||||
|
|
||||||
/// Additional UI elements to draw in the nodes, after the parameters.
|
/// Additional UI elements to draw in the nodes, after the parameters.
|
||||||
fn bottom_ui<DataType, ValueType>(
|
fn bottom_ui(
|
||||||
&self,
|
&self,
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
graph: &Graph<Self, DataType, ValueType>,
|
graph: &Graph<Self, Self::DataType, Self::ValueType>,
|
||||||
user_state: &Self::UserState,
|
user_state: &Self::UserState,
|
||||||
) -> Vec<NodeResponse<Self::Response>>
|
) -> Vec<NodeResponse<Self::Response>>
|
||||||
where
|
where
|
||||||
@ -82,4 +86,4 @@ pub trait NodeTemplateTrait: Clone {
|
|||||||
|
|
||||||
/// The custom user response types when drawing nodes in the graph must
|
/// The custom user response types when drawing nodes in the graph must
|
||||||
/// implement this trait.
|
/// implement this trait.
|
||||||
pub trait UserResponseTrait: Clone + Copy + std::fmt::Debug + PartialEq + Eq {}
|
pub trait UserResponseTrait: Clone + Copy + std::fmt::Debug + PartialEq + Eq {}
|
||||||
|
|||||||
@ -242,17 +242,19 @@ impl UserResponseTrait for MyResponse {}
|
|||||||
impl NodeDataTrait for MyNodeData {
|
impl NodeDataTrait for MyNodeData {
|
||||||
type Response = MyResponse;
|
type Response = MyResponse;
|
||||||
type UserState = MyGraphState;
|
type UserState = MyGraphState;
|
||||||
|
type DataType = MyDataType;
|
||||||
|
type ValueType = MyValueType;
|
||||||
|
|
||||||
// This method will be called when drawing each node. This allows adding
|
// This method will be called when drawing each node. This allows adding
|
||||||
// extra ui elements inside the nodes. In this case, we create an "active"
|
// extra ui elements inside the nodes. In this case, we create an "active"
|
||||||
// button which introduces the concept of having an active node in the
|
// button which introduces the concept of having an active node in the
|
||||||
// graph. This is done entirely from user code with no modifications to the
|
// graph. This is done entirely from user code with no modifications to the
|
||||||
// node graph library.
|
// node graph library.
|
||||||
fn bottom_ui<DataType, ValueType>(
|
fn bottom_ui(
|
||||||
&self,
|
&self,
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
_graph: &Graph<MyNodeData, DataType, ValueType>,
|
_graph: &Graph<MyNodeData, MyDataType, MyValueType>,
|
||||||
user_state: &Self::UserState,
|
user_state: &Self::UserState,
|
||||||
) -> Vec<NodeResponse<MyResponse>>
|
) -> Vec<NodeResponse<MyResponse>>
|
||||||
where
|
where
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user