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