Try to use TextBlobs to paint ui::Style's text layers

This commit is contained in:
David Capello 2024-11-29 23:18:05 -03:00
parent 9e51e04606
commit 3f591aa5df
2 changed files with 25 additions and 4 deletions

View File

@ -103,6 +103,7 @@ PaintWidgetPartInfo::PaintWidgetPartInfo()
bgColor = gfx::ColorNone; bgColor = gfx::ColorNone;
styleFlags = 0; styleFlags = 0;
text = nullptr; text = nullptr;
textBlob = nullptr;
mnemonic = 0; mnemonic = 0;
icon = nullptr; icon = nullptr;
} }
@ -114,6 +115,7 @@ PaintWidgetPartInfo::PaintWidgetPartInfo(const Widget* widget)
gfx::ColorNone); gfx::ColorNone);
styleFlags = PaintWidgetPartInfo::getStyleFlagsForWidget(widget); styleFlags = PaintWidgetPartInfo::getStyleFlagsForWidget(widget);
text = &widget->text(); text = &widget->text();
textBlob = widget->textBlob();
mnemonic = widget->mnemonic(); mnemonic = widget->mnemonic();
icon = nullptr; icon = nullptr;
if (const Style::Layer::IconSurfaceProvider* iconProvider = dynamic_cast<const Style::Layer::IconSurfaceProvider*>(widget)) { if (const Style::Layer::IconSurfaceProvider* iconProvider = dynamic_cast<const Style::Layer::IconSurfaceProvider*>(widget)) {
@ -210,6 +212,7 @@ void Theme::paintWidgetPart(Graphics* g,
(const Style::Layer& layer) { (const Style::Layer& layer) {
paintLayer(g, style, layer, paintLayer(g, style, layer,
(info.text ? *info.text: std::string()), (info.text ? *info.text: std::string()),
info.textBlob,
info.mnemonic, info.icon, rc, outBgColor); info.mnemonic, info.icon, rc, outBgColor);
}); });
} }
@ -326,6 +329,7 @@ void Theme::paintLayer(Graphics* g,
const Style* style, const Style* style,
const Style::Layer& layer, const Style::Layer& layer,
const std::string& text, const std::string& text,
const text::TextBlobRef& textBlob,
const int mnemonic, const int mnemonic,
os::Surface* providedIcon, os::Surface* providedIcon,
gfx::Rect& rc, gfx::Rect& rc,
@ -481,10 +485,25 @@ void Theme::paintLayer(Graphics* g,
pt += layer.offset(); pt += layer.offset();
g->drawUIText(text, // Fast path with TextBlobs
layer.color(), if ((textBlob) &&
bgColor, (!style->mnemonics() || mnemonic == 0) &&
pt, style->mnemonics() ? mnemonic : 0); (style->font() == nullptr)) {
Paint paint;
if (gfx::geta(bgColor) > 0) { // Paint background
paint.color(bgColor);
paint.style(os::Paint::Fill);
g->drawRect(gfx::RectF(textBlob->bounds()).offset(pt), paint);
}
paint.color(layer.color());
g->drawTextBlob(textBlob, gfx::PointF(pt), paint);
}
else {
g->drawUIText(text,
layer.color(),
bgColor,
pt, style->mnemonics() ? mnemonic : 0);
}
} }
if (style->font()) if (style->font())

View File

@ -48,6 +48,7 @@ namespace ui {
gfx::Color bgColor; gfx::Color bgColor;
int styleFlags; // ui::Style::Layer flags int styleFlags; // ui::Style::Layer flags
const std::string* text; const std::string* text;
text::TextBlobRef textBlob;
int mnemonic; int mnemonic;
os::Surface* icon; os::Surface* icon;
@ -154,6 +155,7 @@ namespace ui {
const Style* style, const Style* style,
const Style::Layer& layer, const Style::Layer& layer,
const std::string& text, const std::string& text,
const text::TextBlobRef& textBlob,
const int mnemonic, const int mnemonic,
os::Surface* icon, os::Surface* icon,
gfx::Rect& rc, gfx::Rect& rc,