Skip to content

Commit

Permalink
πŸ› Fix: wrong values were stored in the history
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Oct 31, 2022
1 parent 0a445b4 commit 58b1430
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Dependencies/Ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,25 @@ class Ui_Ref {
template<typename T>
void widget(const Cool::VariableId<T>& id, Cool::Variable<T>& variable)
{
const auto prev_value = variable.value;
const auto prev_metadata = variable.metadata;
Cool::imgui(
variable,
{
.on_value_changed =
[&]() { _command_executor.execute(
Command_SetVariable<T>{.id = id, .value = variable.value}
[&]() {
const auto new_value = variable.value;
variable.value = prev_value; // To make sure the reversible command that will be created sees the correct previous value.
_command_executor.execute(
Command_SetVariable<T>{.id = id, .value = new_value}
); },

.on_metadata_changed =
[&]() { _command_executor.execute(
Command_SetVariableMetadata<T>{.id = id, .metadata = variable.metadata}
[&]() {
const auto new_metadata = variable.metadata;
variable.metadata = prev_metadata; // To make sure the reversible command that will be created sees the correct previous value.
_command_executor.execute(
Command_SetVariableMetadata<T>{.id = id, .metadata = new_metadata}
); },

.on_value_editing_finished =
Expand Down

0 comments on commit 58b1430

Please sign in to comment.