Skip to content

Commit 4441834

Browse files
committed
QuantumKnob: allow value & unit to use newline separator
Signed-off-by: falkTX <[email protected]>
1 parent 9fd3e6a commit 4441834

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

opengl/Quantum.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@ bool QuantumDualSidedSwitch::onMotion(const MotionEvent& ev)
590590

591591
// --------------------------------------------------------------------------------------------------------------------
592592

593-
template<bool small>
594-
AbstractQuantumKnob<small>::AbstractQuantumKnob(NanoTopLevelWidget* const parent, const QuantumTheme& t)
593+
template<bool small, bool unitInNewline>
594+
AbstractQuantumKnob<small, unitInNewline>::AbstractQuantumKnob(NanoTopLevelWidget* const parent, const QuantumTheme& t)
595595
: NanoSubWidget(parent),
596596
KnobEventHandler(this),
597597
theme(t)
@@ -601,8 +601,8 @@ AbstractQuantumKnob<small>::AbstractQuantumKnob(NanoTopLevelWidget* const parent
601601
setSize(QuantumMetrics(t).knob);
602602
}
603603

604-
template<bool small>
605-
AbstractQuantumKnob<small>::AbstractQuantumKnob(NanoSubWidget* const parent, const QuantumTheme& t)
604+
template<bool small, bool unitInNewline>
605+
AbstractQuantumKnob<small, unitInNewline>::AbstractQuantumKnob(NanoSubWidget* const parent, const QuantumTheme& t)
606606
: NanoSubWidget(parent),
607607
KnobEventHandler(this),
608608
theme(t)
@@ -612,39 +612,39 @@ AbstractQuantumKnob<small>::AbstractQuantumKnob(NanoSubWidget* const parent, con
612612
setSize(QuantumMetrics(t).knob);
613613
}
614614

615-
template<bool small>
616-
AbstractQuantumKnob<small>::~AbstractQuantumKnob()
615+
template<bool small, bool unitInNewline>
616+
AbstractQuantumKnob<small, unitInNewline>::~AbstractQuantumKnob()
617617
{
618618
std::free(label);
619619
std::free(unitLabel);
620620
std::free(sidelabels[0]);
621621
std::free(sidelabels[1]);
622622
}
623623

624-
template<bool small>
625-
void AbstractQuantumKnob<small>::setLabel(const char* const label2)
624+
template<bool small, bool unitInNewline>
625+
void AbstractQuantumKnob<small, unitInNewline>::setLabel(const char* const label2)
626626
{
627627
std::free(label);
628628
label = label2 != nullptr && label2[0] != '\0' ? strdup(label2) : nullptr;
629629
repaint();
630630
}
631631

632-
template<bool small>
633-
void AbstractQuantumKnob<small>::setOrientation(const Orientation orientation2)
632+
template<bool small, bool unitInNewline>
633+
void AbstractQuantumKnob<small, unitInNewline>::setOrientation(const Orientation orientation2)
634634
{
635635
orientation = orientation2;
636636
repaint();
637637
}
638638

639-
template<bool small>
640-
void AbstractQuantumKnob<small>::setRingColor(const Color color)
639+
template<bool small, bool unitInNewline>
640+
void AbstractQuantumKnob<small, unitInNewline>::setRingColor(const Color color)
641641
{
642642
ringColor = color;
643643
repaint();
644644
}
645645

646-
template<bool small>
647-
void AbstractQuantumKnob<small>::setSideLabels(const char* const label1, const char* const label2)
646+
template<bool small, bool unitInNewline>
647+
void AbstractQuantumKnob<small, unitInNewline>::setSideLabels(const char* const label1, const char* const label2)
648648
{
649649
std::free(sidelabels[0]);
650650
std::free(sidelabels[1]);
@@ -655,29 +655,29 @@ void AbstractQuantumKnob<small>::setSideLabels(const char* const label1, const c
655655
repaint();
656656
}
657657

658-
template<bool small>
659-
void AbstractQuantumKnob<small>::setSideLabelsFontSize(const uint fontSize)
658+
template<bool small, bool unitInNewline>
659+
void AbstractQuantumKnob<small, unitInNewline>::setSideLabelsFontSize(const uint fontSize)
660660
{
661661
sidelabelsFontSize = fontSize;
662662
repaint();
663663
}
664664

665-
template<bool small>
666-
void AbstractQuantumKnob<small>::setUnitLabel(const char* const unitLabel2)
665+
template<bool small, bool unitInNewline>
666+
void AbstractQuantumKnob<small, unitInNewline>::setUnitLabel(const char* const unitLabel2)
667667
{
668668
std::free(unitLabel);
669669
unitLabel = unitLabel2 != nullptr && unitLabel2[0] != '\0' ? strdup(unitLabel2) : nullptr;
670670
}
671671

672-
template<bool small>
673-
void AbstractQuantumKnob<small>::setValueFontSize(const uint fontSize)
672+
template<bool small, bool unitInNewline>
673+
void AbstractQuantumKnob<small, unitInNewline>::setValueFontSize(const uint fontSize)
674674
{
675675
valueFontSize = fontSize;
676676
repaint();
677677
}
678678

679-
template<bool small>
680-
void AbstractQuantumKnob<small>::onNanoDisplay()
679+
template<bool small, bool unitInNewline>
680+
void AbstractQuantumKnob<small, unitInNewline>::onNanoDisplay()
681681
{
682682
// const double scaleFactor = getScaleFactor();
683683
const int w = getWidth();
@@ -860,7 +860,7 @@ void AbstractQuantumKnob<small>::onNanoDisplay()
860860
const int value = d_roundToInt(getValue());
861861

862862
if (unitLabel != nullptr)
863-
std::snprintf(valuestr, sizeof(valuestr)-1, "%d %s", value, unitLabel);
863+
std::snprintf(valuestr, sizeof(valuestr)-1, "%d%c%s", value, unitInNewline ? '\n' : ' ', unitLabel);
864864
else
865865
std::snprintf(valuestr, sizeof(valuestr)-1, "%d", value);
866866
}
@@ -878,38 +878,42 @@ void AbstractQuantumKnob<small>::onNanoDisplay()
878878
format = "%.0f%s%s";
879879

880880
if (unitLabel != nullptr)
881-
std::snprintf(valuestr, sizeof(valuestr)-1, format, value, " ", unitLabel);
881+
std::snprintf(valuestr, sizeof(valuestr)-1, format, value, unitInNewline ? "\n" : " ", unitLabel);
882882
else
883883
std::snprintf(valuestr, sizeof(valuestr)-1, format, value, "", "");
884884
}
885885

886886
fillColor(enabled ? theme.textLightColor : theme.textDarkColor);
887887
fontSize(valueFontSize);
888888
textAlign(ALIGN_CENTER|ALIGN_MIDDLE);
889-
text(knobCenterX, knobCenterY, valuestr, nullptr);
889+
if (unitInNewline)
890+
textBox(knobStartX, knobCenterY - knobStartY, knobSize, valuestr, nullptr);
891+
else
892+
text(knobCenterX, knobCenterY, valuestr, nullptr);
890893
}
891894
}
892895

893-
template<bool small>
894-
bool AbstractQuantumKnob<small>::onMouse(const MouseEvent& ev)
896+
template<bool small, bool unitInNewline>
897+
bool AbstractQuantumKnob<small, unitInNewline>::onMouse(const MouseEvent& ev)
895898
{
896899
return mouseEvent(ev, getTopLevelWidget()->getScaleFactor());
897900
}
898901

899-
template<bool small>
900-
bool AbstractQuantumKnob<small>::onMotion(const MotionEvent& ev)
902+
template<bool small, bool unitInNewline>
903+
bool AbstractQuantumKnob<small, unitInNewline>::onMotion(const MotionEvent& ev)
901904
{
902905
return motionEvent(ev, getTopLevelWidget()->getScaleFactor());
903906
}
904907

905-
template<bool small>
906-
bool AbstractQuantumKnob<small>::onScroll(const ScrollEvent& ev)
908+
template<bool small, bool unitInNewline>
909+
bool AbstractQuantumKnob<small, unitInNewline>::onScroll(const ScrollEvent& ev)
907910
{
908911
return scrollEvent(ev);
909912
}
910913

911-
template class AbstractQuantumKnob<false>;
912-
template class AbstractQuantumKnob<true>;
914+
template class AbstractQuantumKnob<false, false>;
915+
template class AbstractQuantumKnob<true, false>;
916+
template class AbstractQuantumKnob<true, true>;
913917

914918
// --------------------------------------------------------------------------------------------------------------------
915919

opengl/Quantum.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class QuantumDualSidedSwitch : public NanoSubWidget,
358358

359359
// --------------------------------------------------------------------------------------------------------------------
360360

361-
template<bool small>
361+
template<bool small, bool unitInNewline>
362362
class AbstractQuantumKnob : public NanoSubWidget,
363363
public KnobEventHandler
364364
{
@@ -416,8 +416,9 @@ class AbstractQuantumKnob : public NanoSubWidget,
416416
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AbstractQuantumKnob)
417417
};
418418

419-
typedef AbstractQuantumKnob<false> QuantumKnob;
420-
typedef AbstractQuantumKnob<true> QuantumSmallKnob;
419+
typedef AbstractQuantumKnob<false, false> QuantumKnob;
420+
typedef AbstractQuantumKnob<true, false> QuantumSmallKnob;
421+
typedef AbstractQuantumKnob<true, true> QuantumSmallKnobWithUnitInNewline;
421422

422423
// --------------------------------------------------------------------------------------------------------------------
423424

0 commit comments

Comments
 (0)