From d7e09dfc49c5eaedd412f15727ea423b76a81abb Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 24 Oct 2022 22:58:27 -0700 Subject: [PATCH] Documented font --- src/dawn/ui/UILabel.cpp | 8 +++++++- src/dawn/ui/UILabel.hpp | 34 +++++++++++++++++++++++++++++++--- src/dawn/ui/UISprite.cpp | 2 -- src/dawn/ui/UISprite.hpp | 7 +++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/dawn/ui/UILabel.cpp b/src/dawn/ui/UILabel.cpp index 9106f9db..c3c071ca 100644 --- a/src/dawn/ui/UILabel.cpp +++ b/src/dawn/ui/UILabel.cpp @@ -11,6 +11,12 @@ UILabel::UILabel(UICanvas &canvas) : UIComponent(canvas) { } +void UILabel::updatePositions() { + UIComponent::updatePositions(); + + this->updateMesh(); +} + void UILabel::updateMesh() { if(!this->needsRebuffering) return; if(this->font == nullptr) return; @@ -18,7 +24,7 @@ void UILabel::updateMesh() { this->font->buffer( this->text, this->fontSize, - -1, + this->getWidth(), this->mesh, &this->measure ); diff --git a/src/dawn/ui/UILabel.hpp b/src/dawn/ui/UILabel.hpp index be2234bd..59539b98 100644 --- a/src/dawn/ui/UILabel.hpp +++ b/src/dawn/ui/UILabel.hpp @@ -18,19 +18,47 @@ namespace Dawn { std::string text = ""; float_t fontSize = 10.0f; + void updatePositions() override; + + /** + * Internal method to force the font mesh to be recreated. + */ void updateMesh(); public: + /** The colour of this label */ struct Color textColor = COLOR_MAGENTA; - - UILabel(UICanvas &canvas); + UILabel(UICanvas &canvas); + void drawSelf(UIShader &shader, glm::mat4 selfTransform); + + /** + * 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); - void drawSelf(UIShader &shader, glm::mat4 selfTransform); }; } \ No newline at end of file diff --git a/src/dawn/ui/UISprite.cpp b/src/dawn/ui/UISprite.cpp index d821d34b..9000919b 100644 --- a/src/dawn/ui/UISprite.cpp +++ b/src/dawn/ui/UISprite.cpp @@ -14,8 +14,6 @@ UISprite::UISprite(UICanvas &canvas) : UIComponent(canvas) { void UISprite::updatePositions() { UIComponent::updatePositions(); - std::cout << "Updating" << std::endl; - QuadMesh::bufferQuadMesh( this->mesh, glm::vec2(0, 0), glm::vec2(0, 0), diff --git a/src/dawn/ui/UISprite.hpp b/src/dawn/ui/UISprite.hpp index 286cf5e7..c3a71cd0 100644 --- a/src/dawn/ui/UISprite.hpp +++ b/src/dawn/ui/UISprite.hpp @@ -17,9 +17,12 @@ namespace Dawn { Mesh mesh; Texture *texture; + /** + * UI Sprite Constructor, use the UIElement / UIComponent create instead. + * + * @param canvas Canvas that this sprite belongs to. + */ UISprite(UICanvas &canvas); - - // void update() override; void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) override; }; } \ No newline at end of file