// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "scene/components/ui/UIComponentRenderable.hpp" #include "display/mesh/QuadMesh.hpp" #include "asset/assets/TrueTypeAsset.hpp" #include "util/Xml.hpp" #define UI_LABEL_MAX_WIDTH_NONE -1 namespace Dawn { struct UILabelStyle { struct Color color = COLOR_WHITE; flag_t style = 0; flag_t decorations = 0; uint32_t size = 16; TrueTypeAsset *font = nullptr; }; struct UILabelText { std::string text; struct UILabelStyle style; int32_t lineStart = 0; int32_t lineCount = 0; usagelockid_t lockId = -1; struct TrueTypeFaceTexture *texture = nullptr; }; struct UILabelLine { float_t width = 0.0f; float_t height = 0.0f; glm::vec2 position; int32_t quadStart = -1; int32_t quadCount = 0; }; enum UILabelVerticalAlign { UI_LABEL_VERTICAL_ALIGN_TOP, UI_LABEL_VERTICAL_ALIGN_MIDDLE, UI_LABEL_VERTICAL_ALIGN_BOTTOM }; enum UILabelTextAlign { UI_LABEL_TEXT_ALIGN_LEFT, UI_LABEL_TEXT_ALIGN_CENTER, UI_LABEL_TEXT_ALIGN_RIGHT // TODO: Add justify }; class UILabel : public UIComponentRenderable { private: Mesh mesh; Mesh meshDecorations; FontShaderBuffer shaderBuffer; std::map textureMap; bool_t ignoreAlignmentUpdate = false; bool_t hasDecorations = false; void updateTextAlignments(); public: int32_t quadStart = 0; int32_t quadCount = -1; int32_t quadCountTotal = -1; glm::vec2 textOffset = glm::vec2(0.0f, 0.0f); std::vector texts; std::vector textsBuffered; std::vector lines; StateEvent<> eventTextChanged; // @optional StateProperty lineHeight; // @optional StateProperty textAlign; UILabel(SceneItem *item); void onStart() override; std::vector getUIRenderPasses() override; float_t getContentWidth() override; float_t getContentHeight() override; /** * Rebuffer the quads for this label. This method will perform all the * necessary difference calculations from where the current state of this text is. * * @param texts Texts to buffer. */ void rebufferQuads(std::vector texts); }; }