Skip to content

Commit bdd3dd9

Browse files
committed
Refactor locking/unlocking Widget Settings dropdowns when TopNav UIs are selected
1 parent 43f91d6 commit bdd3dd9

2 files changed

Lines changed: 18 additions & 47 deletions

File tree

OpenBCI_GUI/TopNav.pde

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -696,20 +696,8 @@ class LayoutSelector {
696696

697697
void toggleVisibility() {
698698
isVisible = !isVisible;
699-
if (isVisible) {
700-
//the very convoluted way of locking all controllers of a single controlP5 instance...
701-
for (int i = 0; i < widgetManager.widgets.size(); i++) {
702-
for (int j = 0; j < widgetManager.widgets.get(i).cp5_widget.getAll().size(); j++) {
703-
widgetManager.widgets.get(i).cp5_widget.getController(widgetManager.widgets.get(i).cp5_widget.getAll().get(j).getAddress()).lock();
704-
}
705-
}
706-
} else {
707-
//the very convoluted way of unlocking all controllers of a single controlP5 instance...
708-
for (int i = 0; i < widgetManager.widgets.size(); i++) {
709-
for (int j = 0; j < widgetManager.widgets.get(i).cp5_widget.getAll().size(); j++) {
710-
widgetManager.widgets.get(i).cp5_widget.getController(widgetManager.widgets.get(i).cp5_widget.getAll().get(j).getAddress()).unlock();
711-
}
712-
}
699+
if (widgetManager != null) {
700+
widgetManager.lockCp5ObjectsInAllWidgets(isVisible);
713701
}
714702
}
715703

@@ -880,23 +868,9 @@ class ConfigSelector {
880868

881869
void toggleVisibility() {
882870
isVisible = !isVisible;
883-
if (systemMode >= SYSTEMMODE_POSTINIT) {
884-
if (isVisible) {
885-
//the very convoluted way of locking all controllers of a single controlP5 instance...
886-
for (int i = 0; i < widgetManager.widgets.size(); i++) {
887-
for (int j = 0; j < widgetManager.widgets.get(i).cp5_widget.getAll().size(); j++) {
888-
widgetManager.widgets.get(i).cp5_widget.getController(widgetManager.widgets.get(i).cp5_widget.getAll().get(j).getAddress()).lock();
889-
}
890-
}
891-
clearAllSettingsPressed = false;
892-
} else {
893-
//the very convoluted way of unlocking all controllers of a single controlP5 instance...
894-
for (int i = 0; i < widgetManager.widgets.size(); i++) {
895-
for (int j = 0; j < widgetManager.widgets.get(i).cp5_widget.getAll().size(); j++) {
896-
widgetManager.widgets.get(i).cp5_widget.getController(widgetManager.widgets.get(i).cp5_widget.getAll().get(j).getAddress()).unlock();
897-
}
898-
}
899-
}
871+
if (widgetManager != null) {
872+
widgetManager.lockCp5ObjectsInAllWidgets(isVisible);
873+
clearAllSettingsPressed = !isVisible;
900874
}
901875

902876
//When closed by any means and confirmation buttons are open...
@@ -1188,22 +1162,8 @@ class TutorialSelector {
11881162

11891163
void toggleVisibility() {
11901164
isVisible = !isVisible;
1191-
if (systemMode >= SYSTEMMODE_POSTINIT) {
1192-
if (isVisible) {
1193-
//the very convoluted way of locking all controllers of a single controlP5 instance...
1194-
for (int i = 0; i < widgetManager.widgets.size(); i++) {
1195-
for (int j = 0; j < widgetManager.widgets.get(i).cp5_widget.getAll().size(); j++) {
1196-
widgetManager.widgets.get(i).cp5_widget.getController(widgetManager.widgets.get(i).cp5_widget.getAll().get(j).getAddress()).lock();
1197-
}
1198-
}
1199-
} else {
1200-
//the very convoluted way of unlocking all controllers of a single controlP5 instance...
1201-
for (int i = 0; i < widgetManager.widgets.size(); i++) {
1202-
for (int j = 0; j < widgetManager.widgets.get(i).cp5_widget.getAll().size(); j++) {
1203-
widgetManager.widgets.get(i).cp5_widget.getController(widgetManager.widgets.get(i).cp5_widget.getAll().get(j).getAddress()).unlock();
1204-
}
1205-
}
1206-
}
1165+
if (widgetManager != null) {
1166+
widgetManager.lockCp5ObjectsInAllWidgets(isVisible);
12071167
}
12081168
}
12091169

OpenBCI_GUI/WidgetManager.pde

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ class WidgetManager{
347347

348348
println("Widget Manager: All widgets set to null.");
349349
}
350+
351+
// Useful in places like TopNav which overlap widget dropdowns
352+
public void lockCp5ObjectsInAllWidgets(boolean lock) {
353+
for (int i = 0; i < widgets.size(); i++) {
354+
for (int j = 0; j < widgets.get(i).cp5_widget.getAll().size(); j++) {
355+
ControlP5 cp5Instance = widgets.get(i).cp5_widget;
356+
String widgetAddress = cp5Instance.getAll().get(j).getAddress();
357+
cp5Instance.getController(widgetAddress).setLock(lock);
358+
}
359+
}
360+
}
350361
};
351362

352363
//the Layout class is an orgnanizational tool ... a layout consists of a combination of containers ... refer to Container.pde

0 commit comments

Comments
 (0)