File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments