Skip to content

Commit f0521f2

Browse files
committed
Add QuantumLabel::setCustomFontSize
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 58de3e5 commit f0521f2

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

opengl/Quantum.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void QuantumLabel::adjustSize()
174174
if (label != nullptr && label[0] != '\0')
175175
{
176176
Rectangle<float> bounds;
177-
fontSize(theme.fontSize);
177+
fontSize(customFontSize == 0 ? theme.fontSize : customFontSize);
178178

179179
textBounds(0, 0, label, nullptr, bounds);
180180
width = std::max(static_cast<uint>(bounds.getWidth() + 0.5f), theme.padding) + theme.textPixelRatioWidthCompensation;
@@ -198,13 +198,28 @@ void QuantumLabel::setAlignment(const uint alignment2)
198198
repaint();
199199
}
200200

201+
void QuantumLabel::setCustomFontSize(const uint size, const bool adjustSizeNow)
202+
{
203+
if (customFontSize == size)
204+
return;
205+
206+
customFontSize = size;
207+
208+
if (adjustSizeNow)
209+
adjustSize();
210+
211+
repaint();
212+
}
213+
201214
void QuantumLabel::setLabel(const char* const label2, const bool adjustSizeNow)
202215
{
203216
std::free(label);
204217
label = label2 != nullptr ? strdup(label2) : nullptr;
205218

206219
if (adjustSizeNow)
207220
adjustSize();
221+
222+
repaint();
208223
}
209224

210225
void QuantumLabel::setLabelColor(const Color color)
@@ -219,12 +234,12 @@ void QuantumLabel::onNanoDisplay()
219234
return;
220235

221236
fillColor(labelColor);
222-
fontSize(theme.fontSize);
237+
fontSize(customFontSize == 0 ? theme.fontSize : customFontSize);
223238
textAlign(alignment);
224239

225240
float y;
226241
if (alignment & ALIGN_MIDDLE)
227-
y = getHeight() / 2;
242+
y = getHeight() * 0.5f;
228243
else if (alignment & ALIGN_BOTTOM)
229244
y = getHeight();
230245
else

opengl/Quantum.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class QuantumLabel : public NanoSubWidget
191191
{
192192
const QuantumTheme& theme;
193193
uint alignment = ALIGN_LEFT|ALIGN_MIDDLE;
194+
uint customFontSize = 0;
194195
char* label = nullptr;
195196
Color labelColor = theme.textLightColor;
196197

@@ -204,6 +205,11 @@ class QuantumLabel : public NanoSubWidget
204205
return alignment;
205206
}
206207

208+
inline uint getCustomFontSize() const noexcept
209+
{
210+
return customFontSize;
211+
}
212+
207213
inline const char* getLabel() const noexcept
208214
{
209215
return label;
@@ -216,6 +222,7 @@ class QuantumLabel : public NanoSubWidget
216222

217223
void adjustSize();
218224
void setAlignment(uint alignment);
225+
void setCustomFontSize(uint size, bool adjustSizeNow = true);
219226
void setLabel(const char* label, bool adjustSizeNow = true);
220227
void setLabelColor(Color color);
221228

0 commit comments

Comments
 (0)