Skip to content

Commit

Permalink
Make nbx/floatbox return key behaviour like Pd
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Nov 28, 2024
1 parent 3a9dec4 commit b3a8f33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Source/Components/DraggableNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DraggableNumber : public Label

public:
std::function<void(double)> onValueChange = [](double) { };
std::function<void(double)> onReturnKey = [](double) { };
std::function<void()> dragStart = []() { };
std::function<void()> dragEnd = []() { };

Expand Down Expand Up @@ -587,7 +588,7 @@ class DraggableNumber : public Label

return 0.0f;
}

void textEditorFocusLost (TextEditor& editor) override
{
textEditorReturnKeyPressed(editor);
Expand All @@ -598,6 +599,7 @@ class DraggableNumber : public Label
auto text = editor.getText();
double newValue = parseExpression(text);
setValue(newValue);
onReturnKey(newValue);
}
};

Expand Down
6 changes: 5 additions & 1 deletion Source/Objects/FloatAtomObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class FloatAtomObject final : public ObjectBase {
object->updateBounds();
}
};

input.onReturnKey = [this](double newValue)
{
sendFloatValue(newValue);
};

input.dragEnd = [this]() {
stopEdition();
Expand Down Expand Up @@ -112,7 +117,6 @@ class FloatAtomObject final : public ObjectBase {
if (key.getKeyCode() == KeyPress::returnKey) {
auto inputValue = input.getText().getFloatValue();
sendFloatValue(inputValue);
cnv->grabKeyboardFocus();
return true;
}

Expand Down
8 changes: 6 additions & 2 deletions Source/Objects/NumberObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NumberObject final : public ObjectBase {
editor->setColour(TextEditor::focusedOutlineColourId, Colours::transparentBlack);
editor->setBorder({ 0, 8, 4, 1 });
};

input.onInteraction = [this](bool isFocused) {
if (isFocused)
input.setColour(Label::textColourId, convertColour(backgroundCol).contrasting());
Expand All @@ -77,6 +77,11 @@ class NumberObject final : public ObjectBase {
input.onValueChange = [this](float newValue) {
sendFloatValue(newValue);
};

input.onReturnKey = [this](double newValue)
{
sendFloatValue(newValue);
};

input.dragEnd = [this]() {
stopEdition();
Expand Down Expand Up @@ -206,7 +211,6 @@ class NumberObject final : public ObjectBase {
auto inputValue = input.getText().getFloatValue();
preFocusValue = value;
sendFloatValue(inputValue);
cnv->grabKeyboardFocus();
return true;
}

Expand Down

0 comments on commit b3a8f33

Please sign in to comment.