// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "UIComponent.hpp" #include "display/mesh/QuadMesh.hpp" #include "display/font/Font.hpp" namespace Dawn { class UILabel : public UIComponent { private: Mesh mesh; bool_t needsRebuffering = true; Font *font = nullptr; std::string key = ""; float_t fontSize = 10.0f; bool_t hasText = false; void updatePositions() override; /** Event for when the language strings are updated */ void onLanguageUpdated(); public: struct FontMeasure measure; int32_t startQuad = 0; int32_t quadCount = -1; /** The colour of this label */ struct Color textColor = COLOR_MAGENTA; UILabel(UICanvas *canvas); void drawSelf(UIShader *shader, glm::mat4 selfTransform) override; virtual float_t getContentWidth() override; virtual float_t getContentHeight() override; void setTransform( UIComponentAlign xAlign, UIComponentAlign yAlign, glm::vec4 alignment, float_t z ) override; /** * Internal method to force the font mesh to be recreated. */ void updateMesh(); /** * Set the font to use for the label. * * @param font Font to use. */ void setFont(Font *font); /** * Sets the text for the label to use. * * @param key Localzied string key for the label to use. */ void setText(std::string key); /** * Sets / Updates the font size for the label. * * @param fontSize Font size to use. */ void setFontSize(float_t fontSize); ~UILabel(); }; }