2020-06-28 16:39:18 +00:00
|
|
|
//
|
|
|
|
// TextComponent.h
|
|
|
|
//
|
|
|
|
// Displays text.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "resources/Font.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "GuiComponent.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);
|
|
|
|
TextComponent(
|
|
|
|
Window* window,
|
|
|
|
const std::string& text,
|
|
|
|
const std::shared_ptr<Font>& font,
|
|
|
|
unsigned int color = 0x000000FF,
|
|
|
|
Alignment align = ALIGN_LEFT,
|
|
|
|
Vector3f pos = Vector3f::Zero(),
|
|
|
|
Vector2f size = Vector2f::Zero(),
|
|
|
|
unsigned int bgcolor = 0x00000000);
|
|
|
|
|
|
|
|
void setFont(const std::shared_ptr<Font>& font);
|
|
|
|
void setUppercase(bool uppercase);
|
|
|
|
void onSizeChanged() override;
|
|
|
|
void setText(const std::string& text);
|
|
|
|
void setColor(unsigned int color) override;
|
|
|
|
void setHorizontalAlignment(Alignment align);
|
|
|
|
void setVerticalAlignment(Alignment align);
|
|
|
|
void setLineSpacing(float spacing);
|
|
|
|
void setBackgroundColor(unsigned int color);
|
|
|
|
void setRenderBackground(bool render);
|
|
|
|
|
|
|
|
unsigned int getColor() const override { return mColor; };
|
|
|
|
void render(const Transform4x4f& parentTrans) override;
|
|
|
|
|
|
|
|
std::string getValue() const override;
|
|
|
|
void setValue(const std::string& value) override;
|
|
|
|
|
|
|
|
unsigned char getOpacity() const override;
|
|
|
|
void setOpacity(unsigned char opacity) override;
|
|
|
|
|
|
|
|
inline std::shared_ptr<Font> getFont() const { return mFont; }
|
|
|
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
bool mRenderBackground;
|
|
|
|
|
|
|
|
bool mUppercase;
|
|
|
|
Vector2i mAutoCalcExtent;
|
|
|
|
std::shared_ptr<TextCache> mTextCache;
|
|
|
|
Alignment mHorizontalAlignment;
|
|
|
|
Alignment mVerticalAlignment;
|
|
|
|
float mLineSpacing;
|
2013-06-14 15:48:13 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|