mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 12:09:41 +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;
|
||||
tie(top, height) = gmenu2x->getContentArea();
|
||||
|
||||
int fontHeight = gmenu2x->font->getLineSpacing();
|
||||
if (showDirectories) {
|
||||
fontHeight = constrain(fontHeight, 20, 40);
|
||||
auto folderIcon = gmenu2x->sc.skinRes("imgs/folder.png");
|
||||
|
||||
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();
|
||||
|
||||
unsigned int firstElement = 0;
|
||||
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;
|
||||
while (!close) {
|
||||
OutputSurface& s = *gmenu2x->s;
|
||||
@ -110,23 +107,28 @@ int Selector::exec(int startSelection) {
|
||||
}
|
||||
|
||||
//Selection
|
||||
unsigned int iY = top + (selected - firstElement) * fontHeight;
|
||||
int iY = top + (selected - firstElement) * lineHeight;
|
||||
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
|
||||
s.setClipRect(0, top, 311, height);
|
||||
for (unsigned int i = firstElement;
|
||||
i < fl.size() && i < firstElement + nb_elements; i++) {
|
||||
iY = top + (i - firstElement) * fontHeight;
|
||||
iY = top + (i - firstElement) * lineHeight;
|
||||
x = 4;
|
||||
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],
|
||||
21, iY + (fontHeight / 2),
|
||||
x, iY + lineHeight / 2,
|
||||
Font::HAlignLeft, Font::VAlignMiddle);
|
||||
} else {
|
||||
gmenu2x->font->write(s, trimExtension(fl[i]),
|
||||
4, iY + (fontHeight / 2),
|
||||
x, iY + lineHeight / 2,
|
||||
Font::HAlignLeft, Font::VAlignMiddle);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user