From 9780ab98527a29052bb7a76d749eb029ad9f74f3 Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Sat, 11 Jan 2025 19:42:13 +0100 Subject: [PATCH] Switch to C++20 and utilize std::erase_if (broken) --- CMakeLists.txt | 2 +- src/ServerMainComponent.cpp | 42 ++++++++++++++++-------------------- src/SoftKeyMaskComponent.cpp | 2 +- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a09c7a4..3d36a89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ juce_add_gui_app( DESCRIPTION "An ISO11783-6 Server") -set_target_properties(AgISOVirtualTerminal PROPERTIES CXX_STANDARD 17) +set_target_properties(AgISOVirtualTerminal PROPERTIES CXX_STANDARD 20) target_compile_definitions(AgISOVirtualTerminal PRIVATE JUCE_USE_CURL=0 JUCE_WEB_BROWSER=0) diff --git a/src/ServerMainComponent.cpp b/src/ServerMainComponent.cpp index ec2e573..9d0768b 100644 --- a/src/ServerMainComponent.cpp +++ b/src/ServerMainComponent.cpp @@ -1174,30 +1174,24 @@ void ServerMainComponent::handle_softkey_release_if_mask_changed() { // If a Key object .... is erased from the screen ... while it is activated, the VT shall send a Soft Key Activation message // ... indicating released to the erased object on its parent Data Mask. - - for (auto button = heldButtons.begin(); button != heldButtons.end();) - { - if (button->softKeyMaskObjectID != activeWorkingSetSoftkeyMaskObjectID) - { - if (button->isSoftKey) - { - send_soft_key_activation_message(isobus::VirtualTerminalBase::KeyActivationCode::ButtonUnlatchedOrReleased, - button->buttonObjectID, - button->softKeyMaskObjectID, - button->buttonKeyCode, - get_active_working_set()->get_control_function()); - // In the case if a currently pressed softkey is being replaced with a new one during a softkey mask change - // the mouseUp event on the newly added key will not be called, however the mouseRelease will. - // To prevent sending the unneeded mouse release events in this scenario we cache the softkey positions of the pressed and replaced keys. - softKeyPositionReleasedByMaskChange = button->keyPosition; - button = heldButtons.erase(button); - } - } - else - { - button++; - } - } + std::erase_if(heldButtons, + [this] (const HeldButtonData button) + { + if ((button.softKeyMaskObjectID != activeWorkingSetSoftkeyMaskObjectID) && button.isSoftKey) + { + send_soft_key_activation_message(isobus::VirtualTerminalBase::KeyActivationCode::ButtonUnlatchedOrReleased, + button.buttonObjectID, + button.softKeyMaskObjectID, + button.buttonKeyCode, + get_active_working_set()->get_control_function()); + // In the case if a currently pressed softkey is being replaced with a new one during a softkey mask change + // the mouseUp event on the newly added key will not be called, however the mouseRelease will. + // To prevent sending the unneeded mouse release events in this scenario we cache the softkey positions of the pressed and replaced keys. + softKeyPositionReleasedByMaskChange = button.keyPosition; + return true; + } + return false; + }); } void ServerMainComponent::repaint_on_next_update() diff --git a/src/SoftKeyMaskComponent.cpp b/src/SoftKeyMaskComponent.cpp index 484ef89..2b58415 100644 --- a/src/SoftKeyMaskComponent.cpp +++ b/src/SoftKeyMaskComponent.cpp @@ -36,7 +36,7 @@ void SoftKeyMaskComponent::on_content_changed(bool initial) if (isobus::VirtualTerminalObjectType::ObjectPointer == child->get_object_type()) { - childComponents.back()->setSize(softKeyWidth, softKeyHeight); + childComponents.back()->setSize(dimensionInfo.keyHeight, dimensionInfo.keyWidth); auto keyReference = get_object_by_id(std::static_pointer_cast(childComponents.back())->get_value(), parentWorkingSet->get_object_tree()); if (nullptr != keyReference && isobus::VirtualTerminalObjectType::Key == child->get_object_type()) {