mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-27 06:35:16 +00:00
Remove Graphics::measureUIText/Length() functions
With the introduction of Widget::processMnemonicFromText() in 17151cddcd25ab089f5d2ffcc9ec680ba6cd57bf we don't require these functions anymore because the '&' character isn't not present in the widget text (so we can just measure the text length as usual). This was discovered in PR #4604: https://github.com/aseprite/aseprite/pull/4604#discussion_r1731172284
This commit is contained in:
parent
7941b5d971
commit
f9d2f1ce46
@ -283,8 +283,8 @@ private:
|
||||
if (m_key && m_key->keycontext() != KeyContext::Any) {
|
||||
int w =
|
||||
m_headerItem->contextXPos() +
|
||||
Graphics::measureUITextLength(
|
||||
convertKeyContextToUserFriendlyString(m_key->keycontext()), font());
|
||||
font()->textLength(
|
||||
convertKeyContextToUserFriendlyString(m_key->keycontext()));
|
||||
size.w = std::max(size.w, w);
|
||||
}
|
||||
|
||||
@ -384,9 +384,9 @@ private:
|
||||
auto theme = SkinTheme::get(this);
|
||||
|
||||
for (int i=0; i<maxi; ++i, y += dh) {
|
||||
int w = Graphics::measureUITextLength(
|
||||
(accels && i < (int)accels->size() ? getAccelText((*accels)[i]).c_str(): ""),
|
||||
font());
|
||||
int w = font()->textLength(
|
||||
(accels && i < (int)accels->size() ? getAccelText((*accels)[i]):
|
||||
std::string()));
|
||||
gfx::Rect itemBounds(bounds.x + m_headerItem->keyXPos(), y, w, dh);
|
||||
itemBounds = itemBounds.enlarge(
|
||||
gfx::Border(
|
||||
@ -422,8 +422,7 @@ private:
|
||||
gfx::Rect(
|
||||
itemBounds.x + itemBounds.w + 2*guiscale(),
|
||||
itemBounds.y,
|
||||
Graphics::measureUITextLength(
|
||||
label, font()) + 4*guiscale(),
|
||||
font()->textLength(label) + 4*guiscale(),
|
||||
itemBounds.h));
|
||||
m_deleteButton->setText(label);
|
||||
|
||||
@ -439,7 +438,7 @@ private:
|
||||
m_addButton->setStyle(theme->styles.miniButton());
|
||||
addChild(m_addButton.get());
|
||||
|
||||
itemBounds.w = 8*guiscale() + Graphics::measureUITextLength("Add", font());
|
||||
itemBounds.w = 8*guiscale() + font()->textLength("Add");
|
||||
itemBounds.x -= itemBounds.w + 2*guiscale();
|
||||
|
||||
m_addButton->setBgColor(gfx::ColorNone);
|
||||
|
@ -224,7 +224,7 @@ protected:
|
||||
// Draw the line number
|
||||
{
|
||||
auto lineNumText = base::convert_to<std::string>(i+1);
|
||||
int lw = Graphics::measureUITextLength(lineNumText, f);
|
||||
int lw = f->textLength(lineNumText);
|
||||
g->drawText(
|
||||
lineNumText.c_str(),
|
||||
fg, linesBg,
|
||||
@ -249,7 +249,7 @@ protected:
|
||||
for (const uint8_t* line : m_fileContent->lines) {
|
||||
ASSERT(line);
|
||||
tmp.assign((const char*)line);
|
||||
m_maxLineWidth = std::max(m_maxLineWidth, Graphics::measureUITextLength(tmp, f));
|
||||
m_maxLineWidth = std::max(m_maxLineWidth, f->textLength(tmp));
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ private:
|
||||
auto f = font();
|
||||
int nlines = (m_fileContent ? m_fileContent->lines.size(): 0);
|
||||
return
|
||||
Graphics::measureUITextLength(base::convert_to<std::string>(nlines), f)
|
||||
f->textLength(base::convert_to<std::string>(nlines))
|
||||
+ 4*guiscale(); // TODO configurable from the theme?
|
||||
}
|
||||
|
||||
|
@ -122,8 +122,8 @@ void AppMenuItem::onSizeHint(SizeHintEvent& ev)
|
||||
+ border().height();
|
||||
|
||||
if (m_key && !m_key->accels().empty()) {
|
||||
size.w += Graphics::measureUITextLength(
|
||||
m_key->accels().front().toString().c_str(), font());
|
||||
size.w += font()->textLength(
|
||||
m_key->accels().front().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1230,14 +1230,14 @@ void Editor::drawTileNumbers(ui::Graphics* g, const Cel* cel)
|
||||
text = fmt::format("{}", ti + ti_offset);
|
||||
|
||||
gfx::Point pt2(pt);
|
||||
pt2.x -= g->measureUIText(text).w/2;
|
||||
pt2.x -= g->font()->textLength(text)/2;
|
||||
g->drawText(text, fgColor, color, pt2);
|
||||
|
||||
if (tf && tileSize.h > 2*th) {
|
||||
text.clear();
|
||||
build_tile_flags_string(tf, text);
|
||||
|
||||
const gfx::Size tsize = g->measureUIText(text);
|
||||
const gfx::Size tsize = g->measureText(text);
|
||||
pt.x -= tsize.w/2;
|
||||
pt.y += tsize.h;
|
||||
g->drawText(text, fgColor, color, pt);
|
||||
@ -1359,7 +1359,7 @@ void Editor::drawCelHGuide(ui::Graphics* g,
|
||||
}
|
||||
|
||||
auto text = fmt::format("{}px", ABS(sprX2 - sprX1));
|
||||
const int textW = Graphics::measureUITextLength(text, font());
|
||||
const int textW = font()->textLength(text);
|
||||
g->drawText(text,
|
||||
color_utils::blackandwhite_neg(color), color,
|
||||
gfx::Point((scrX1+scrX2)/2-textW/2, scrY-textHeight()));
|
||||
@ -2296,7 +2296,7 @@ void Editor::onPaint(ui::PaintEvent& ev)
|
||||
vp.origin() - bounds().origin());
|
||||
|
||||
m_perfInfoBounds.setOrigin(vp.origin());
|
||||
m_perfInfoBounds.setSize(g->measureUIText(buf));
|
||||
m_perfInfoBounds.setSize(g->measureText(buf));
|
||||
}
|
||||
#endif // ENABLE_DEVMODE
|
||||
|
||||
|
@ -68,7 +68,7 @@ void ResourceListItem::onPaint(PaintEvent& ev)
|
||||
g->drawText(text(), fgcolor, gfx::ColorNone,
|
||||
gfx::Point(
|
||||
bounds.x + 2*guiscale(),
|
||||
bounds.y + bounds.h/2 - g->measureUIText(text()).h/2));
|
||||
bounds.y + bounds.h/2 - g->font()->height()/2));
|
||||
}
|
||||
|
||||
void ResourceListItem::onSizeHint(SizeHintEvent& ev)
|
||||
|
@ -1614,7 +1614,7 @@ void SkinTheme::drawText(Graphics* g, const char* t,
|
||||
if (!t)
|
||||
t = widget->text().c_str();
|
||||
|
||||
textrc.setSize(g->measureUIText(t));
|
||||
textrc.setSize(g->measureText(t));
|
||||
|
||||
// Horizontally text alignment
|
||||
|
||||
|
@ -446,21 +446,10 @@ void Graphics::drawAlignedUIText(const std::string& str, gfx::Color fg, gfx::Col
|
||||
doUIStringAlgorithm(str, fg, bg, rc, align, true);
|
||||
}
|
||||
|
||||
gfx::Size Graphics::measureUIText(const std::string& str)
|
||||
gfx::Size Graphics::measureText(const std::string& str)
|
||||
{
|
||||
return gfx::Size(
|
||||
Graphics::measureUITextLength(str, m_font.get()),
|
||||
m_font->height());
|
||||
}
|
||||
|
||||
// static
|
||||
int Graphics::measureUITextLength(const std::string& str,
|
||||
text::Font* font)
|
||||
{
|
||||
if (str.empty())
|
||||
return 0;
|
||||
|
||||
return font->textLength(str);
|
||||
return gfx::Size(m_font->textLength(str),
|
||||
m_font->height());
|
||||
}
|
||||
|
||||
gfx::Size Graphics::fitString(const std::string& str, int maxWidth, int align)
|
||||
|
@ -115,9 +115,7 @@ namespace ui {
|
||||
void drawUIText(const std::string& str, gfx::Color fg, gfx::Color bg, const gfx::Point& pt, const int mnemonic);
|
||||
void drawAlignedUIText(const std::string& str, gfx::Color fg, gfx::Color bg, const gfx::Rect& rc, const int align);
|
||||
|
||||
gfx::Size measureUIText(const std::string& str);
|
||||
static int measureUITextLength(const std::string& str,
|
||||
text::Font* font);
|
||||
gfx::Size measureText(const std::string& str);
|
||||
gfx::Size fitString(const std::string& str, int maxWidth, int align);
|
||||
|
||||
// Can be used in case that you've accessed/changed the
|
||||
|
@ -454,7 +454,7 @@ void Theme::paintLayer(Graphics* g,
|
||||
textBounds, layer.align());
|
||||
}
|
||||
else {
|
||||
gfx::Size textSize = g->measureUIText(text);
|
||||
gfx::Size textSize = g->measureText(text);
|
||||
gfx::Point pt;
|
||||
gfx::Border undef = Style::UndefinedBorder();
|
||||
gfx::Border padding = style->padding();
|
||||
@ -594,12 +594,12 @@ void Theme::measureLayer(const Widget* widget,
|
||||
|
||||
case Style::Layer::Type::kText:
|
||||
if (layer.color() != gfx::ColorNone) {
|
||||
text::Font* styleFont = style->font();
|
||||
gfx::Size textSize;
|
||||
if (style->font() &&
|
||||
style->font() != widget->font()) {
|
||||
text::Font* font = style->font();
|
||||
textSize = gfx::Size(Graphics::measureUITextLength(widget->text(), font),
|
||||
font->height());
|
||||
if (styleFont &&
|
||||
styleFont != widget->font()) {
|
||||
textSize = gfx::Size(styleFont->textLength(widget->text()),
|
||||
styleFont->height());
|
||||
}
|
||||
else {
|
||||
// We can use Widget::textSize() because we're going to use
|
||||
|
Loading…
x
Reference in New Issue
Block a user