@@ -353,6 +353,7 @@ template<bool small>
353353void AbstractQuantumSwitch<small>::onNanoDisplay()
354354{
355355 const bool checked = isChecked ();
356+ const bool enabled = isEnabled ();
356357 const uint blockSize = small ? theme.textHeight / 2 : theme.fontSize ;
357358 const int yOffset = (getHeight () - blockSize - theme.borderSize * 2 ) / 2 ;
358359
@@ -362,21 +363,22 @@ void AbstractQuantumSwitch<small>::onNanoDisplay()
362363 fill ();
363364
364365 beginPath ();
366+
365367 if (checked)
366- {
367368 rect (theme.borderSize + blockSize , yOffset + theme.borderSize , blockSize, blockSize);
368- fillColor (theme.widgetActiveColor );
369- }
370369 else
371- {
372370 rect (theme.borderSize , yOffset + theme.borderSize , blockSize, blockSize);
371+
372+ if (checked && enabled)
373+ fillColor (theme.widgetActiveColor );
374+ else
373375 fillColor (theme.textDarkColor );
374- }
376+
375377 fill ();
376378
377379 if (label != nullptr && label[0 ] != ' \0 ' )
378380 {
379- fillColor (checked ? theme.textLightColor : theme.textMidColor );
381+ fillColor (checked && enabled ? theme.textLightColor : theme.textMidColor );
380382 fontSize (theme.fontSize );
381383 textAlign (ALIGN_LEFT |ALIGN_MIDDLE );
382384 text (blockSize * 2 + theme.borderSize * 2 + theme.padding * 2 , getHeight () / 2 , label, nullptr );
@@ -1256,15 +1258,41 @@ void QuantumValueMeter::setUnitLabel(const char* const label)
12561258 repaint ();
12571259}
12581260
1259- void QuantumValueMeter::setValue (const float value2)
1261+ void QuantumValueMeter::setValue (float value2)
12601262{
1263+ if (value2 > maximum)
1264+ value2 = maximum;
1265+ else if (value2 < minimum)
1266+ value2 = minimum;
1267+
12611268 if (d_isEqual (value, value2))
12621269 return ;
12631270
12641271 value = value2;
12651272 repaint ();
12661273}
12671274
1275+ void QuantumValueMeter::setValueCentered (const bool centered)
1276+ {
1277+ if (valueCentered == centered)
1278+ return ;
1279+
1280+ valueCentered = centered;
1281+ repaint ();
1282+ }
1283+
1284+ void QuantumValueMeter::setValueFormat (const char * const format)
1285+ {
1286+ std::free (valueFormat);
1287+
1288+ if (format != nullptr && format[0 ] != ' \0 ' )
1289+ valueFormat = strdup (format);
1290+ else
1291+ valueFormat = nullptr ;
1292+
1293+ repaint ();
1294+ }
1295+
12681296void QuantumValueMeter::setTextColor (const Color color)
12691297{
12701298 textColor = color;
@@ -1353,16 +1381,27 @@ void QuantumValueMeter::onNanoDisplay()
13531381 char valuestr[32 ] = {};
13541382 const float roundedValue = std::round (value * 10 .0f )/10 .0f ;
13551383
1356- if (unitLabel != nullptr )
1384+ if (valueFormat != nullptr )
1385+ std::snprintf (valuestr, sizeof (valuestr)-1 , valueFormat, roundedValue);
1386+ else if (unitLabel != nullptr )
13571387 std::snprintf (valuestr, sizeof (valuestr)-1 , " %.1f %s" , roundedValue, unitLabel);
13581388 else
13591389 std::snprintf (valuestr, sizeof (valuestr)-1 , " %.1f" , roundedValue);
13601390
13611391 beginPath ();
13621392 fontSize (theme.fontSize );
13631393 fillColor (textColor);
1364- textAlign (ALIGN_CENTER |ALIGN_MIDDLE );
1365- text (getWidth ()/2 , getHeight ()/2 , valuestr, nullptr );
1394+
1395+ if (valueCentered)
1396+ {
1397+ textAlign (ALIGN_CENTER |ALIGN_MIDDLE );
1398+ text (getWidth () * 0 .5f , getHeight () * 0 .5f , valuestr, nullptr );
1399+ }
1400+ else
1401+ {
1402+ textAlign (ALIGN_RIGHT |ALIGN_MIDDLE );
1403+ text (getWidth () * 0 .8f , getHeight () * 0 .5f , valuestr, nullptr );
1404+ }
13661405}
13671406
13681407// --------------------------------------------------------------------------------------------------------------------
0 commit comments