Skip to content

Commit 252d91f

Browse files
committed
Better layout UI
1 parent bc7ded8 commit 252d91f

File tree

1 file changed

+169
-30
lines changed

1 file changed

+169
-30
lines changed

Applications/Note/Note.cpp

Lines changed: 169 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -489,21 +489,22 @@ void Note::ColorSelector() {
489489
}
490490

491491
void Note::LayoutSelector() {
492-
UI layoutSelector("Layout Selector", Color(0xFFFF00), false);
492+
const Color color = Color(0xFFFF00);
493+
UI layoutSelector("Layout Selector", color, false);
493494

494495
int32_t x_offset = notePadConfigs[activeConfig].x_offset;
495496
int32_t y_offset = notePadConfigs[activeConfig].y_offset;
496497

497498
UIButton octaveModeBtn;
498499
octaveModeBtn.SetName("Octave Mode");
499-
octaveModeBtn.SetColorFunc([&]() -> Color { return Color(0xFFFF00).DimIfNot(notePadConfigs[activeConfig].mode == OCTAVE_LAYOUT); });
500+
octaveModeBtn.SetColorFunc([&]() -> Color { Color c = color; return c.DimIfNot(notePadConfigs[activeConfig].mode == OCTAVE_LAYOUT); });
500501
octaveModeBtn.OnPress([&]() -> void { notePadConfigs[activeConfig].mode = OCTAVE_LAYOUT; });
501502
layoutSelector.AddUIComponent(octaveModeBtn, Point(2, 0));
502503

503504
UIButton offsetModeBtn;
504505
offsetModeBtn.SetName("Offset Mode");
505-
offsetModeBtn.SetColorFunc([&]() -> Color { return Color(0xFFFF00).DimIfNot(notePadConfigs[activeConfig].mode == OFFSET_LAYOUT); });
506-
offsetModeBtn.OnPress([&]() -> void {
506+
offsetModeBtn.SetColorFunc([&]() -> Color { Color c = color; return c.DimIfNot(notePadConfigs[activeConfig].mode == OFFSET_LAYOUT); });
507+
offsetModeBtn.OnPress([&]() -> void {
507508
if(notePadConfigs[activeConfig].mode != OFFSET_LAYOUT)
508509
{
509510
notePadConfigs[activeConfig].mode = OFFSET_LAYOUT;
@@ -515,51 +516,195 @@ void Note::LayoutSelector() {
515516

516517
UIButton chromaticModeBtn;
517518
chromaticModeBtn.SetName("Chromatic Mode");
518-
chromaticModeBtn.SetColorFunc([&]() -> Color { return Color(0xFFFF00).DimIfNot(notePadConfigs[activeConfig].mode == CHROMATIC_LAYOUT); });
519+
chromaticModeBtn.SetColorFunc([&]() -> Color { Color c = color; return c.DimIfNot(notePadConfigs[activeConfig].mode == CHROMATIC_LAYOUT); });
519520
chromaticModeBtn.OnPress([&]() -> void { notePadConfigs[activeConfig].mode = CHROMATIC_LAYOUT; });
520521
layoutSelector.AddUIComponent(chromaticModeBtn, Point(4, 0));
521522

522523
UIButton pianoModeBtn;
523-
pianoModeBtn.SetName("Piano Mode");
524-
pianoModeBtn.SetColorFunc([&]() -> Color { return Color(0xFFFF00).DimIfNot(notePadConfigs[activeConfig].mode == PIANO_LAYOUT); });
524+
pianoModeBtn.SetName("Piano Keyboard");
525+
pianoModeBtn.SetColorFunc([&]() -> Color { Color c = color; return c.DimIfNot(notePadConfigs[activeConfig].mode == PIANO_LAYOUT); });
525526
pianoModeBtn.OnPress([&]() -> void { notePadConfigs[activeConfig].mode = PIANO_LAYOUT; });
526527
layoutSelector.AddUIComponent(pianoModeBtn, Point(5, 0));
527528

529+
// Octave mode
530+
TimedDisplay octTextDisplay(UINT32_MAX);
531+
octTextDisplay.SetDimension(Dimension(8, 4));
532+
octTextDisplay.SetRenderFunc([&](Point origin) -> void {
533+
// O
534+
MatrixOS::LED::SetColor(origin + Point(0, 0), color);
535+
MatrixOS::LED::SetColor(origin + Point(0, 1), color);
536+
MatrixOS::LED::SetColor(origin + Point(0, 2), color);
537+
MatrixOS::LED::SetColor(origin + Point(0, 3), color);
538+
MatrixOS::LED::SetColor(origin + Point(1, 0), color);
539+
MatrixOS::LED::SetColor(origin + Point(1, 3), color);
540+
MatrixOS::LED::SetColor(origin + Point(2, 0), color);
541+
MatrixOS::LED::SetColor(origin + Point(2, 1), color);
542+
MatrixOS::LED::SetColor(origin + Point(2, 2), color);
543+
MatrixOS::LED::SetColor(origin + Point(2, 3), color);
544+
545+
// C
546+
MatrixOS::LED::SetColor(origin + Point(3, 0), Color(0xFFFFFF));
547+
MatrixOS::LED::SetColor(origin + Point(3, 1), Color(0xFFFFFF));
548+
MatrixOS::LED::SetColor(origin + Point(3, 2), Color(0xFFFFFF));
549+
MatrixOS::LED::SetColor(origin + Point(3, 3), Color(0xFFFFFF));
550+
MatrixOS::LED::SetColor(origin + Point(4, 0), Color(0xFFFFFF));
551+
MatrixOS::LED::SetColor(origin + Point(4, 3), Color(0xFFFFFF));
552+
553+
// T
554+
MatrixOS::LED::SetColor(origin + Point(5, 0), color);
555+
MatrixOS::LED::SetColor(origin + Point(6, 0), color);
556+
MatrixOS::LED::SetColor(origin + Point(6, 1), color);
557+
MatrixOS::LED::SetColor(origin + Point(6, 2), color);
558+
MatrixOS::LED::SetColor(origin + Point(6, 3), color);
559+
MatrixOS::LED::SetColor(origin + Point(7, 0), color);
560+
});
561+
octTextDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OCTAVE_LAYOUT; });
562+
layoutSelector.AddUIComponent(octTextDisplay, Point(0, 2));
563+
564+
528565
// Offset Mode
566+
const Color xColor = Color(0x00FFFF);
567+
const Color yColor = Color(0xFF00FF);
568+
569+
UI4pxNumber yOffsetDisplay;
570+
yOffsetDisplay.SetColor(yColor);
571+
yOffsetDisplay.SetDigits(1);
572+
yOffsetDisplay.SetValuePointer((int32_t*)&y_offset);
573+
yOffsetDisplay.SetAlternativeColor(yColor);
574+
yOffsetDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
575+
layoutSelector.AddUIComponent(yOffsetDisplay, Point(2, 2));
576+
577+
UI4pxNumber xOffsetDisplay;
578+
xOffsetDisplay.SetColor(xColor);
579+
xOffsetDisplay.SetDigits(1);
580+
xOffsetDisplay.SetValuePointer((int32_t*)&x_offset);
581+
xOffsetDisplay.SetAlternativeColor(xColor);
582+
xOffsetDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
583+
layoutSelector.AddUIComponent(xOffsetDisplay, Point(5, 2));
584+
585+
TimedDisplay ofsTextDisplay(500);
586+
ofsTextDisplay.SetDimension(Dimension(6, 4));
587+
ofsTextDisplay.SetRenderFunc([&](Point origin) -> void {
588+
// Y
589+
MatrixOS::LED::SetColor(origin + Point(0, 0), yColor);
590+
MatrixOS::LED::SetColor(origin + Point(0, 1), yColor);
591+
MatrixOS::LED::SetColor(origin + Point(1, 2), yColor);
592+
MatrixOS::LED::SetColor(origin + Point(1, 3), yColor);
593+
MatrixOS::LED::SetColor(origin + Point(2, 0), yColor);
594+
MatrixOS::LED::SetColor(origin + Point(2, 1), yColor);
595+
596+
// X
597+
MatrixOS::LED::SetColor(origin + Point(3, 0), xColor);
598+
MatrixOS::LED::SetColor(origin + Point(3, 3), xColor);
599+
MatrixOS::LED::SetColor(origin + Point(4, 1), xColor);
600+
MatrixOS::LED::SetColor(origin + Point(4, 2), xColor);
601+
MatrixOS::LED::SetColor(origin + Point(5, 0), xColor);
602+
MatrixOS::LED::SetColor(origin + Point(5, 3), xColor);
603+
});
604+
ofsTextDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
605+
layoutSelector.AddUIComponent(ofsTextDisplay, Point(2, 2));
606+
529607
UISelector yOffsetInput;
530608
yOffsetInput.SetDimension(Dimension(1, 8));
531609
yOffsetInput.SetName("Y Offset");
532-
yOffsetInput.SetColor(Color(0xFF00FF));
610+
yOffsetInput.SetColor(yColor);
533611
yOffsetInput.SetValuePointer((uint16_t*)&y_offset);
534612
yOffsetInput.SetLitMode(UISelectorLitMode::LIT_LESS_EQUAL_THAN);
535613
yOffsetInput.SetDirection(UISelectorDirection::UP_THEN_RIGHT);
536614
yOffsetInput.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
615+
yOffsetInput.OnChange([&](uint16_t val) -> void {
616+
notePadConfigs[activeConfig].y_offset = val;
617+
ofsTextDisplay.Disable();
618+
});
537619
layoutSelector.AddUIComponent(yOffsetInput, Point(0, 0));
538620

539-
UI4pxNumber yOffsetDisplay;
540-
yOffsetDisplay.SetColor(Color(0xFF00FF));
541-
yOffsetDisplay.SetDigits(1);
542-
yOffsetDisplay.SetValuePointer((int32_t*)&y_offset);
543-
yOffsetDisplay.SetAlternativeColor(Color(0xFF00FF));
544-
yOffsetDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
545-
layoutSelector.AddUIComponent(yOffsetDisplay, Point(2, 2));
546-
547621
UISelector xOffsetInput;
548622
xOffsetInput.SetDimension(Dimension(8, 1));
549623
xOffsetInput.SetName("X Offset");
550-
xOffsetInput.SetColor(Color(0x00FFFF));
624+
xOffsetInput.SetColor(xColor);
551625
xOffsetInput.SetValuePointer((uint16_t*)&x_offset);
552626
xOffsetInput.SetLitMode(UISelectorLitMode::LIT_LESS_EQUAL_THAN);
553627
xOffsetInput.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
628+
xOffsetInput.OnChange([&](uint16_t val) -> void {
629+
notePadConfigs[activeConfig].x_offset = val;
630+
ofsTextDisplay.Disable();
631+
});
554632
layoutSelector.AddUIComponent(xOffsetInput, Point(0, 7));
555633

556-
UI4pxNumber xOffsetDisplay;
557-
xOffsetDisplay.SetColor(Color(0x00FFFF));
558-
xOffsetDisplay.SetDigits(1);
559-
xOffsetDisplay.SetValuePointer((int32_t*)&x_offset);
560-
xOffsetDisplay.SetAlternativeColor(Color(0x00FFFF));
561-
xOffsetDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
562-
layoutSelector.AddUIComponent(xOffsetDisplay, Point(5, 2));
634+
// Chromatic
635+
TimedDisplay chmTextDisplay(UINT32_MAX);
636+
chmTextDisplay.SetDimension(Dimension(8, 4));
637+
chmTextDisplay.SetRenderFunc([&](Point origin) -> void {
638+
// C
639+
MatrixOS::LED::SetColor(origin + Point(0, 0), color);
640+
MatrixOS::LED::SetColor(origin + Point(0, 1), color);
641+
MatrixOS::LED::SetColor(origin + Point(0, 2), color);
642+
MatrixOS::LED::SetColor(origin + Point(0, 3), color);
643+
MatrixOS::LED::SetColor(origin + Point(1, 0), color);
644+
MatrixOS::LED::SetColor(origin + Point(1, 3), color);
645+
646+
// H
647+
MatrixOS::LED::SetColor(origin + Point(2, 0), Color(0xFFFFFF));
648+
MatrixOS::LED::SetColor(origin + Point(2, 1), Color(0xFFFFFF));
649+
MatrixOS::LED::SetColor(origin + Point(2, 2), Color(0xFFFFFF));
650+
MatrixOS::LED::SetColor(origin + Point(2, 3), Color(0xFFFFFF));
651+
MatrixOS::LED::SetColor(origin + Point(3, 2), Color(0xFFFFFF));
652+
MatrixOS::LED::SetColor(origin + Point(4, 0), Color(0xFFFFFF));
653+
MatrixOS::LED::SetColor(origin + Point(4, 1), Color(0xFFFFFF));
654+
MatrixOS::LED::SetColor(origin + Point(4, 2), Color(0xFFFFFF));
655+
MatrixOS::LED::SetColor(origin + Point(4, 3), Color(0xFFFFFF));
656+
657+
// M
658+
MatrixOS::LED::SetColor(origin + Point(5, 0), color);
659+
MatrixOS::LED::SetColor(origin + Point(5, 1), color);
660+
MatrixOS::LED::SetColor(origin + Point(5, 2), color);
661+
MatrixOS::LED::SetColor(origin + Point(5, 3), color);
662+
MatrixOS::LED::SetColor(origin + Point(6, 0), color);
663+
MatrixOS::LED::SetColor(origin + Point(6, 1), color);
664+
MatrixOS::LED::SetColor(origin + Point(7, 0), color);
665+
MatrixOS::LED::SetColor(origin + Point(7, 1), color);
666+
MatrixOS::LED::SetColor(origin + Point(7, 2), color);
667+
MatrixOS::LED::SetColor(origin + Point(7, 3), color);
668+
});
669+
chmTextDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == CHROMATIC_LAYOUT; });
670+
layoutSelector.AddUIComponent(chmTextDisplay, Point(0, 2));
671+
672+
// Piano
673+
TimedDisplay pioTextDisplay(UINT32_MAX);
674+
pioTextDisplay.SetDimension(Dimension(8, 4));
675+
pioTextDisplay.SetRenderFunc([&](Point origin) -> void {
676+
// P
677+
MatrixOS::LED::SetColor(origin + Point(0, 0), color);
678+
MatrixOS::LED::SetColor(origin + Point(0, 1), color);
679+
MatrixOS::LED::SetColor(origin + Point(0, 2), color);
680+
MatrixOS::LED::SetColor(origin + Point(0, 3), color);
681+
MatrixOS::LED::SetColor(origin + Point(1, 0), color);
682+
MatrixOS::LED::SetColor(origin + Point(1, 2), color);
683+
MatrixOS::LED::SetColor(origin + Point(2, 0), color);
684+
MatrixOS::LED::SetColor(origin + Point(2, 1), color);
685+
MatrixOS::LED::SetColor(origin + Point(2, 2), color);
686+
687+
// I
688+
MatrixOS::LED::SetColor(origin + Point(4, 0), Color(0xFFFFFF));
689+
MatrixOS::LED::SetColor(origin + Point(4, 1), Color(0xFFFFFF));
690+
MatrixOS::LED::SetColor(origin + Point(4, 2), Color(0xFFFFFF));
691+
MatrixOS::LED::SetColor(origin + Point(4, 3), Color(0xFFFFFF));
692+
693+
694+
// O
695+
MatrixOS::LED::SetColor(origin + Point(5, 0), color);
696+
MatrixOS::LED::SetColor(origin + Point(5, 1), color);
697+
MatrixOS::LED::SetColor(origin + Point(5, 2), color);
698+
MatrixOS::LED::SetColor(origin + Point(5, 3), color);
699+
MatrixOS::LED::SetColor(origin + Point(6, 0), color);
700+
MatrixOS::LED::SetColor(origin + Point(6, 3), color);
701+
MatrixOS::LED::SetColor(origin + Point(7, 0), color);
702+
MatrixOS::LED::SetColor(origin + Point(7, 1), color);
703+
MatrixOS::LED::SetColor(origin + Point(7, 2), color);
704+
MatrixOS::LED::SetColor(origin + Point(7, 3), color);
705+
});
706+
pioTextDisplay.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == PIANO_LAYOUT; });
707+
layoutSelector.AddUIComponent(pioTextDisplay, Point(0, 2));
563708

564709
// Show Off Scale Notes Toggle (only for Octave and Offset modes)
565710
UIButton inKeyNoteOnlyToggle;
@@ -570,12 +715,6 @@ void Note::LayoutSelector() {
570715
layoutSelector.AddUIComponent(inKeyNoteOnlyToggle, Point(0, 7));
571716

572717
layoutSelector.Start();
573-
574-
if(notePadConfigs[activeConfig].mode == OFFSET_LAYOUT)
575-
{
576-
notePadConfigs[activeConfig].x_offset = x_offset;
577-
notePadConfigs[activeConfig].y_offset = y_offset;
578-
}
579718
}
580719

581720
void Note::ChannelSelector() {

0 commit comments

Comments
 (0)