Skip to content

Commit b3a8f33

Browse files
committed
Make nbx/floatbox return key behaviour like Pd
1 parent 3a9dec4 commit b3a8f33

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Source/Components/DraggableNumber.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class DraggableNumber : public Label
4141

4242
public:
4343
std::function<void(double)> onValueChange = [](double) { };
44+
std::function<void(double)> onReturnKey = [](double) { };
4445
std::function<void()> dragStart = []() { };
4546
std::function<void()> dragEnd = []() { };
4647

@@ -587,7 +588,7 @@ class DraggableNumber : public Label
587588

588589
return 0.0f;
589590
}
590-
591+
591592
void textEditorFocusLost (TextEditor& editor) override
592593
{
593594
textEditorReturnKeyPressed(editor);
@@ -598,6 +599,7 @@ class DraggableNumber : public Label
598599
auto text = editor.getText();
599600
double newValue = parseExpression(text);
600601
setValue(newValue);
602+
onReturnKey(newValue);
601603
}
602604
};
603605

Source/Objects/FloatAtomObject.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class FloatAtomObject final : public ObjectBase {
6363
object->updateBounds();
6464
}
6565
};
66+
67+
input.onReturnKey = [this](double newValue)
68+
{
69+
sendFloatValue(newValue);
70+
};
6671

6772
input.dragEnd = [this]() {
6873
stopEdition();
@@ -112,7 +117,6 @@ class FloatAtomObject final : public ObjectBase {
112117
if (key.getKeyCode() == KeyPress::returnKey) {
113118
auto inputValue = input.getText().getFloatValue();
114119
sendFloatValue(inputValue);
115-
cnv->grabKeyboardFocus();
116120
return true;
117121
}
118122

Source/Objects/NumberObject.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class NumberObject final : public ObjectBase {
5252
editor->setColour(TextEditor::focusedOutlineColourId, Colours::transparentBlack);
5353
editor->setBorder({ 0, 8, 4, 1 });
5454
};
55-
55+
5656
input.onInteraction = [this](bool isFocused) {
5757
if (isFocused)
5858
input.setColour(Label::textColourId, convertColour(backgroundCol).contrasting());
@@ -77,6 +77,11 @@ class NumberObject final : public ObjectBase {
7777
input.onValueChange = [this](float newValue) {
7878
sendFloatValue(newValue);
7979
};
80+
81+
input.onReturnKey = [this](double newValue)
82+
{
83+
sendFloatValue(newValue);
84+
};
8085

8186
input.dragEnd = [this]() {
8287
stopEdition();
@@ -206,7 +211,6 @@ class NumberObject final : public ObjectBase {
206211
auto inputValue = input.getText().getFloatValue();
207212
preFocusValue = value;
208213
sendFloatValue(inputValue);
209-
cnv->grabKeyboardFocus();
210214
return true;
211215
}
212216

0 commit comments

Comments
 (0)