mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 15:56:15 +02:00
Improved Selector's handling of the folder icon
Renamed fontHeight to lineHeight, since it is computed using both the font's line spacing and the height of the folder icon. For the latter, use the actual icon height plus two pixels spacing instead of the hardcoded value of 20 (16 height + 4 pixels spacing). Fixed recently introduced bug where "top" is added to the folder icon y-coordinate twice. Also center the icon vertically when a large font is used. Don't crash if the folder icon is missing. This could only happen on broken installations though. Also don't search for the icon twice: SurfaceCollection::skinRes already calls addSkinRes internally when there is no cached surface for the key.
This commit is contained in:
parent
88a4d1d911
commit
d16cb902b3
@ -73,22 +73,19 @@ int Selector::exec(int startSelection) {
|
|||||||
unsigned int top, height;
|
unsigned int top, height;
|
||||||
tie(top, height) = gmenu2x->getContentArea();
|
tie(top, height) = gmenu2x->getContentArea();
|
||||||
|
|
||||||
int fontHeight = gmenu2x->font->getLineSpacing();
|
auto folderIcon = gmenu2x->sc.skinRes("imgs/folder.png");
|
||||||
if (showDirectories) {
|
|
||||||
fontHeight = constrain(fontHeight, 20, 40);
|
int lineHeight = gmenu2x->font->getLineSpacing();
|
||||||
|
if (showDirectories && folderIcon) {
|
||||||
|
lineHeight = max(lineHeight, folderIcon->height() + 2);
|
||||||
}
|
}
|
||||||
unsigned int nb_elements = height / fontHeight;
|
unsigned int nb_elements = max(height / lineHeight, 1u);
|
||||||
|
|
||||||
bg.convertToDisplayFormat();
|
bg.convertToDisplayFormat();
|
||||||
|
|
||||||
unsigned int firstElement = 0;
|
unsigned int firstElement = 0;
|
||||||
unsigned int selected = constrain(startSelection, 0, fl.size() - 1);
|
unsigned int selected = constrain(startSelection, 0, fl.size() - 1);
|
||||||
|
|
||||||
auto folderIcon = gmenu2x->sc.skinRes("imgs/folder.png");
|
|
||||||
if (!folderIcon) {
|
|
||||||
folderIcon = gmenu2x->sc.addSkinRes("imgs/folder.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool close = false, result = true;
|
bool close = false, result = true;
|
||||||
while (!close) {
|
while (!close) {
|
||||||
OutputSurface& s = *gmenu2x->s;
|
OutputSurface& s = *gmenu2x->s;
|
||||||
@ -110,23 +107,28 @@ int Selector::exec(int startSelection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Selection
|
//Selection
|
||||||
unsigned int iY = top + (selected - firstElement) * fontHeight;
|
int iY = top + (selected - firstElement) * lineHeight;
|
||||||
if (selected<fl.size())
|
if (selected<fl.size())
|
||||||
s.box(1, iY, 309, fontHeight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
s.box(1, iY, 309, lineHeight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
||||||
|
|
||||||
//Files & Dirs
|
//Files & Dirs
|
||||||
s.setClipRect(0, top, 311, height);
|
s.setClipRect(0, top, 311, height);
|
||||||
for (unsigned int i = firstElement;
|
for (unsigned int i = firstElement;
|
||||||
i < fl.size() && i < firstElement + nb_elements; i++) {
|
i < fl.size() && i < firstElement + nb_elements; i++) {
|
||||||
iY = top + (i - firstElement) * fontHeight;
|
iY = top + (i - firstElement) * lineHeight;
|
||||||
|
x = 4;
|
||||||
if (fl.isDirectory(i)) {
|
if (fl.isDirectory(i)) {
|
||||||
folderIcon->blit(s, 4, top + iY);
|
if (folderIcon) {
|
||||||
|
folderIcon->blit(s,
|
||||||
|
x, iY + (lineHeight - folderIcon->height()) / 2);
|
||||||
|
x += folderIcon->width() + 2;
|
||||||
|
}
|
||||||
gmenu2x->font->write(s, fl[i],
|
gmenu2x->font->write(s, fl[i],
|
||||||
21, iY + (fontHeight / 2),
|
x, iY + lineHeight / 2,
|
||||||
Font::HAlignLeft, Font::VAlignMiddle);
|
Font::HAlignLeft, Font::VAlignMiddle);
|
||||||
} else {
|
} else {
|
||||||
gmenu2x->font->write(s, trimExtension(fl[i]),
|
gmenu2x->font->write(s, trimExtension(fl[i]),
|
||||||
4, iY + (fontHeight / 2),
|
x, iY + lineHeight / 2,
|
||||||
Font::HAlignLeft, Font::VAlignMiddle);
|
Font::HAlignLeft, Font::VAlignMiddle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user