From a4f3542217f088c841ca0c77858d63269d9efd1c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 6 Aug 2021 20:13:45 -0400 Subject: [PATCH] Update blendish. Add TextField::prevField/nextField. --- Makefile | 3 ++- dep/oui-blendish | 2 +- include/ui/TextField.hpp | 5 +++++ src/app/MenuBar.cpp | 32 ++++++-------------------------- src/ui/Label.cpp | 2 +- src/ui/MenuItem.cpp | 3 --- src/ui/TextField.cpp | 12 ++++++++++++ 7 files changed, 27 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index db224cf1..cc59092d 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ SED := perl -pi -e SOURCES += dep/nanovg/src/nanovg.c SOURCES += dep/osdialog/osdialog.c +SOURCES += dep/oui-blendish/blendish.c SOURCES += dep/pffft/pffft.c dep/pffft/fftpack.c SOURCES += $(wildcard src/*.c src/*/*.c) SOURCES += $(wildcard src/*.cpp src/*/*.cpp) @@ -130,7 +131,7 @@ valgrind: $(STANDALONE_TARGET) valgrind --suppressions=valgrind.supp ./$< -d clean: - rm -rfv $(TARGET) $(STANDALONE_TARGET) libRack.dll.a Rack.res build dist *.d + rm -rfv build dist *.a Rack.res *.d $(TARGET) $(STANDALONE_TARGET) # For Windows resources diff --git a/dep/oui-blendish b/dep/oui-blendish index 910847b5..008cceaa 160000 --- a/dep/oui-blendish +++ b/dep/oui-blendish @@ -1 +1 @@ -Subproject commit 910847b53396fd394e5fa25c3430caea02a3fe70 +Subproject commit 008cceaa10d18661129fb94b2b678c1827c04cd3 diff --git a/include/ui/TextField.hpp b/include/ui/TextField.hpp index 376d6e15..b9b40680 100644 --- a/include/ui/TextField.hpp +++ b/include/ui/TextField.hpp @@ -19,6 +19,11 @@ struct TextField : widget::OpaqueWidget { */ int selection = 0; + /** For Tab and Shift-Tab focusing. + */ + Widget* prevField = NULL; + Widget* nextField = NULL; + TextField(); void draw(const DrawArgs& args) override; void onDragHover(const DragHoverEvent& e) override; diff --git a/src/app/MenuBar.cpp b/src/app/MenuBar.cpp index ea9e2bff..b4e11b6c 100644 --- a/src/app/MenuBar.cpp +++ b/src/app/MenuBar.cpp @@ -608,31 +608,10 @@ struct EngineButton : MenuButton { static bool isLoggingIn = false; -struct AccountEmailField : ui::TextField { - ui::TextField* passwordField; - - void onSelectKey(const SelectKeyEvent& e) override { - if (e.action == GLFW_PRESS && e.key == GLFW_KEY_TAB) { - APP->event->setSelected(passwordField); - e.consume(this); - } - - if (!e.getTarget()) - ui::TextField::onSelectKey(e); - } -}; - -struct AccountPasswordField : ui::PasswordField { +struct AccountPasswordField : ui::TextField { ui::MenuItem* logInItem; - - void onSelectKey(const SelectKeyEvent& e) override { - if (e.action == GLFW_PRESS && (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER)) { - logInItem->doAction(); - e.consume(this); - } - - if (!e.getTarget()) - ui::PasswordField::onSelectKey(e); + void onAction(const ActionEvent& e) override { + logInItem->doAction(); } }; @@ -802,7 +781,7 @@ struct LibraryMenu : ui::Menu { registerItem->url = "https://vcvrack.com/login"; addChild(registerItem); - AccountEmailField* emailField = new AccountEmailField; + ui::TextField* emailField = new ui::TextField; emailField->placeholder = "Email"; emailField->box.size.x = 240.0; addChild(emailField); @@ -810,7 +789,8 @@ struct LibraryMenu : ui::Menu { AccountPasswordField* passwordField = new AccountPasswordField; passwordField->placeholder = "Password"; passwordField->box.size.x = 240.0; - emailField->passwordField = passwordField; + passwordField->nextField = emailField; + emailField->nextField = passwordField; addChild(passwordField); LogInItem* logInItem = new LogInItem; diff --git a/src/ui/Label.cpp b/src/ui/Label.cpp index 7b6e316d..db6cc055 100644 --- a/src/ui/Label.cpp +++ b/src/ui/Label.cpp @@ -7,7 +7,7 @@ namespace ui { Label::Label() { box.size.y = BND_WIDGET_HEIGHT; - fontSize = 13; + fontSize = BND_LABEL_FONT_SIZE; lineHeight = 1.2; color = bndGetTheme()->regularTheme.textColor; } diff --git a/src/ui/MenuItem.cpp b/src/ui/MenuItem.cpp index 36efe52c..16e3ec5c 100644 --- a/src/ui/MenuItem.cpp +++ b/src/ui/MenuItem.cpp @@ -6,9 +6,6 @@ namespace rack { namespace ui { -#define BND_LABEL_FONT_SIZE 13 - - void MenuItem::draw(const DrawArgs& args) { BNDwidgetState state = BND_DEFAULT; diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index c46eeb10..76dd5179 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -220,6 +220,18 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { } e.consume(this); } + // Tab + if (e.key == GLFW_KEY_TAB && (e.mods & RACK_MOD_MASK) == 0) { + if (nextField) + APP->event->setSelected(nextField); + e.consume(this); + } + // Shift-Tab + if (e.key == GLFW_KEY_TAB && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (prevField) + APP->event->setSelected(prevField); + e.consume(this); + } // Consume all printable keys if (e.keyName != "") { e.consume(this);