Skip to content

Commit 9d09c95

Browse files
committed
fix(userInterface): remove function when expression is cleared
1 parent 78cb2ad commit 9d09c95

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

‎include/mathplotter/userInterface.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace mathplotter {
2020
std::size_t rowIndex;
2121
std::string expression;
2222
sf::Color color;
23+
bool shouldRemove{false};
2324
};
2425

2526
class UserInterface {

‎src/application.cpp‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,30 @@ namespace mathplotter {
144144
)
145145
};
146146

147-
if (renderer->IsValid()) {
148-
m_functionRenderers[submission->rowIndex] =
149-
std::move(renderer);
150-
151-
m_userInterface.SetFunctionError(
152-
submission->rowIndex,
153-
false
154-
);
147+
if (submission->shouldRemove) {
148+
if (submission->rowIndex < m_functionRenderers.size()) {
149+
m_functionRenderers[submission->rowIndex].reset();
150+
}
155151
} else {
156-
m_functionRenderers[submission->rowIndex].reset();
157-
158-
m_userInterface.SetFunctionError(
159-
submission->rowIndex,
160-
true
161-
);
152+
if (renderer->IsValid()) {
153+
m_functionRenderers[submission->rowIndex] =
154+
std::move(renderer);
155+
156+
m_userInterface.SetFunctionError(
157+
submission->rowIndex,
158+
false
159+
);
160+
} else {
161+
m_functionRenderers[submission->rowIndex].reset();
162+
163+
m_userInterface.SetFunctionError(
164+
submission->rowIndex,
165+
true
166+
);
167+
}
162168
}
169+
170+
163171
}
164172

165173
// Render User Interface

‎src/userInterface.cpp‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,19 @@ namespace mathplotter {
487487
)
488488
};
489489

490-
if (ImGui::IsItemEdited()) {
490+
if (
491+
ImGui::IsItemEdited() &&
492+
m_functionRows[i].expression.empty()
493+
) {
491494
m_functionRows[i].isSubmitted = false;
495+
m_functionRows[i].hasError = false;
496+
497+
submission = FunctionSubmission{
498+
i,
499+
"",
500+
ToSfmlColor(m_functionRows[i].color),
501+
true
502+
};
492503
}
493504

494505
if (

0 commit comments

Comments
 (0)