ScrollableContainer parameters are now themeable.

This commit is contained in:
Leon Styhre 2022-02-10 20:02:56 +01:00
parent 788c9a3f58
commit 28a3beb9ce
4 changed files with 38 additions and 2 deletions

View file

@ -135,7 +135,6 @@ void GamelistView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
else if (element.second.type == "text") { else if (element.second.type == "text") {
if (element.second.has("container") && element.second.get<bool>("container")) { if (element.second.has("container") && element.second.get<bool>("container")) {
mContainerComponents.push_back(std::make_unique<ScrollableContainer>()); mContainerComponents.push_back(std::make_unique<ScrollableContainer>());
mContainerComponents.back()->setAutoScroll(true);
mContainerComponents.back()->setDefaultZIndex(40.0f); mContainerComponents.back()->setDefaultZIndex(40.0f);
addChild(mContainerComponents.back().get()); addChild(mContainerComponents.back().get());
mContainerTextComponents.push_back(std::make_unique<TextComponent>()); mContainerTextComponents.push_back(std::make_unique<TextComponent>());
@ -144,11 +143,12 @@ void GamelistView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
mContainerComponents.back()->applyTheme(theme, "gamelist", element.first, mContainerComponents.back()->applyTheme(theme, "gamelist", element.first,
POSITION | ThemeFlags::SIZE | Z_INDEX | POSITION | ThemeFlags::SIZE | Z_INDEX |
VISIBLE); VISIBLE);
mContainerComponents.back()->setAutoScroll(true);
mContainerTextComponents.back()->setSize( mContainerTextComponents.back()->setSize(
mContainerComponents.back()->getSize().x, 0.0f); mContainerComponents.back()->getSize().x, 0.0f);
mContainerTextComponents.back()->applyTheme( mContainerTextComponents.back()->applyTheme(
theme, "gamelist", element.first, theme, "gamelist", element.first,
(ALL ^ POSITION ^ Z_INDEX ^ ThemeFlags::SIZE ^ VISIBLE ^ ROTATION) | COLOR); ALL ^ POSITION ^ Z_INDEX ^ ThemeFlags::SIZE ^ VISIBLE ^ ROTATION);
mContainerComponents.back()->setScrollHide(true); mContainerComponents.back()->setScrollHide(true);
} }
else { else {

View file

@ -145,6 +145,9 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"text", STRING}, {"text", STRING},
{"metadata", STRING}, {"metadata", STRING},
{"container", BOOLEAN}, {"container", BOOLEAN},
{"containerScrollSpeed", FLOAT},
{"containerStartDelay", FLOAT},
{"containerResetDelay", FLOAT},
{"fontPath", PATH}, {"fontPath", PATH},
{"fontSize", FLOAT}, {"fontSize", FLOAT},
{"alignment", STRING}, {"alignment", STRING},

View file

@ -77,6 +77,34 @@ void ScrollableContainer::reset()
} }
} }
void ScrollableContainer::applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,
const std::string& element,
unsigned int properties)
{
using namespace ThemeFlags;
GuiComponent::applyTheme(theme, view, element, properties);
const ThemeData::ThemeElement* elem {theme->getElement(view, element, "text")};
if (!elem || !elem->has("container"))
return;
if (elem->has("containerScrollSpeed")) {
mAutoScrollSpeedConstant =
AUTO_SCROLL_SPEED / glm::clamp(elem->get<float>("containerScrollSpeed"), 0.1f, 10.0f);
}
if (elem->has("containerStartDelay")) {
mAutoScrollDelayConstant =
glm::clamp(elem->get<float>("containerStartDelay"), 0.0f, 10.0f) * 1000.0f;
}
if (elem->has("containerResetDelay")) {
mAutoScrollResetDelayConstant =
glm::clamp(elem->get<float>("containerResetDelay"), 0.0f, 20.0f) * 1000.0f;
}
}
void ScrollableContainer::update(int deltaTime) void ScrollableContainer::update(int deltaTime)
{ {
if (mSize == glm::vec2 {0.0f, 0.0f}) if (mSize == glm::vec2 {0.0f, 0.0f})

View file

@ -33,6 +33,11 @@ public:
float autoScrollSpeedConstant) override; float autoScrollSpeedConstant) override;
void reset(); void reset();
void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view,
const std::string& element,
unsigned int properties) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const glm::mat4& parentTrans) override; void render(const glm::mat4& parentTrans) override;