[ui] Align text with different fonts correctly to ui::Entry baseline

Regression introduced in af6e8b65c3
This commit is contained in:
David Capello 2025-06-11 17:05:40 -03:00
parent bd13e5d574
commit 0ddf7d939b
3 changed files with 21 additions and 5 deletions

View File

@ -42,6 +42,7 @@
#include "text/font.h"
#include "text/font_metrics.h"
#include "text/font_style_set.h"
#include "text/text_blob.h"
#include "ui/intern.h"
#include "ui/ui.h"
@ -1443,11 +1444,12 @@ void SkinTheme::drawEntryText(ui::Graphics* g, ui::Entry* widget)
IntersectClip clip(g, bounds);
if (clip) {
g->drawTextWithDelegate(std::string(pos, textString.end()), // TODO use a string_view()
colors.text(),
ColorNone,
bounds.origin(),
&delegate);
g->drawTextWithDelegate(
std::string(pos, textString.end()), // TODO use a string_view()
colors.text(),
ColorNone,
gfx::Point(bounds.x, widget->textBaseline() - widget->textBlob()->baseline()),
&delegate);
}
}

View File

@ -15,6 +15,7 @@
#include "os/system.h"
#include "text/draw_text.h"
#include "text/font.h"
#include "text/font_metrics.h"
#include "ui/clipboard_delegate.h"
#include "ui/display.h"
#include "ui/menu.h"
@ -549,6 +550,18 @@ void Entry::onSetText()
m_caret = textlen;
}
float Entry::onGetTextBaseline() const
{
text::FontMetrics metrics;
font()->metrics(&metrics);
// Here we only use the descent+ascent to measure the text height,
// without the metrics.leading part (which is the used to separate
// text lines in a paragraph, but here'd make widgets too big)
const float textHeight = metrics.descent - metrics.ascent;
const gfx::Rect rc = getEntryTextBounds();
return guiscaled_center(rc.y, rc.h, textHeight) - metrics.ascent;
}
void Entry::onChange()
{
Change();

View File

@ -84,6 +84,7 @@ protected:
void onPaint(PaintEvent& ev) override;
void onSetFont() override;
void onSetText() override;
float onGetTextBaseline() const override;
// New Events
virtual void onChange();