Dawn/src/dawn/ui/UILabel.hpp

73 lines
1.7 KiB
C++

// 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 text = "";
float_t fontSize = 10.0f;
void updatePositions() override;
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;
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();
/**
* Returns the current text that the label has.
*
* @return The current label string.
*/
std::string getText();
/**
* 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 text Text for the label to use.
*/
void setText(std::string text);
/**
* Sets / Updates the font size for the label.
*
* @param fontSize Font size to use.
*/
void setFontSize(float_t fontSize);
};
}