-
Notifications
You must be signed in to change notification settings - Fork 137
Change UserState to outside of GraphEditorState #57
Comments
I am thinking of changing some the UserState arguments from &UserState to &mut UserState, is there any reason why it should be &UserState? |
Hi! You are right, there is no reason I can think of to have
When the user state struct was inside the graph, it wasn't possible to pass it as an exclusive reference to some methods. If that is possible now after your PR, it may help simplify some things so I wouldn't be against it 🤔 I still like the current design where people are encouraged to defer mutations to the user state until the end via the |
Making user_state mutable in bottom_ui() makes the following line unnecessary, but requires an example of response usage. egui_node_graph/egui_node_graph_example/src/app.rs Lines 404 to 409 in 75308d0
I suggest adding a node such as AddScalarByUi (related #25). |
I like that the current example showcases the custom user response feature. Deferring side effects is useful, because it lets you decouple the UI code from the business logic. Showing that in the example helps users understand why there's a custom response type to begin with. This would be more obvious if there was more complex logic attached to the "set active" action, but then that would complicate the example unnecessarily. |
Ok, I just realized I misunderstood your original comment. Sorry about that @kkngsm! Yes, I'm all for an example like |
In some cases, you do not want to implement serde in UserState but want to pass it as an argument to bottom_ui().
However, currently, if the user implements serde in GraphEditorState, the user must also implement it in UserState.
Therefore, we suggest not keeping UserState in GraphEditorState.
Like this,
The text was updated successfully, but these errors were encountered: