Bugfixing and refactoring - proper menu icons

This commit is contained in:
jpirnay
2026-04-03 11:03:10 +02:00
parent adc4efa9e6
commit 01d05e654d
14 changed files with 466 additions and 490 deletions
+1 -1
View File
@@ -230,7 +230,7 @@ void HomeActivity::render(RenderLock&&) {
// Build menu items dynamically
std::vector<const char*> menuItems = {tr(STR_BROWSE_FILES), tr(STR_MENU_RECENT_BOOKS), tr(STR_FILE_TRANSFER),
tr(STR_WEATHER), tr(STR_SETTINGS_TITLE)};
std::vector<UIIcon> menuIcons = {Folder, Recent, Transfer, Library, Settings};
std::vector<UIIcon> menuIcons = {Folder, Recent, Transfer, Weather, Settings};
if (hasOpdsUrl) {
// Insert OPDS Browser after Recents (before File Transfer)
+10 -10
View File
@@ -124,8 +124,8 @@ void WeatherActivity::onEnter() {
void WeatherActivity::onExit() {
Activity::onExit();
// Restore orientation from settings
renderer.setOrientation(static_cast<GfxRenderer::Orientation>(SETTINGS.orientation));
// Weather screen is always landscape; restore app UI to portrait on exit.
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
WiFi.mode(WIFI_OFF);
}
@@ -405,12 +405,12 @@ void WeatherActivity::renderCurrentConditions(int x, int y, int w, int h) {
textY += 15;
}
// Weather icon (WEATHER_ICON_LARGE x WEATHER_ICON_LARGE)
// Weather icon (WEATHER_ICON_SIZE x WEATHER_ICON_SIZE)
auto iconType = getWeatherIconType(cur.weatherCode, cur.isDay);
const uint8_t* icon = getWeatherIconLarge(iconType);
int iconX = x + (w - WEATHER_ICON_LARGE) / 2;
drawWeatherIconWithOrientation(renderer, icon, iconX, textY + 2, WEATHER_ICON_LARGE);
textY += WEATHER_ICON_LARGE + 5;
int iconX = x + (w - WEATHER_ICON_SIZE) / 2;
drawWeatherIconWithOrientation(renderer, icon, iconX, textY + 2, WEATHER_ICON_SIZE);
textY += WEATHER_ICON_SIZE + 5;
// Temperature (large)
char tempBuf[16];
@@ -528,12 +528,12 @@ void WeatherActivity::renderDailyForecast(int x, int y, int w, int h) {
renderer.drawText(SMALL_FONT_ID, cardX + (cardWidth - dateWidth) / 2, textY, dateBuf);
textY += 18;
// Weather icon (WEATHER_ICON_LARGE for all days)
// Weather icon (WEATHER_ICON_SIZE for all days)
auto iconType = getWeatherIconType(day.weatherCode, true);
const uint8_t* icon = getWeatherIconLarge(iconType);
int iconX = cardX + (cardWidth - WEATHER_ICON_LARGE) / 2;
drawWeatherIconWithOrientation(renderer, icon, iconX, textY, WEATHER_ICON_LARGE);
textY += WEATHER_ICON_LARGE + 8;
int iconX = cardX + (cardWidth - WEATHER_ICON_SIZE) / 2;
drawWeatherIconWithOrientation(renderer, icon, iconX, textY, WEATHER_ICON_SIZE);
textY += WEATHER_ICON_SIZE + 8;
// Weather description (short)
const char* desc = I18N.get(getWeatherDescriptionStrId(day.weatherCode));
@@ -55,12 +55,15 @@ void WeatherSettingsActivity::loop() {
}
buttonNavigator.onNext([this] {
selectedIndex = (selectedIndex + 1) % searchResults.size();
if (searchResults.empty()) return;
selectedIndex = (selectedIndex + 1) % static_cast<int>(searchResults.size());
requestUpdate();
});
buttonNavigator.onPrevious([this] {
selectedIndex = (selectedIndex + searchResults.size() - 1) % searchResults.size();
if (searchResults.empty()) return;
const int size = static_cast<int>(searchResults.size());
selectedIndex = (selectedIndex + size - 1) % size;
requestUpdate();
});
return;
@@ -24,13 +24,15 @@ class WeatherSettingsActivity final : public Activity {
private:
ButtonNavigator buttonNavigator;
size_t selectedIndex = 0;
int selectedIndex = 0;
// City search results (populated when user searches)
std::vector<GeocodingResult> searchResults;
bool showingSearchResults = false;
bool searchInProgress = false;
std::string searchQuery;
static constexpr size_t MENU_ITEMS = 6; // Location, Lat, Lon, TempUnit, WindUnit, PrecipUnit
static constexpr int MENU_ITEMS = 6; // Location, Lat, Lon, TempUnit, WindUnit, PrecipUnit
void handleSelection();
void launchCitySearch();
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include <cstdint>
// 24x24 weather icon generated from assets/weather-icons/svg/wi-day-sunny.svg
static const uint8_t Weather24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 0xC7, 0xE3, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xF0, 0x0F, 0xFF, 0xFE, 0x7C, 0x3E,
0x7F, 0xFC, 0x7F, 0xFE, 0x3F, 0xF8, 0xFF, 0xFF, 0x1F, 0xF9, 0xFF, 0xFF, 0x9F, 0xFB, 0xFE, 0x7F, 0xDF, 0xFF, 0xFE,
0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF,
};
+1 -1
View File
@@ -64,7 +64,7 @@ struct ThemeMetrics {
bool keyboardCenteredText;
};
enum UIIcon { Folder, Text, Image, Book, File, Recent, Settings, Transfer, Library, Wifi, Hotspot };
enum UIIcon { Folder, Text, Image, Book, File, Recent, Settings, Transfer, Library, Wifi, Hotspot, Weather };
// Default theme implementation (Classic Theme)
// Additional themes can inherit from this and override methods as needed
+15 -3
View File
@@ -25,6 +25,8 @@
#include "components/icons/settings2.h"
#include "components/icons/text24.h"
#include "components/icons/transfer.h"
#include "components/icons/weather24.h"
#include "components/icons/weather32.h"
#include "components/icons/wifi.h"
#include "fontIds.h"
@@ -97,6 +99,8 @@ const uint8_t* iconForName(UIIcon icon, int size) {
return Book24Icon;
case UIIcon::File:
return File24Icon;
case UIIcon::Weather:
return Weather24Icon;
default:
return nullptr;
}
@@ -118,6 +122,8 @@ const uint8_t* iconForName(UIIcon icon, int size) {
return WifiIcon;
case UIIcon::Hotspot:
return HotspotIcon;
case UIIcon::Weather:
return Weather32Icon;
default:
return nullptr;
}
@@ -530,10 +536,16 @@ void LyraTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount
if (rowIcon != nullptr) {
UIIcon icon = rowIcon(i);
const uint8_t* iconBitmap = iconForName(icon, mainMenuIconSize);
int iconSize = mainMenuIconSize;
const uint8_t* iconBitmap = iconForName(icon, iconSize);
if (iconBitmap == nullptr) {
// Some icons only have 24px variants; fall back so they still render.
iconSize = listIconSize;
iconBitmap = iconForName(icon, iconSize);
}
if (iconBitmap != nullptr) {
renderer.drawIcon(iconBitmap, textX, textY + 3, mainMenuIconSize, mainMenuIconSize);
textX += mainMenuIconSize + hPaddingInSelection + 2;
renderer.drawIcon(iconBitmap, textX, textY + 3, iconSize, iconSize);
textX += iconSize + hPaddingInSelection + 2;
}
}