Skip to content

Commit fab10da

Browse files
committed
TextBox: preferred_size_impl() was unreliable
The following was detected by the new ``preferred_size()`` cache consistency checks in debug mode. ``TextBox::preferred_size_impl()`` forgot to set the font and font size. This meant the computed result was dependent on UI/sizing computation done by other widgets previously :-(.
1 parent 9e27364 commit fab10da

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/textbox.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ void TextBox::set_theme(Theme *theme) {
6161
}
6262

6363
Vector2i TextBox::preferred_size_impl(NVGcontext *ctx) const {
64-
Vector2i size(0, font_size() * 1.4f);
64+
Vector2i size(0, m_font_size * 1.4f);
65+
66+
nvgFontFace(ctx, "sans");
67+
nvgFontSize(ctx, m_font_size);
6568

6669
float uw = 0;
6770
if (m_units_image > 0) {
@@ -79,6 +82,7 @@ Vector2i TextBox::preferred_size_impl(NVGcontext *ctx) const {
7982

8083
float ts = nvgTextBounds(ctx, 0, 0, m_value.c_str(), nullptr, nullptr);
8184
size[0] = size[1] + ts + uw + sw;
85+
8286
return size;
8387
}
8488

@@ -125,7 +129,7 @@ void TextBox::draw(NVGcontext* ctx) {
125129
nvgStrokeColor(ctx, Color(0, 48));
126130
nvgStroke(ctx);
127131

128-
nvgFontSize(ctx, font_size());
132+
nvgFontSize(ctx, m_font_size);
129133
nvgFontFace(ctx, "sans");
130134
Vector2i draw_pos(m_pos.x(), m_pos.y() + m_size.y() * 0.5f + 1);
131135

@@ -187,7 +191,7 @@ void TextBox::draw(NVGcontext* ctx) {
187191
nvgText(ctx, icon_pos.x(), icon_pos.y(), icon.data(), nullptr);
188192
}
189193

190-
nvgFontSize(ctx, font_size());
194+
nvgFontSize(ctx, m_font_size);
191195
nvgFontFace(ctx, "sans");
192196
}
193197

@@ -206,7 +210,7 @@ void TextBox::draw(NVGcontext* ctx) {
206210
break;
207211
}
208212

209-
nvgFontSize(ctx, font_size());
213+
nvgFontSize(ctx, m_font_size);
210214
nvgFillColor(ctx, m_enabled && (!m_committed || !m_value.empty()) ?
211215
m_theme->m_text_color :
212216
m_theme->m_disabled_text_color);

0 commit comments

Comments
 (0)