1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 18:23:08 +02:00

Handle labelless icon positioning in GMenu2X::drawButton(Right)

Instead of correcting the returned coordinate with "- 10" externally,
omit the white space inside the methods.

Note that Font::getTextWidth, which was used until recently, considers
an empty string to have width 1, so 3 + getTextWidth("") + 6 == 10.

There is a difference in how buttons that have neither a label nor an
icon are positioned in the new code, but that is a situation that
should not occur in practice. Plus I'd argue that the new behavior is
actually better in that case.
This commit is contained in:
Maarten ter Huurne 2014-08-15 18:41:17 +02:00
parent 45304052cd
commit 3df841c150
5 changed files with 19 additions and 13 deletions

View File

@ -1037,11 +1037,14 @@ int GMenu2X::drawButton(Surface& s, const string &btn, const string &text, int x
if (y < 0) y = resY + y; if (y < 0) y = resY + y;
w = icon->width(); w = icon->width();
icon->blit(s, x, y - 7); icon->blit(s, x, y - 7);
if (!text.empty()) {
w += 3; w += 3;
w += font->write( w += font->write(
s, text, x + w, y, Font::HAlignLeft, Font::VAlignMiddle); s, text, x + w, y, Font::HAlignLeft, Font::VAlignMiddle);
w += 6;
} }
return x + w + 6; }
return x + w;
} }
int GMenu2X::drawButtonRight(Surface& s, const string &btn, const string &text, int x, int y) { int GMenu2X::drawButtonRight(Surface& s, const string &btn, const string &text, int x, int y) {
@ -1051,11 +1054,14 @@ int GMenu2X::drawButtonRight(Surface& s, const string &btn, const string &text,
if (y < 0) y = resY + y; if (y < 0) y = resY + y;
w = icon->width(); w = icon->width();
icon->blit(s, x - w, y - 7); icon->blit(s, x - w, y - 7);
if (!text.empty()) {
w += 3; w += 3;
w += font->write( w += font->write(
s, text, x - w, y, Font::HAlignRight, Font::VAlignMiddle); s, text, x - w, y, Font::HAlignRight, Font::VAlignMiddle);
w += 6;
} }
return x - (w + 6); }
return x - w;
} }
void GMenu2X::drawScrollBar(uint pageSize, uint totalSize, uint pagePos) { void GMenu2X::drawScrollBar(uint pageSize, uint totalSize, uint pagePos) {

View File

@ -475,7 +475,7 @@ void LinkApp::showManual() {
gmenu2x->drawButton(s, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(s, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(s, "cancel", "", gmenu2x->drawButton(s, "cancel", "",
gmenu2x->drawButton(s, "right", gmenu2x->tr["Change page"], gmenu2x->drawButton(s, "right", gmenu2x->tr["Change page"],
gmenu2x->drawButton(s, "left", "", 5)-10))-10); gmenu2x->drawButton(s, "left", "", 5))));
ss.clear(); ss.clear();
ss << page+1; ss << page+1;

View File

@ -66,11 +66,11 @@ int Selector::exec(int startSelection) {
gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"],
gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"], gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"],
gmenu2x->drawButton(bg, "left", "", 5)-10))); gmenu2x->drawButton(bg, "left", "", 5))));
} else { } else {
gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(bg, "cancel", "", gmenu2x->drawButton(bg, "cancel", "",
gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], 5)) - 10); gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], 5)));
} }
unsigned int top, height; unsigned int top, height;

View File

@ -73,7 +73,7 @@ void TextDialog::exec() {
gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
gmenu2x->drawButton(bg, "cancel", "", gmenu2x->drawButton(bg, "cancel", "",
gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"], gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"],
gmenu2x->drawButton(bg, "up", "", 5)-10))-10); gmenu2x->drawButton(bg, "up", "", 5))));
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();

View File

@ -82,7 +82,7 @@ void TextManualDialog::exec() {
gmenu2x->drawButton(bg, "right", gmenu2x->tr["Change page"], gmenu2x->drawButton(bg, "right", gmenu2x->tr["Change page"],
gmenu2x->drawButton(bg, "left", "", gmenu2x->drawButton(bg, "left", "",
gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"], gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"],
gmenu2x->drawButton(bg, "up", "", 5)-10))-10))-10); gmenu2x->drawButton(bg, "up", "", 5))))));
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();