Changed the UserState args to mutable

This commit is contained in:
KOKI 2022-09-16 21:30:34 +09:00
parent b32d864f0b
commit 19ce5f4fa3
3 changed files with 12 additions and 12 deletions

View File

@ -82,7 +82,7 @@ where
&mut self,
ui: &mut Ui,
all_kinds: impl NodeTemplateIter<Item = NodeTemplate>,
user_state: &UserState,
user_state: &mut UserState,
) -> GraphResponse<UserResponse, NodeData> {
// This causes the graph editor to use as much free space as it can.
// (so for windows it will use up to the resizeably set limit
@ -357,7 +357,7 @@ where
pub fn show(
self,
ui: &mut Ui,
user_state: &UserState,
user_state: &mut UserState,
) -> Vec<NodeResponse<UserResponse, NodeData>> {
let mut child_ui = ui.child_ui_with_id_source(
Rect::from_min_size(*self.position + self.pan, Self::MAX_NODE_SIZE.into()),
@ -373,7 +373,7 @@ where
fn show_graph_node(
self,
ui: &mut Ui,
user_state: &UserState,
user_state: &mut UserState,
) -> Vec<NodeResponse<UserResponse, NodeData>> {
let margin = egui::vec2(15.0, 5.0);
let mut responses = Vec::<NodeResponse<UserResponse, NodeData>>::new();
@ -468,7 +468,7 @@ where
ui: &mut Ui,
graph: &Graph<NodeData, DataType, ValueType>,
node_id: NodeId,
user_state: &UserState,
user_state: &mut UserState,
port_pos: Pos2,
responses: &mut Vec<NodeResponse<UserResponse, NodeData>>,
param_id: AnyParameterId,

View File

@ -17,7 +17,7 @@ pub trait WidgetValueTrait {
/// to the user.
pub trait DataTypeTrait<UserState>: PartialEq + Eq {
/// The associated port color of this datatype
fn data_type_color(&self, user_state: &UserState) -> egui::Color32;
fn data_type_color(&self, user_state: &mut UserState) -> egui::Color32;
/// The name of this datatype. Return type is specified as Cow<str> because
/// some implementations will need to allocate a new string to provide an
@ -71,7 +71,7 @@ where
ui: &mut egui::Ui,
node_id: NodeId,
graph: &Graph<Self, Self::DataType, Self::ValueType>,
user_state: &Self::UserState,
user_state: &mut Self::UserState,
) -> Vec<NodeResponse<Self::Response, Self>>
where
Self::Response: UserResponseTrait;
@ -83,7 +83,7 @@ where
_ui: &egui::Ui,
_node_id: NodeId,
_graph: &Graph<Self, Self::DataType, Self::ValueType>,
_user_state: &Self::UserState,
_user_state: &mut Self::UserState,
) -> Option<egui::Color32> {
None
}
@ -126,7 +126,7 @@ pub trait NodeTemplateTrait: Clone {
fn build_node(
&self,
graph: &mut Graph<Self::NodeData, Self::DataType, Self::ValueType>,
user_state: &Self::UserState,
user_state: &mut Self::UserState,
node_id: NodeId,
);
}

View File

@ -95,7 +95,7 @@ pub struct MyGraphState {
// A trait for the data types, to tell the library how to display them
impl DataTypeTrait<MyGraphState> for MyDataType {
fn data_type_color(&self, _user_state: &MyGraphState) -> egui::Color32 {
fn data_type_color(&self, _user_state: &mut MyGraphState) -> egui::Color32 {
match self {
MyDataType::Scalar => egui::Color32::from_rgb(38, 109, 211),
MyDataType::Vec2 => egui::Color32::from_rgb(238, 207, 109),
@ -143,7 +143,7 @@ impl NodeTemplateTrait for MyNodeTemplate {
fn build_node(
&self,
graph: &mut Graph<Self::NodeData, Self::DataType, Self::ValueType>,
_user_state: &Self::UserState,
_user_state: &mut Self::UserState,
node_id: NodeId,
) {
// The nodes are created empty by default. This function needs to take
@ -300,7 +300,7 @@ impl NodeDataTrait for MyNodeData {
ui: &mut egui::Ui,
node_id: NodeId,
_graph: &Graph<MyNodeData, MyDataType, MyValueType>,
user_state: &Self::UserState,
user_state: &mut Self::UserState,
) -> Vec<NodeResponse<MyResponse, MyNodeData>>
where
MyResponse: UserResponseTrait,
@ -394,7 +394,7 @@ impl eframe::App for NodeGraphExample {
let graph_response = egui::CentralPanel::default()
.show(ctx, |ui| {
self.state
.draw_graph_editor(ui, AllMyNodeTemplates, &self.user_state)
.draw_graph_editor(ui, AllMyNodeTemplates, &mut self.user_state)
})
.inner;
for node_response in graph_response.node_responses {