mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-10 21:38:27 +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>
|
||||
GraphEditorState<NodeData, DataType, ValueType, NodeTemplate, UserState>
|
||||
where
|
||||
NodeData: NodeDataTrait<Response = UserResponse, UserState = UserState>,
|
||||
NodeData: NodeDataTrait<
|
||||
Response = UserResponse,
|
||||
UserState = UserState,
|
||||
DataType = DataType,
|
||||
ValueType = ValueType,
|
||||
>,
|
||||
UserResponse: UserResponseTrait,
|
||||
ValueType: WidgetValueTrait,
|
||||
NodeTemplate: NodeTemplateTrait<NodeData = NodeData, DataType = DataType, ValueType = ValueType>,
|
||||
NodeTemplate:
|
||||
NodeTemplateTrait<NodeData = NodeData, DataType = DataType, ValueType = ValueType>,
|
||||
DataType: DataTypeTrait,
|
||||
{
|
||||
#[must_use]
|
||||
@ -241,18 +247,19 @@ where
|
||||
impl<'a, NodeData, DataType, ValueType, UserResponse, UserState>
|
||||
GraphNodeWidget<'a, NodeData, DataType, ValueType>
|
||||
where
|
||||
NodeData: NodeDataTrait<Response = UserResponse, UserState = UserState>,
|
||||
NodeData: NodeDataTrait<
|
||||
Response = UserResponse,
|
||||
UserState = UserState,
|
||||
DataType = DataType,
|
||||
ValueType = ValueType,
|
||||
>,
|
||||
UserResponse: UserResponseTrait,
|
||||
ValueType: WidgetValueTrait,
|
||||
DataType: DataTypeTrait,
|
||||
{
|
||||
pub const MAX_NODE_SIZE: [f32; 2] = [200.0, 200.0];
|
||||
|
||||
pub fn show(
|
||||
self,
|
||||
ui: &mut Ui,
|
||||
user_state: &UserState,
|
||||
) -> Vec<NodeResponse<UserResponse>> {
|
||||
pub fn show(self, ui: &mut Ui, user_state: &UserState) -> Vec<NodeResponse<UserResponse>> {
|
||||
let mut child_ui = ui.child_ui_with_id_source(
|
||||
Rect::from_min_size(*self.position + self.pan, Self::MAX_NODE_SIZE.into()),
|
||||
Layout::default(),
|
||||
@ -264,7 +271,11 @@ where
|
||||
|
||||
/// Draws this node. Also fills in the list of port locations with all of its ports.
|
||||
/// 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 mut responses = Vec::new();
|
||||
|
||||
|
||||
@ -28,13 +28,17 @@ where
|
||||
type Response;
|
||||
/// Must be set to the custom user `UserState` type
|
||||
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.
|
||||
fn bottom_ui<DataType, ValueType>(
|
||||
fn bottom_ui(
|
||||
&self,
|
||||
ui: &mut egui::Ui,
|
||||
node_id: NodeId,
|
||||
graph: &Graph<Self, DataType, ValueType>,
|
||||
graph: &Graph<Self, Self::DataType, Self::ValueType>,
|
||||
user_state: &Self::UserState,
|
||||
) -> Vec<NodeResponse<Self::Response>>
|
||||
where
|
||||
@ -82,4 +86,4 @@ pub trait NodeTemplateTrait: Clone {
|
||||
|
||||
/// The custom user response types when drawing nodes in the graph must
|
||||
/// 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 {
|
||||
type Response = MyResponse;
|
||||
type UserState = MyGraphState;
|
||||
type DataType = MyDataType;
|
||||
type ValueType = MyValueType;
|
||||
|
||||
// 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"
|
||||
// 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
|
||||
// node graph library.
|
||||
fn bottom_ui<DataType, ValueType>(
|
||||
fn bottom_ui(
|
||||
&self,
|
||||
ui: &mut egui::Ui,
|
||||
node_id: NodeId,
|
||||
_graph: &Graph<MyNodeData, DataType, ValueType>,
|
||||
_graph: &Graph<MyNodeData, MyDataType, MyValueType>,
|
||||
user_state: &Self::UserState,
|
||||
) -> Vec<NodeResponse<MyResponse>>
|
||||
where
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user