added tooltips

This commit is contained in:
MihailRis
2024-05-24 08:03:05 +03:00
parent 1c45236693
commit eb10904069
10 changed files with 146 additions and 11 deletions
+27 -4
View File
@@ -64,12 +64,28 @@ Label::Label(std::wstring text, std::string fontName)
cache.update(this->text, multiline, textWrap);
}
glm::vec2 Label::calcSize() {
auto font = cache.font;
uint lineHeight = font->getLineHeight();
if (cache.lines.size() > 1) {
lineHeight *= lineInterval;
}
return glm::vec2 (
cache.font->calcWidth(text),
lineHeight * cache.lines.size() + font->getYOffset()
);
}
void Label::setText(std::wstring text) {
if (text == this->text && !cache.resetFlag) {
return;
}
this->text = text;
cache.update(this->text, multiline, textWrap);
if (cache.font) {
setSize(calcSize());
}
}
const std::wstring& Label::getText() const {
@@ -156,10 +172,10 @@ void Label::draw(const DrawContext* pctx, Assets* assets) {
lineHeight *= lineInterval;
}
glm::vec2 size = getSize();
glm::vec2 newsize (
font->calcWidth(text),
lineHeight * cache.lines.size() + font->getYOffset()
);
glm::vec2 newsize = calcSize();
if (autoresize) {
setSize(newsize);
}
glm::vec2 pos = calcPos();
switch (align) {
@@ -194,6 +210,13 @@ void Label::textSupplier(wstringsupplier supplier) {
this->supplier = supplier;
}
void Label::setAutoResize(bool flag) {
this->autoresize = flag;
}
bool Label::isAutoResize() const {
return autoresize;
}
void Label::setMultiline(bool multiline) {
if (multiline != this->multiline) {