From ab48784a808a1b8d087ed207a3c448b49d51acd3 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Fri, 14 Feb 2025 01:01:20 +0100 Subject: [PATCH] Fix more issues --- Source/Components/DraggableNumber.h | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Source/Components/DraggableNumber.h b/Source/Components/DraggableNumber.h index aaaf76810..af62244ad 100644 --- a/Source/Components/DraggableNumber.h +++ b/Source/Components/DraggableNumber.h @@ -48,9 +48,9 @@ class DraggableNumber : public Component, public TextEditor::Listener std::unique_ptr nvgCtx; public: - std::function onTextChange; - std::function onEditorShow; - std::function onEditorHide; + std::function onTextChange = [](){}; + std::function onEditorShow = [](){}; + std::function onEditorHide = [](){}; std::function onValueChange = [](double) { }; std::function onReturnKey = [](double) { }; @@ -79,7 +79,7 @@ class DraggableNumber : public Component, public TextEditor::Listener textColour = findColour(Label::textColourId); } - void editorShown(Label* l, TextEditor& editor) + void editorShown(TextEditor& editor) { onInteraction(true); dragStart(); @@ -222,21 +222,24 @@ class DraggableNumber : public Component, public TextEditor::Listener copyColourIfSpecified (*this, *editor, Label::outlineWhenEditingColourId, TextEditor::focusedOutlineColourId); editor->setSize (10, 10); + editor->setBorder(border); + editor->setFont(font); addAndMakeVisible (editor.get()); editor->setText (currentValue, false); - //editor->setKeyboardType (keyboardType); editor->addListener (this); editor->grabKeyboardFocus(); if (editor == nullptr) // may be deleted by a callback return; + editor->setColour(TextEditor::backgroundColourId, Colours::transparentBlack); editor->setHighlightedRegion (Range (0, currentValue.length())); resized(); repaint(); - //editorShown (editor.get()); + editorShown(*editor); + onEditorShow(); enterModalState (false); editor->grabKeyboardFocus(); @@ -271,18 +274,17 @@ class DraggableNumber : public Component, public TextEditor::Listener std::unique_ptr outgoingEditor; std::swap (outgoingEditor, editor); - const bool changed = (! discardCurrentEditorContents) - && updateFromTextEditorContents (*outgoingEditor); + if(!discardCurrentEditorContents) { + updateFromTextEditorContents (*outgoingEditor); + } + outgoingEditor.reset(); - if (deletionChecker != nullptr) + if (deletionChecker != nullptr) { repaint(); - - //if (changed) - // textWasEdited(); - - if (deletionChecker != nullptr) - exitModalState (0); + onEditorHide(); + exitModalState(0); + } } } @@ -767,6 +769,7 @@ class DraggableNumber : public Component, public TextEditor::Listener double const newValue = parseExpression(text); setValue(newValue, dontSendNotification); onReturnKey(newValue); + hideEditor(false); } };