From 545046971a7461550a18676b5bf99b561cbe919f Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 13 Aug 2020 14:08:23 +0200 Subject: [PATCH] Add a `getTextHeight` to the GuiText class --- include/gui/GuiText.h | 1 + source/gui/GuiText.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/gui/GuiText.h b/include/gui/GuiText.h index 83eb1e3..6ac7879 100644 --- a/include/gui/GuiText.h +++ b/include/gui/GuiText.h @@ -104,6 +104,7 @@ public: return maxWidth; } + float getTextHeight(); void setSSAA(int32_t ssaa) { this->internalSSAA = ssaa; diff --git a/source/gui/GuiText.cpp b/source/gui/GuiText.cpp index 46918bd..0dcc7fb 100644 --- a/source/gui/GuiText.cpp +++ b/source/gui/GuiText.cpp @@ -292,6 +292,18 @@ int32_t GuiText::getTextWidth() { res = res > maxWidth && maxWidth > 0 ? maxWidth : res; textMutex.unlock(); return res; +} + +float GuiText::getTextHeight() { + textMutex.lock(); + if (wrapMode == GuiText::WRAP && textDyn.empty()) { + if (maxWidth > 0 && font->getWidth(text, currentSize)) { + wrapText(); + } + } + + auto res = textDyn.empty() ? getLineHeight() : getLineHeight() * textDyn.size(); + textMutex.unlock(); return res; }