652: cleanup code, theme tags

This commit is contained in:
shadash 2021-11-05 10:26:14 +01:00 committed by Sophia Hadash
parent b822aea514
commit 761b086331
2 changed files with 23 additions and 18 deletions

View file

@ -56,17 +56,16 @@ void SystemView::populate()
{ {
mEntries.clear(); mEntries.clear();
for (auto it = SystemData::sSystemVector.cbegin(); // Line break. for (auto it : SystemData::sSystemVector) {
it != SystemData::sSystemVector.cend(); it++) { const std::shared_ptr<ThemeData>& theme = it->getTheme();
const std::shared_ptr<ThemeData>& theme = (*it)->getTheme();
if (mViewNeedsReload) if (mViewNeedsReload)
getViewElements(theme); getViewElements(theme);
if ((*it)->isVisible()) { if (it->isVisible()) {
Entry e; Entry e;
e.name = (*it)->getName(); e.name = it->getName();
e.object = *it; e.object = it;
// Component offset. Used for positioning placeholders. // Component offset. Used for positioning placeholders.
glm::vec3 offsetLogo = {0.0f, 0.0f, 0.0f}; glm::vec3 offsetLogo = {0.0f, 0.0f, 0.0f};
@ -75,13 +74,13 @@ void SystemView::populate()
// Make logo. // Make logo.
const ThemeData::ThemeElement* logoElem = theme->getElement("system", "logo", "image"); const ThemeData::ThemeElement* logoElem = theme->getElement("system", "logo", "image");
if (logoElem) { if (logoElem) {
std::string path = logoElem->get<std::string>("path"); auto path = logoElem->get<std::string>("path");
std::string defaultPath = std::string defaultPath =
logoElem->has("default") ? logoElem->get<std::string>("default") : ""; logoElem->has("default") ? logoElem->get<std::string>("default") : "";
if ((!path.empty() && ResourceManager::getInstance()->fileExists(path)) || if ((!path.empty() && ResourceManager::getInstance()->fileExists(path)) ||
(!defaultPath.empty() && (!defaultPath.empty() &&
ResourceManager::getInstance()->fileExists(defaultPath))) { ResourceManager::getInstance()->fileExists(defaultPath))) {
ImageComponent* logo = new ImageComponent(mWindow, false, false); auto* logo = new ImageComponent(mWindow, false, false);
logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale); logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale);
logo->applyTheme(theme, "system", "logo", ThemeFlags::PATH | ThemeFlags::COLOR); logo->applyTheme(theme, "system", "logo", ThemeFlags::PATH | ThemeFlags::COLOR);
logo->setRotateByTargetSize(true); logo->setRotateByTargetSize(true);
@ -97,8 +96,7 @@ void SystemView::populate()
glm::vec3 center = {resolution.x / 2.0f, resolution.y / 2.0f, 1.0f}; glm::vec3 center = {resolution.x / 2.0f, resolution.y / 2.0f, 1.0f};
// Placeholder Image. // Placeholder Image.
const ThemeData::ThemeElement* logoElem = logoElem = theme->getElement("system", "logoPlaceholderImage", "image");
theme->getElement("system", "logoPlaceholderImage", "image");
if (logoElem) { if (logoElem) {
auto path = logoElem->get<std::string>("path"); auto path = logoElem->get<std::string>("path");
std::string defaultPath = std::string defaultPath =
@ -106,7 +104,7 @@ void SystemView::populate()
if ((!path.empty() && ResourceManager::getInstance()->fileExists(path)) || if ((!path.empty() && ResourceManager::getInstance()->fileExists(path)) ||
(!defaultPath.empty() && (!defaultPath.empty() &&
ResourceManager::getInstance()->fileExists(defaultPath))) { ResourceManager::getInstance()->fileExists(defaultPath))) {
ImageComponent* logo = new ImageComponent(mWindow, false, false); auto* logo = new ImageComponent(mWindow, false, false);
logo->applyTheme(theme, "system", "logoPlaceholderImage", ThemeFlags::ALL); logo->applyTheme(theme, "system", "logoPlaceholderImage", ThemeFlags::ALL);
if (!logoElem->has("size")) if (!logoElem->has("size"))
logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale); logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale);
@ -122,7 +120,7 @@ void SystemView::populate()
if (logoPlaceholderText) { if (logoPlaceholderText) {
// Element 'logoPlaceholderText' found in theme: place text // Element 'logoPlaceholderText' found in theme: place text
auto* text = auto* text =
new TextComponent(mWindow, (*it)->getName(), Font::get(FONT_SIZE_LARGE), new TextComponent(mWindow, it->getName(), Font::get(FONT_SIZE_LARGE),
0x000000FF, ALIGN_CENTER); 0x000000FF, ALIGN_CENTER);
text->setSize(mCarousel.logoSize * mCarousel.logoScale); text->setSize(mCarousel.logoSize * mCarousel.logoScale);
if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL) { if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL) {
@ -133,7 +131,7 @@ void SystemView::populate()
text->setHorizontalAlignment(ALIGN_CENTER); text->setHorizontalAlignment(ALIGN_CENTER);
text->setVerticalAlignment(mCarousel.logoAlignment); text->setVerticalAlignment(mCarousel.logoAlignment);
} }
text->applyTheme((*it)->getTheme(), "system", "logoPlaceholderText", text->applyTheme(it->getTheme(), "system", "logoPlaceholderText",
ThemeFlags::ALL); ThemeFlags::ALL);
if (!e.data.logo) { if (!e.data.logo) {
e.data.logo = std::shared_ptr<GuiComponent>(text); e.data.logo = std::shared_ptr<GuiComponent>(text);
@ -146,11 +144,11 @@ void SystemView::populate()
} }
else { else {
// Fallback to legacy centered placeholder text. // Fallback to legacy centered placeholder text.
TextComponent* text = auto* text =
new TextComponent(mWindow, (*it)->getName(), Font::get(FONT_SIZE_LARGE), new TextComponent(mWindow, it->getName(), Font::get(FONT_SIZE_LARGE),
0x000000FF, ALIGN_CENTER); 0x000000FF, ALIGN_CENTER);
text->setSize(mCarousel.logoSize * mCarousel.logoScale); text->setSize(mCarousel.logoSize * mCarousel.logoScale);
text->applyTheme((*it)->getTheme(), "system", "logoText", text->applyTheme(it->getTheme(), "system", "logoText",
ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE |
ThemeFlags::COLOR | ThemeFlags::FORCE_UPPERCASE | ThemeFlags::COLOR | ThemeFlags::FORCE_UPPERCASE |
ThemeFlags::LINE_SPACING | ThemeFlags::TEXT); ThemeFlags::LINE_SPACING | ThemeFlags::TEXT);
@ -192,7 +190,7 @@ void SystemView::populate()
v + offsetLogoPlaceholderText); v + offsetLogoPlaceholderText);
// Make background extras. // Make background extras.
e.data.backgroundExtras = ThemeData::makeExtras((*it)->getTheme(), "system", mWindow); e.data.backgroundExtras = ThemeData::makeExtras(it->getTheme(), "system", mWindow);
// Sort the extras by z-index. // Sort the extras by z-index.
std::stable_sort( std::stable_sort(
@ -202,7 +200,7 @@ void SystemView::populate()
this->add(e); this->add(e);
} }
} }
if (mEntries.size() == 0) { if (mEntries.empty()) {
// Something is wrong, there is not a single system to show, check if UI mode is not full. // Something is wrong, there is not a single system to show, check if UI mode is not full.
if (!UIModeController::getInstance()->isUIModeFull()) { if (!UIModeController::getInstance()->isUIModeFull()) {
Settings::getInstance()->setString("UIMode", "full"); Settings::getInstance()->setString("UIMode", "full");

View file

@ -21,6 +21,13 @@ based on: 'recalbox-multi' by the Recalbox community
<fontPath>./core/fonts/Exo2-RegularCondensed.otf</fontPath> <fontPath>./core/fonts/Exo2-RegularCondensed.otf</fontPath>
<fontSize>0.035</fontSize> <fontSize>0.035</fontSize>
</text> </text>
<text name="logoPlaceholderText">
<fontPath>./core/fonts/Exo2-RegularCondensed.otf</fontPath>
<fontSize>0.035</fontSize>
<color>000000FF</color>
<pos>0 0</pos>
<size>.2 .2</size>
</text>
</view> </view>
</feature> </feature>