Skip to content

Commit cee22aa

Browse files
author
Joachim Meyer
committed
Fix getHeight() - it now more looks for the highest label but for the whole height of the UIMultilineLabel.
1 parent 49b533b commit cee22aa

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Modules/Contents/UI/Include/PolyUIElement.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ namespace Polycode {
166166
String labelFontName;
167167
int labelAAMode;
168168
int spacing;
169-
169+
int linesCount;
170+
170171
void clearLabels();
171172
std::vector<UILabel*> labels;
172173
};

Modules/Contents/UI/Source/PolyUIElement.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ void UIMultilineLabel::setText(const String& text) {
4242
clearLabels();
4343

4444
std::vector<String> lines = text.split("\n");
45-
46-
Number lineSize = spacing;
45+
linesCount = lines.size();
46+
47+
Number lineSize = spacing;
4748
Number yPos = 0.0;
4849
for(int i=0; i < lines.size(); i++) {
4950
if(lines[i] == "") {
@@ -107,13 +108,12 @@ Number UIMultilineLabel::getWidth(){
107108
}
108109

109110
Number UIMultilineLabel::getHeight(){
110-
Number maxHeight = 0;
111+
Number retHeight = 0;
111112
for (int i = 0; i < labels.size(); i++) {
112-
if (labels[i]->getHeight() > maxHeight){
113-
maxHeight = labels[i]->getHeight();
114-
}
113+
retHeight += labels[i]->getHeight() + spacing;
115114
}
116-
return maxHeight;
115+
retHeight += (linesCount - labels.size()) * (labelSize + spacing);
116+
return retHeight;
117117
}
118118

119119
UIMultilineLabel::~UIMultilineLabel() {

0 commit comments

Comments
 (0)