Add Scrolling.

This commit is contained in:
VoltZ 2019-11-01 20:50:00 +01:00 committed by GitHub
commit da49c38c9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 3 deletions

View file

@ -41,6 +41,8 @@
#define BarColor C2D_Color32(57, 84, 114, 255)
#define TopBGColor C2D_Color32(96, 168, 192, 255)
#define BottomBGColor C2D_Color32(38, 44, 77, 255)
#define SelectedColor C2D_Color32(120, 192, 216, 255)
#define UnselectedColor C2D_Color32(77, 118, 132, 255)
#define BLACK C2D_Color32(0, 0, 0, 255)
#define WHITE C2D_Color32(255, 255, 255, 255)
#define TextColor C2D_Color32(102, 179, 255, 255)

View file

@ -37,10 +37,12 @@ public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
ScriptList();
void showParsedObjects(void) const;
private:
std::vector<DirEntry> dirContents;
uint selectedFile = 0;
mutable int screenPos = 0;
mutable int selection = 0;
int keyRepeatDelay = 0;
int fastMode = false;
bool dirChanged = true;

View file

@ -58,6 +58,7 @@ Info parseInfo(std::string fileName) {
return info;
}
std::vector<Info> fileInfo;
ScriptList::ScriptList() {
@ -69,21 +70,61 @@ ScriptList::ScriptList() {
}
}
void ScriptList::Draw(void) const {
std::string titleinfo;
Gui::DrawTop();
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, "Universal-Updater", 400);
Gui::DrawBottom();
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo.size();i++) {
titleinfo = fileInfo[i].title + '\n' + fileInfo[i].description;
Gui::Draw_Rect(0, 40+(i*57), 320, 45, TopBGColor);
titleinfo = fileInfo[screenPos + i].title + '\n' + fileInfo[screenPos + i].description;
if(screenPos + i == selection) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, SelectedColor);
} else {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, UnselectedColor);
}
Gui::DrawString(0, 40+(i*57), 0.7f, WHITE, titleinfo, 320);
}
}
void ScriptList::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if (hDown & KEY_B) {
Gui::screenBack();
return;
}
if (hHeld & KEY_DOWN && !keyRepeatDelay) {
if (selection < (int)fileInfo.size()-1) {
selection++;
} else {
selection = 0;
}
if (fastMode == true) {
keyRepeatDelay = 3;
} else if (fastMode == false){
keyRepeatDelay = 6;
}
}
if (hHeld & KEY_UP && !keyRepeatDelay) {
if (selection > 0) {
selection--;
} else {
selection = (int)fileInfo.size()-1;
}
if (fastMode == true) {
keyRepeatDelay = 3;
} else if (fastMode == false){
keyRepeatDelay = 6;
}
}
if(selection < screenPos) {
screenPos = selection;
} else if (selection > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = selection - ENTRIES_PER_SCREEN + 1;
}
}