Skip to content

Commit

Permalink
Fix more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 14, 2025
1 parent 761c608 commit ab48784
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Source/Components/DraggableNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class DraggableNumber : public Component, public TextEditor::Listener
std::unique_ptr<NanoVGGraphicsContext> nvgCtx;

public:
std::function<void()> onTextChange;
std::function<void()> onEditorShow;
std::function<void()> onEditorHide;
std::function<void()> onTextChange = [](){};
std::function<void()> onEditorShow = [](){};
std::function<void()> onEditorHide = [](){};

std::function<void(double)> onValueChange = [](double) { };
std::function<void(double)> onReturnKey = [](double) { };
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<int> (0, currentValue.length()));

resized();
repaint();

//editorShown (editor.get());
editorShown(*editor);
onEditorShow();

enterModalState (false);
editor->grabKeyboardFocus();
Expand Down Expand Up @@ -271,18 +274,17 @@ class DraggableNumber : public Component, public TextEditor::Listener
std::unique_ptr<TextEditor> 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);
}
}
}

Expand Down Expand Up @@ -767,6 +769,7 @@ class DraggableNumber : public Component, public TextEditor::Listener
double const newValue = parseExpression(text);
setValue(newValue, dontSendNotification);
onReturnKey(newValue);
hideEditor(false);
}
};

Expand Down

0 comments on commit ab48784

Please sign in to comment.