Avoid drawing empty strings

This commit is contained in:
Christian Kaiser 2024-08-19 12:03:31 -03:00 committed by David Capello
parent 1c1c4593ed
commit aed9127b51
5 changed files with 21 additions and 10 deletions

2
laf

@ -1 +1 @@
Subproject commit 50573685f7af01a68233acaed99bea00145b6778
Subproject commit 06279da54f2849ee042897af5457efa442401ab4

View File

@ -1264,6 +1264,9 @@ private:
void SkinTheme::drawEntryText(ui::Graphics* g, ui::Entry* widget)
{
if (widget->text().empty())
return;
// Draw the text
gfx::Rect bounds = widget->getEntryTextBounds();

View File

@ -340,6 +340,9 @@ void Graphics::drawText(const std::string& str,
const gfx::Point& origPt,
text::DrawTextDelegate* delegate)
{
if (str.empty())
return;
gfx::Point pt(m_dx+origPt.x, m_dy+origPt.y);
os::SurfaceLock lock(m_surface.get());
@ -423,6 +426,9 @@ private:
void Graphics::drawUIText(const std::string& str, gfx::Color fg, gfx::Color bg,
const gfx::Point& pt, const int mnemonic)
{
if (str.empty())
return;
os::SurfaceLock lock(m_surface.get());
int x = m_dx+pt.x;
int y = m_dy+pt.y;
@ -451,12 +457,10 @@ gfx::Size Graphics::measureUIText(const std::string& str)
int Graphics::measureUITextLength(const std::string& str,
text::Font* font)
{
DrawUITextDelegate delegate(nullptr, font, 0);
text::draw_text(nullptr, get_theme()->fontMgr(),
base::AddRef(font), str,
gfx::ColorNone, gfx::ColorNone,
0, 0, &delegate);
return delegate.bounds().w;
if (str.empty())
return 0;
return font->textLength(str);
}
gfx::Size Graphics::fitString(const std::string& str, int maxWidth, int align)
@ -561,7 +565,8 @@ gfx::Size Graphics::doUIStringAlgorithm(const std::string& str, gfx::Color fg, g
else
xout = pt.x;
drawText(line, fg, bg, gfx::Point(xout, pt.y));
if (!line.empty())
drawText(line, fg, bg, gfx::Point(xout, pt.y));
if (!gfx::is_transparent(bg))
fillAreaBetweenRects(bg,

View File

@ -436,6 +436,9 @@ void Theme::paintLayer(Graphics* g,
break;
case Style::Layer::Type::kText:
if (text.empty())
break;
if (layer.color() != gfx::ColorNone) {
text::FontRef oldFont = base::AddRef(g->font());
if (style->font())
@ -949,7 +952,7 @@ void Theme::drawTextBox(Graphics* g, const Widget* widget,
len = font->textLength(beg);
// Render the text
if (g) {
if (g && len > 0) {
int xout;
if (widget->align() & CENTER)

View File

@ -920,7 +920,7 @@ void Widget::getDrawableRegion(gfx::Region& region, DrawableRegionFlags flags)
text::TextBlobRef Widget::textBlob() const
{
if (!m_blob) {
if (!m_blob && !m_text.empty()) {
m_blob = text::TextBlob::MakeWithShaper(
theme()->fontMgr(),
AddRef(font()),