From a1ed59553f12f691b2ce48aee551d9e9a7e883b9 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 14 Oct 2021 21:29:23 +0200 Subject: [PATCH] Made it possible to set a 'a/select' help prompt for TextComponent. --- es-core/src/components/TextComponent.cpp | 58 ++++++++++++++---------- es-core/src/components/TextComponent.h | 5 ++ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index ad4dda89f..fa15ce628 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -13,18 +13,19 @@ #include "utils/StringUtil.h" TextComponent::TextComponent(Window* window) - : GuiComponent(window) - , mFont(Font::get(FONT_SIZE_MEDIUM)) - , mColor(0x000000FF) - , mBgColor(0) - , mMargin(0.0f) - , mRenderBackground(false) - , mUppercase(false) - , mAutoCalcExtent(true, true) - , mHorizontalAlignment(ALIGN_LEFT) - , mVerticalAlignment(ALIGN_CENTER) - , mLineSpacing(1.5f) - , mNoTopMargin(false) + : GuiComponent{window} + , mFont{Font::get(FONT_SIZE_MEDIUM)} + , mColor{0x000000FF} + , mBgColor{0} + , mMargin{0.0f} + , mRenderBackground{false} + , mUppercase{false} + , mAutoCalcExtent{1, 1} + , mHorizontalAlignment{ALIGN_LEFT} + , mVerticalAlignment{ALIGN_CENTER} + , mLineSpacing{1.5f} + , mNoTopMargin{false} + , mSelectable{false} { } @@ -37,18 +38,19 @@ TextComponent::TextComponent(Window* window, glm::vec2 size, unsigned int bgcolor, float margin) - : GuiComponent(window) - , mFont(nullptr) - , mColor(0x000000FF) - , mBgColor(0) - , mMargin(margin) - , mRenderBackground(false) - , mUppercase(false) - , mAutoCalcExtent(true, true) - , mHorizontalAlignment(align) - , mVerticalAlignment(ALIGN_CENTER) - , mLineSpacing(1.5f) - , mNoTopMargin(false) + : GuiComponent{window} + , mFont{nullptr} + , mColor{0x000000FF} + , mBgColor{0} + , mMargin{margin} + , mRenderBackground{false} + , mUppercase{false} + , mAutoCalcExtent{1, 1} + , mHorizontalAlignment{align} + , mVerticalAlignment{ALIGN_CENTER} + , mLineSpacing{1.5f} + , mNoTopMargin{false} + , mSelectable{false} { setFont(font); setColor(color); @@ -282,6 +284,14 @@ void TextComponent::setNoTopMargin(bool margin) onTextChanged(); } +std::vector TextComponent::getHelpPrompts() +{ + std::vector prompts; + if (mSelectable) + prompts.push_back(HelpPrompt("a", "select")); + return prompts; +} + void TextComponent::applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element, diff --git a/es-core/src/components/TextComponent.h b/es-core/src/components/TextComponent.h index 57a5561c5..cd07f5592 100644 --- a/es-core/src/components/TextComponent.h +++ b/es-core/src/components/TextComponent.h @@ -60,11 +60,15 @@ public: unsigned char getOpacity() const override { return mColor & 0x000000FF; } void setOpacity(unsigned char opacity) override; + void setSelectable(bool status) { mSelectable = status; } + virtual void applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element, unsigned int properties) override; + virtual std::vector getHelpPrompts() override; + unsigned int getColor() const override { return mColor; } std::shared_ptr getFont() const override { return mFont; } Alignment getHorizontalAlignment() { return mHorizontalAlignment; } @@ -95,6 +99,7 @@ private: Alignment mVerticalAlignment; float mLineSpacing; bool mNoTopMargin; + bool mSelectable; }; #endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H