From 0cdc49d21e121b96c0d82e8124306caa370ad71e Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Fri, 14 Feb 2025 02:25:48 +0100 Subject: [PATCH] More draggable number fixes --- Source/Components/DraggableNumber.h | 22 ++-------------------- Source/Components/PropertiesPanel.h | 7 ++++++- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/Source/Components/DraggableNumber.h b/Source/Components/DraggableNumber.h index ab9b700f8..0d611a476 100644 --- a/Source/Components/DraggableNumber.h +++ b/Source/Components/DraggableNumber.h @@ -90,18 +90,6 @@ class DraggableNumber : public Component, public TextEditor::Listener editor.setJustification(Justification::centredLeft); } - void editorHidden(Label*, TextEditor& editor) - { - auto const text = editor.getText(); - double const newValue = parseExpression(text); - - onInteraction(hasKeyboardFocus(false)); - setValue(newValue, dontSendNotification); - editor.setText(currentValue, dontSendNotification); - decimalDrag = 0; - dragEnd(); - } - void focusGained(FocusChangeType const cause) override { if (editableOnSingleClick @@ -127,7 +115,7 @@ class DraggableNumber : public Component, public TextEditor::Listener void setText(String const& newText, NotificationType notification) { - hideEditor(false); + hideEditor(true); currentValue = newText; repaint(); @@ -276,7 +264,7 @@ class DraggableNumber : public Component, public TextEditor::Listener decimalDrag = 0; updateFromTextEditorContents (*outgoingEditor); } - + outgoingEditor.reset(); if (deletionChecker != nullptr) { @@ -909,12 +897,6 @@ struct DraggableListNumber final : public DraggableNumber { nvgText(nvg, textArea.getX(), textArea.getCentreY() + 1.5f, listText.toRawUTF8(), nullptr); } - void editorHidden(Label* l, TextEditor& editor) // TODO: this should override something - { - setText(editor.getText().trimEnd(), dontSendNotification); - onValueChange(0); - dragEnd(); - } void updateListHoverPosition(int const x) { diff --git a/Source/Components/PropertiesPanel.h b/Source/Components/PropertiesPanel.h index e9617a069..00b922b6a 100644 --- a/Source/Components/PropertiesPanel.h +++ b/Source/Components/PropertiesPanel.h @@ -970,6 +970,7 @@ class PropertiesPanel : public Component { draggableNumber->setText(property.toString(), dontSendNotification); draggableNumber->setFont(draggableNumber->getFont().withHeight(14.5f)); draggableNumber->setEditableOnClick(true); + if (minimum != 0.0f) draggableNumber->setMinimum(minimum); if (maximum != 0.0f) @@ -978,10 +979,14 @@ class PropertiesPanel : public Component { if (onInteractionFn) draggableNumber->onInteraction = onInteractionFn; - draggableNumber->onValueChange = [this](double newValue){ + draggableNumber->onValueChange = [this](double const newValue){ property = newValue; }; + draggableNumber->onReturnKey = [this](double const newValue) { + property = newValue; + }; + property.addListener(this); draggableNumber->onEditorShow = [draggableNumber] { auto* editor = draggableNumber->getCurrentTextEditor();