Skip to content

Commit

Permalink
More draggable number fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 14, 2025
1 parent 5e06b19 commit 0cdc49d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
22 changes: 2 additions & 20 deletions Source/Components/DraggableNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -276,7 +264,7 @@ class DraggableNumber : public Component, public TextEditor::Listener
decimalDrag = 0;
updateFromTextEditorContents (*outgoingEditor);
}

outgoingEditor.reset();

if (deletionChecker != nullptr) {
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion Source/Components/PropertiesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down

0 comments on commit 0cdc49d

Please sign in to comment.