2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-28 16:39:18 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-28 16:39:18 +00:00
|
|
|
// TextComponent.h
|
|
|
|
//
|
|
|
|
// Displays text.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "GuiComponent.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "resources/Font.h"
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2013-11-25 20:49:02 +00:00
|
|
|
class ThemeData;
|
|
|
|
|
2014-01-24 22:21:10 +00:00
|
|
|
// Used to display text.
|
|
|
|
// TextComponent::setSize(x, y) works a little differently than most components:
|
2020-06-28 16:39:18 +00:00
|
|
|
// * (0, 0) - Will automatically calculate a size that fits
|
|
|
|
// the text on one line (expand horizontally).
|
|
|
|
// * (x != 0, 0) - Wrap text so that it does not reach beyond x. Will
|
|
|
|
// automatically calculate a vertical size (expand vertically).
|
|
|
|
// * (x != 0, y <= fontHeight) - Will truncate text so it fits within this box.
|
2013-06-14 15:48:13 +00:00
|
|
|
class TextComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2020-06-28 16:39:18 +00:00
|
|
|
TextComponent(Window* window);
|
2021-07-07 18:31:46 +00:00
|
|
|
TextComponent(Window* window,
|
|
|
|
const std::string& text,
|
|
|
|
const std::shared_ptr<Font>& font,
|
|
|
|
unsigned int color = 0x000000FF,
|
|
|
|
Alignment align = ALIGN_LEFT,
|
2021-08-15 20:03:17 +00:00
|
|
|
glm::vec3 pos = {},
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec2 size = {},
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned int bgcolor = 0x00000000,
|
|
|
|
float margin = 0.0f);
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
void setFont(const std::shared_ptr<Font>& font);
|
|
|
|
void setUppercase(bool uppercase);
|
|
|
|
void onSizeChanged() override;
|
2021-09-28 19:46:45 +00:00
|
|
|
void setText(const std::string& text, bool update = true);
|
2021-07-07 18:31:46 +00:00
|
|
|
void setHiddenText(const std::string& text) { mHiddenText = text; }
|
2020-06-28 16:39:18 +00:00
|
|
|
void setColor(unsigned int color) override;
|
|
|
|
void setHorizontalAlignment(Alignment align);
|
2021-09-28 19:46:45 +00:00
|
|
|
void setVerticalAlignment(Alignment align) { mVerticalAlignment = align; }
|
2020-06-28 16:39:18 +00:00
|
|
|
void setLineSpacing(float spacing);
|
2021-09-30 18:11:56 +00:00
|
|
|
float getLineSpacing() override { return mLineSpacing; }
|
2021-03-13 15:52:15 +00:00
|
|
|
void setNoTopMargin(bool margin);
|
2020-06-28 16:39:18 +00:00
|
|
|
void setBackgroundColor(unsigned int color);
|
2021-07-07 18:31:46 +00:00
|
|
|
void setRenderBackground(bool render) { mRenderBackground = render; }
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
std::string getValue() const override { return mText; }
|
|
|
|
void setValue(const std::string& value) override { setText(value); }
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
std::string getHiddenValue() const override { return mHiddenText; }
|
|
|
|
void setHiddenValue(const std::string& value) override { setHiddenText(value); }
|
2020-11-07 11:50:30 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned char getOpacity() const override { return mColor & 0x000000FF; }
|
2020-06-28 16:39:18 +00:00
|
|
|
void setOpacity(unsigned char opacity) override;
|
|
|
|
|
2021-10-14 19:29:23 +00:00
|
|
|
void setSelectable(bool status) { mSelectable = status; }
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) override;
|
2014-01-01 05:39:22 +00:00
|
|
|
|
2021-10-14 19:29:23 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned int getColor() const override { return mColor; }
|
|
|
|
std::shared_ptr<Font> getFont() const override { return mFont; }
|
2021-03-21 10:50:13 +00:00
|
|
|
Alignment getHorizontalAlignment() { return mHorizontalAlignment; }
|
|
|
|
Alignment getVerticalAlignment() { return mVerticalAlignment; }
|
2021-01-13 18:48:31 +00:00
|
|
|
|
2018-10-13 01:08:15 +00:00
|
|
|
protected:
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual void onTextChanged();
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
std::string mText;
|
2020-11-07 11:50:30 +00:00
|
|
|
std::string mHiddenText;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
2018-10-13 01:08:15 +00:00
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
private:
|
2020-06-28 16:39:18 +00:00
|
|
|
void calculateExtent();
|
|
|
|
void onColorChanged();
|
|
|
|
|
|
|
|
unsigned int mColor;
|
|
|
|
unsigned int mBgColor;
|
|
|
|
unsigned char mColorOpacity;
|
|
|
|
unsigned char mBgColorOpacity;
|
2021-01-05 15:52:39 +00:00
|
|
|
float mMargin;
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mRenderBackground;
|
|
|
|
|
|
|
|
bool mUppercase;
|
2021-08-17 16:41:45 +00:00
|
|
|
glm::ivec2 mAutoCalcExtent;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<TextCache> mTextCache;
|
|
|
|
Alignment mHorizontalAlignment;
|
|
|
|
Alignment mVerticalAlignment;
|
|
|
|
float mLineSpacing;
|
2021-03-13 15:52:15 +00:00
|
|
|
bool mNoTopMargin;
|
2021-10-14 19:29:23 +00:00
|
|
|
bool mSelectable;
|
2013-06-14 15:48:13 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|