Skip to content

Commit

Permalink
adjust app list and app details joystick cursor handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Dec 1, 2023
1 parent dbe6a93 commit 274695e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
22 changes: 21 additions & 1 deletion gui/AppDetailsContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,27 @@ bool AppDetailsContent::process(InputEvents* event)
// std::cout << "viewSSButton position: " << viewSSButton.x << ", " << viewSSButton.y << std::endl;
}

return ret || ListElement::process(event);

ret = ret || ListElement::process(event);

int maxScrollOffset = screenshotsContainer.y + screenshotsContainer.height - SCREEN_HEIGHT + 100;

// make sure the max scroll offset is at least the screen height
if (maxScrollOffset < SCREEN_HEIGHT) {
maxScrollOffset = 0;
}

// if our screen scroll is too far down, stop the scroll
// printf("Screenshot container y: %d\n", screenshotsContainer.y);
// printf("Screenshot height: %d\n", screenshotsContainer.height);
// printf("Scroll offset: %d\n", this->y + this->yOff);

// if we're not touch dragging, and we're out of bounds, reset scroll bounds
if ((!event->isScrolling || event->isTouchUp()) && abs(this->y + this->yOff) > maxScrollOffset) {
this->y = -maxScrollOffset;
}

return ret;
}

void AppDetailsContent::switchExtraInfo(Package* package, int newState) {
Expand Down
27 changes: 19 additions & 8 deletions gui/AppList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,35 @@ bool AppList::process(InputEvents* event)
if (!touchMode && this->elements.size() > this->highlighted && this->highlighted >= 0 && this->elements[this->highlighted])
{
// if our highlighted position is large enough, force scroll the screen so that our cursor stays on screen

Element* curTile = this->elements[this->highlighted];

// the y-position of the currently highlighted tile, precisely on them screen (accounting for scroll)
// this means that if it's < 0 or > SCREEN_HEIGHT then it's not visible
int normalizedY = curTile->y + this->y;

// if we're out of range above, recenter at the top row
if (normalizedY < 0)
this->y = -1 * (curTile->y - 15) + 25;
// if we're FAR out of range upwards, speed up the scroll wheel (additive) to get back in range quicker
if (normalizedY < -200)
event->wheelScroll += 0.15;

// far out of range, for bottom of screen
else if (normalizedY > SCREEN_HEIGHT - curTile->height + 200)
event->wheelScroll -= 0.15;

// if we're slightly out of range above, recenter at the top row slowly
else if (normalizedY < -100)
event->wheelScroll = 1;

// special case, scroll when we're on the bottom row of the top of the not-yet-scrolled screen
else if (this->y == 0 && normalizedY > SCREEN_HEIGHT/2)
event->wheelScroll -= 0.5;

// if we're out of range below, recenter at bottom row
if (normalizedY > SCREEN_HEIGHT - curTile->height)
this->y = -1 * (curTile->y - 3 * (curTile->height - 15)) - 40;
else if (normalizedY > SCREEN_HEIGHT - curTile->height + 100)
event->wheelScroll = -1;

// if the card is this close to the top, just set it the list offset to 0 to scroll up to the top
if (this->highlighted < R)
this->y = 0;
else if (this->y != 0 && this->highlighted < R)
event->wheelScroll = 1;

if (this->elements[this->highlighted] && this->elements[this->highlighted]->elasticCounter == NO_HIGHLIGHT)
{
Expand Down
18 changes: 17 additions & 1 deletion gui/ThemeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ namespace HBAS::ThemeManager
{
void themeManagerInit()
{
bool canDetectDarkMode = false;

// Detect if Switch is using dark theme
#ifdef SWITCH
setsysInitialize();
static ColorSetId sysTheme = ColorSetId_Light;
setsysGetColorSetId(&sysTheme);
isDarkMode = (sysTheme == ColorSetId_Dark);
setsysExit();
canDetectDarkMode = true;
#endif

#ifdef __WIIU__
// TODO: Check if a custom dark theme is being used
#endif

#ifdef __APPLE__
if (system("defaults read -g AppleInterfaceStyle 2>/dev/null") == 0) {
isDarkMode = true;
}
canDetectDarkMode = true;
#endif

#ifdef _WIN32
Expand All @@ -33,9 +41,17 @@ namespace HBAS::ThemeManager
}
RegCloseKey(hKey);
}
canDetectDarkMode = true;
#endif

// TODO: check some preference to override the system theme
if (!canDetectDarkMode) {
// we can't detect dark mode on this platform, so let's check the time of day
time_t t = time(NULL);
struct tm *tm = localtime(&t);
isDarkMode = (tm->tm_hour < 5 || tm->tm_hour > 20);
}

// TODO: check some preference to override the automatic theme (system or time detection)

// Set colors for dark mode
if (isDarkMode)
Expand Down
2 changes: 1 addition & 1 deletion libs/chesto

0 comments on commit 274695e

Please sign in to comment.