Added scrollable text container support to the system view

This commit is contained in:
Leon Styhre 2023-03-26 19:38:30 +02:00
parent 8545c619ed
commit 5bffcf887c
2 changed files with 78 additions and 8 deletions

View file

@ -160,6 +160,9 @@ void SystemView::update(int deltaTime)
for (auto& anim : mSystemElements[mPrimary->getCursor()].GIFAnimComponents) for (auto& anim : mSystemElements[mPrimary->getCursor()].GIFAnimComponents)
anim->update(deltaTime); anim->update(deltaTime);
for (auto& container : mSystemElements[mPrimary->getCursor()].containerComponents)
container->update(deltaTime);
GuiComponent::update(deltaTime); GuiComponent::update(deltaTime);
} }
@ -279,6 +282,9 @@ void SystemView::onCursorChanged(const CursorState& state)
video->pauseVideoPlayer(); video->pauseVideoPlayer();
} }
for (auto& container : mSystemElements[mPrimary->getCursor()].containerComponents)
container->reset();
// This is needed to avoid erratic camera movements during extreme navigation input when using // This is needed to avoid erratic camera movements during extreme navigation input when using
// slide transitions. This should very rarely occur during normal application usage. // slide transitions. This should very rarely occur during normal application usage.
if (transitionAnim == ViewTransitionAnimation::SLIDE) { if (transitionAnim == ViewTransitionAnimation::SLIDE) {
@ -651,9 +657,19 @@ void SystemView::populate()
else if (element.second.type == "text" && else if (element.second.type == "text" &&
!(element.second.has("visible") && !(element.second.has("visible") &&
!element.second.get<bool>("visible"))) { !element.second.get<bool>("visible"))) {
// Set as container by default if metadata type is "description".
bool container {false};
if (element.second.has("container")) {
container = element.second.get<bool>("container");
}
else if (element.second.has("metadata") &&
element.second.get<std::string>("metadata") == "description") {
container = true;
}
if (element.second.has("systemdata") && if (element.second.has("systemdata") &&
element.second.get<std::string>("systemdata").substr(0, 9) == element.second.get<std::string>("systemdata").substr(0, 9) ==
"gamecount") { "gamecount") {
// A container can't be used if systemdata is set to a gamecount value.
if (element.second.has("systemdata")) { if (element.second.has("systemdata")) {
elements.gameCountComponents.emplace_back( elements.gameCountComponents.emplace_back(
std::make_unique<TextComponent>()); std::make_unique<TextComponent>());
@ -665,11 +681,39 @@ void SystemView::populate()
} }
} }
else { else {
elements.textComponents.emplace_back(std::make_unique<TextComponent>()); if (container) {
elements.textComponents.back()->setDefaultZIndex(40.0f); elements.containerComponents.push_back(
elements.textComponents.back()->applyTheme( std::make_unique<ScrollableContainer>());
theme, "system", element.first, ThemeFlags::ALL); elements.containerComponents.back()->setDefaultZIndex(40.0f);
elements.children.emplace_back(elements.textComponents.back().get()); elements.containerTextComponents.push_back(
std::make_unique<TextComponent>());
elements.containerTextComponents.back()->setDefaultZIndex(40.0f);
elements.containerComponents.back()->addChild(
elements.containerTextComponents.back().get());
elements.containerComponents.back()->applyTheme(
theme, "system", element.first,
ThemeFlags::POSITION | ThemeFlags::SIZE | ThemeFlags::Z_INDEX |
ThemeFlags::VISIBLE);
elements.containerComponents.back()->setAutoScroll(true);
elements.containerTextComponents.back()->setSize(
elements.containerComponents.back()->getSize().x, 0.0f);
elements.containerTextComponents.back()->applyTheme(
theme, "system", element.first,
ThemeFlags::ALL ^ ThemeFlags::POSITION ^ ThemeFlags::ORIGIN ^
ThemeFlags::Z_INDEX ^ ThemeFlags::SIZE ^
ThemeFlags::VISIBLE ^ ThemeFlags::ROTATION);
elements.children.emplace_back(
elements.containerComponents.back().get());
}
else {
elements.textComponents.emplace_back(
std::make_unique<TextComponent>());
elements.textComponents.back()->setDefaultZIndex(40.0f);
elements.textComponents.back()->applyTheme(
theme, "system", element.first, ThemeFlags::ALL);
elements.children.emplace_back(
elements.textComponents.back().get());
}
} }
} }
else if (element.second.type == "datetime" && else if (element.second.type == "datetime" &&
@ -712,6 +756,12 @@ void SystemView::populate()
const std::unique_ptr<TextComponent>& b) { const std::unique_ptr<TextComponent>& b) {
return b->getZIndex() > a->getZIndex(); return b->getZIndex() > a->getZIndex();
}); });
std::stable_sort(elements.containerTextComponents.begin(),
elements.containerTextComponents.end(),
[](const std::unique_ptr<TextComponent>& a,
const std::unique_ptr<TextComponent>& b) {
return b->getZIndex() > a->getZIndex();
});
mSystemElements.emplace_back(std::move(elements)); mSystemElements.emplace_back(std::move(elements));
mSystemElements.back().helpStyle.applyTheme(theme, "system"); mSystemElements.back().helpStyle.applyTheme(theme, "system");
} }
@ -818,6 +868,16 @@ void SystemView::populate()
text->setValue(text->getThemeSystemdata()); text->setValue(text->getThemeSystemdata());
} }
} }
for (auto& containerText : elements.containerTextComponents) {
if (containerText->getThemeSystemdata() != "") {
if (containerText->getThemeSystemdata() == "name")
containerText->setValue(elements.name);
else if (containerText->getThemeSystemdata() == "fullname")
containerText->setValue(elements.fullName);
else
containerText->setValue(containerText->getThemeSystemdata());
}
}
} }
if (mPrimary->getNumEntries() == 0) { if (mPrimary->getNumEntries() == 0) {
@ -1192,9 +1252,10 @@ void SystemView::updateGameSelectors()
} }
} }
for (auto& text : mSystemElements[cursor].textComponents) { auto textSelectorFunc = [this, cursor,
multipleSelectors](std::unique_ptr<TextComponent>& text) {
if (text->getThemeMetadata() == "") if (text->getThemeMetadata() == "")
continue; return;
GameSelectorComponent* gameSelector {nullptr}; GameSelectorComponent* gameSelector {nullptr};
if (multipleSelectors) { if (multipleSelectors) {
const std::string& textSelector {text->getThemeGameSelector()}; const std::string& textSelector {text->getThemeGameSelector()};
@ -1316,7 +1377,13 @@ void SystemView::updateGameSelectors()
else { else {
text->setValue(""); text->setValue("");
} }
} };
for (auto& text : mSystemElements[cursor].textComponents)
textSelectorFunc(text);
for (auto& containerText : mSystemElements[cursor].containerTextComponents)
textSelectorFunc(containerText);
for (auto& dateTime : mSystemElements[cursor].dateTimeComponents) { for (auto& dateTime : mSystemElements[cursor].dateTimeComponents) {
if (dateTime->getThemeMetadata() == "") if (dateTime->getThemeMetadata() == "")

View file

@ -18,6 +18,7 @@
#include "components/GameSelectorComponent.h" #include "components/GameSelectorComponent.h"
#include "components/LottieAnimComponent.h" #include "components/LottieAnimComponent.h"
#include "components/RatingComponent.h" #include "components/RatingComponent.h"
#include "components/ScrollableContainer.h"
#include "components/TextComponent.h" #include "components/TextComponent.h"
#include "components/VideoFFmpegComponent.h" #include "components/VideoFFmpegComponent.h"
#include "components/primary/CarouselComponent.h" #include "components/primary/CarouselComponent.h"
@ -123,6 +124,8 @@ private:
std::vector<std::unique_ptr<VideoFFmpegComponent>> videoComponents; std::vector<std::unique_ptr<VideoFFmpegComponent>> videoComponents;
std::vector<std::unique_ptr<LottieAnimComponent>> lottieAnimComponents; std::vector<std::unique_ptr<LottieAnimComponent>> lottieAnimComponents;
std::vector<std::unique_ptr<GIFAnimComponent>> GIFAnimComponents; std::vector<std::unique_ptr<GIFAnimComponent>> GIFAnimComponents;
std::vector<std::unique_ptr<ScrollableContainer>> containerComponents;
std::vector<std::unique_ptr<TextComponent>> containerTextComponents;
std::vector<std::unique_ptr<TextComponent>> gameCountComponents; std::vector<std::unique_ptr<TextComponent>> gameCountComponents;
std::vector<std::unique_ptr<TextComponent>> textComponents; std::vector<std::unique_ptr<TextComponent>> textComponents;
std::vector<std::unique_ptr<DateTimeComponent>> dateTimeComponents; std::vector<std::unique_ptr<DateTimeComponent>> dateTimeComponents;