mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-11 05:48:27 +00:00
Merge pull request #38 from kkngsm/connection-color
Connection color for each data type
This commit is contained in:
commit
f56c027aab
@ -55,7 +55,7 @@ where
|
|||||||
ValueType: WidgetValueTrait,
|
ValueType: WidgetValueTrait,
|
||||||
NodeTemplate:
|
NodeTemplate:
|
||||||
NodeTemplateTrait<NodeData = NodeData, DataType = DataType, ValueType = ValueType>,
|
NodeTemplateTrait<NodeData = NodeData, DataType = DataType, ValueType = ValueType>,
|
||||||
DataType: DataTypeTrait,
|
DataType: DataTypeTrait<UserState>,
|
||||||
{
|
{
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn draw_graph_editor(
|
pub fn draw_graph_editor(
|
||||||
@ -150,13 +150,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Draw connections */
|
/* Draw connections */
|
||||||
|
|
||||||
let connection_color = if ui.visuals().dark_mode {
|
|
||||||
color_from_hex("#efefef").unwrap()
|
|
||||||
} else {
|
|
||||||
color_from_hex("#bbbbbb").unwrap()
|
|
||||||
};
|
|
||||||
if let Some((_, ref locator)) = self.connection_in_progress {
|
if let Some((_, ref locator)) = self.connection_in_progress {
|
||||||
|
let port_type = self.graph.any_param_type(*locator).unwrap();
|
||||||
|
let connection_color = port_type.data_type_color(&self.user_state);
|
||||||
let start_pos = port_locations[locator];
|
let start_pos = port_locations[locator];
|
||||||
let (src_pos, dst_pos) = match locator {
|
let (src_pos, dst_pos) = match locator {
|
||||||
AnyParameterId::Output(_) => (start_pos, cursor_pos),
|
AnyParameterId::Output(_) => (start_pos, cursor_pos),
|
||||||
@ -166,6 +162,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (input, output) in self.graph.iter_connections() {
|
for (input, output) in self.graph.iter_connections() {
|
||||||
|
let port_type = self
|
||||||
|
.graph
|
||||||
|
.any_param_type(AnyParameterId::Output(output))
|
||||||
|
.unwrap();
|
||||||
|
let connection_color = port_type.data_type_color(&self.user_state);
|
||||||
let src_pos = port_locations[&AnyParameterId::Output(output)];
|
let src_pos = port_locations[&AnyParameterId::Output(output)];
|
||||||
let dst_pos = port_locations[&AnyParameterId::Input(input)];
|
let dst_pos = port_locations[&AnyParameterId::Input(input)];
|
||||||
draw_connection(ui.painter(), src_pos, dst_pos, connection_color);
|
draw_connection(ui.painter(), src_pos, dst_pos, connection_color);
|
||||||
@ -298,7 +299,7 @@ where
|
|||||||
>,
|
>,
|
||||||
UserResponse: UserResponseTrait,
|
UserResponse: UserResponseTrait,
|
||||||
ValueType: WidgetValueTrait,
|
ValueType: WidgetValueTrait,
|
||||||
DataType: DataTypeTrait,
|
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];
|
||||||
|
|
||||||
@ -404,10 +405,11 @@ where
|
|||||||
let port_right = outer_rect.right();
|
let port_right = outer_rect.right();
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn draw_port<NodeData, DataType, ValueType, UserResponse>(
|
fn draw_port<NodeData, DataType, ValueType, UserResponse, UserState>(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
graph: &Graph<NodeData, DataType, ValueType>,
|
graph: &Graph<NodeData, DataType, ValueType>,
|
||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
|
user_state: &UserState,
|
||||||
port_pos: Pos2,
|
port_pos: Pos2,
|
||||||
responses: &mut Vec<NodeResponse<UserResponse>>,
|
responses: &mut Vec<NodeResponse<UserResponse>>,
|
||||||
param_id: AnyParameterId,
|
param_id: AnyParameterId,
|
||||||
@ -415,7 +417,7 @@ where
|
|||||||
ongoing_drag: Option<(NodeId, AnyParameterId)>,
|
ongoing_drag: Option<(NodeId, AnyParameterId)>,
|
||||||
is_connected_input: bool,
|
is_connected_input: bool,
|
||||||
) where
|
) where
|
||||||
DataType: DataTypeTrait,
|
DataType: DataTypeTrait<UserState>,
|
||||||
UserResponse: UserResponseTrait,
|
UserResponse: UserResponseTrait,
|
||||||
{
|
{
|
||||||
let port_type = graph.any_param_type(param_id).unwrap();
|
let port_type = graph.any_param_type(param_id).unwrap();
|
||||||
@ -432,7 +434,7 @@ where
|
|||||||
let port_color = if resp.hovered() {
|
let port_color = if resp.hovered() {
|
||||||
Color32::WHITE
|
Color32::WHITE
|
||||||
} else {
|
} else {
|
||||||
port_type.data_type_color()
|
port_type.data_type_color(user_state)
|
||||||
};
|
};
|
||||||
ui.painter()
|
ui.painter()
|
||||||
.circle(port_rect.center(), 5.0, port_color, Stroke::none());
|
.circle(port_rect.center(), 5.0, port_color, Stroke::none());
|
||||||
@ -478,6 +480,7 @@ where
|
|||||||
ui,
|
ui,
|
||||||
self.graph,
|
self.graph,
|
||||||
self.node_id,
|
self.node_id,
|
||||||
|
user_state,
|
||||||
pos_left,
|
pos_left,
|
||||||
&mut responses,
|
&mut responses,
|
||||||
AnyParameterId::Input(*param),
|
AnyParameterId::Input(*param),
|
||||||
@ -499,6 +502,7 @@ where
|
|||||||
ui,
|
ui,
|
||||||
self.graph,
|
self.graph,
|
||||||
self.node_id,
|
self.node_id,
|
||||||
|
user_state,
|
||||||
pos_right,
|
pos_right,
|
||||||
&mut responses,
|
&mut responses,
|
||||||
AnyParameterId::Output(*param),
|
AnyParameterId::Output(*param),
|
||||||
|
|||||||
@ -10,9 +10,9 @@ pub trait WidgetValueTrait {
|
|||||||
/// This trait must be implemented by the `DataType` generic parameter of the
|
/// This trait must be implemented by the `DataType` generic parameter of the
|
||||||
/// [`Graph`]. This trait tells the library how to visually expose data types
|
/// [`Graph`]. This trait tells the library how to visually expose data types
|
||||||
/// to the user.
|
/// to the user.
|
||||||
pub trait DataTypeTrait: PartialEq + Eq {
|
pub trait DataTypeTrait<UserState>: PartialEq + Eq {
|
||||||
// The associated port color of this datatype
|
// The associated port color of this datatype
|
||||||
fn data_type_color(&self) -> egui::Color32;
|
fn data_type_color(&self, user_state: &UserState) -> egui::Color32;
|
||||||
|
|
||||||
// The name of this datatype
|
// The name of this datatype
|
||||||
fn name(&self) -> &str;
|
fn name(&self) -> &str;
|
||||||
|
|||||||
@ -89,8 +89,8 @@ pub struct MyGraphState {
|
|||||||
// =========== Then, you need to implement some traits ============
|
// =========== Then, you need to implement some traits ============
|
||||||
|
|
||||||
// A trait for the data types, to tell the library how to display them
|
// A trait for the data types, to tell the library how to display them
|
||||||
impl DataTypeTrait for MyDataType {
|
impl DataTypeTrait<MyGraphState> for MyDataType {
|
||||||
fn data_type_color(&self) -> egui::Color32 {
|
fn data_type_color(&self, _user_state: &MyGraphState) -> egui::Color32 {
|
||||||
match self {
|
match self {
|
||||||
MyDataType::Scalar => egui::Color32::from_rgb(38, 109, 211),
|
MyDataType::Scalar => egui::Color32::from_rgb(38, 109, 211),
|
||||||
MyDataType::Vec2 => egui::Color32::from_rgb(238, 207, 109),
|
MyDataType::Vec2 => egui::Color32::from_rgb(238, 207, 109),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user