Skip to content

Commit 70c2b27

Browse files
committed
feat(userInterface): add function row removal
1 parent 9d09c95 commit 70c2b27

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎include/mathplotter/userInterface.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace mathplotter {
2121
std::string expression;
2222
sf::Color color;
2323
bool shouldRemove{false};
24+
bool shouldErase{false};
2425
};
2526

2627
class UserInterface {

‎src/application.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,16 @@ namespace mathplotter {
144144
)
145145
};
146146

147-
if (submission->shouldRemove) {
147+
148+
if (submission->shouldErase) {
149+
if (submission->rowIndex < m_functionRenderers.size()) {
150+
m_functionRenderers.erase(
151+
m_functionRenderers.begin() +
152+
submission->rowIndex
153+
);
154+
}
155+
}
156+
else if (submission->shouldRemove) {
148157
if (submission->rowIndex < m_functionRenderers.size()) {
149158
m_functionRenderers[submission->rowIndex].reset();
150159
}

‎src/userInterface.cpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ namespace mathplotter {
342342
ImGui::GetCursorScreenPos()
343343
};
344344

345+
std::optional<std::size_t> rowToRemove;
346+
345347
for (std::size_t i{0}; i < m_functionRows.size(); ++i) {
346348
ImGui::PushID(static_cast<int>(i));
347349

@@ -487,6 +489,15 @@ namespace mathplotter {
487489
)
488490
};
489491

492+
if (
493+
ImGui::IsItemActive() &&
494+
m_functionRows[i].expression.empty() &&
495+
ImGui::IsKeyPressed(ImGuiKey_Backspace) &&
496+
m_functionRows.size() > 1
497+
) {
498+
rowToRemove = i;
499+
}
500+
490501
if (
491502
ImGui::IsItemEdited() &&
492503
m_functionRows[i].expression.empty()
@@ -521,6 +532,21 @@ namespace mathplotter {
521532

522533
ImGui::PopID();
523534
}
535+
536+
if (rowToRemove.has_value()) {
537+
submission = FunctionSubmission{
538+
*rowToRemove,
539+
"",
540+
{},
541+
false,
542+
true
543+
};
544+
545+
m_functionRows.erase(
546+
m_functionRows.begin() + *rowToRemove
547+
);
548+
}
549+
524550
ImGui::PopStyleVar();
525551
ImGui::PopStyleColor(3);
526552

0 commit comments

Comments
 (0)