Skip to content

Commit 49b533b

Browse files
author
Joachim Meyer
committed
Fix UIMultilineLabels to return the correct width and height.
1 parent 6bea25d commit 49b533b

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

Modules/Contents/UI/Include/PolyUIElement.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ namespace Polycode {
149149
*/
150150
void setColor(Color color);
151151

152+
/**
153+
* @return the max width as a Number
154+
*/
155+
Number getWidth();
156+
157+
/**
158+
* @return the max height as a Number
159+
*/
160+
Number getHeight();
161+
152162
~UIMultilineLabel();
153163
protected:
154164

@@ -160,9 +170,7 @@ namespace Polycode {
160170
void clearLabels();
161171
std::vector<UILabel*> labels;
162172
};
163-
164-
165-
173+
166174
class _PolyExport UIImage : public UIRect {
167175
public:
168176
UIImage(String imagePath);

Modules/Contents/UI/Source/PolyUIElement.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,32 @@ void UIMultilineLabel::clearLabels() {
9696
labels.clear();
9797
}
9898

99+
Number UIMultilineLabel::getWidth(){
100+
Number maxWidth = 0;
101+
for (int i = 0; i < labels.size(); i++) {
102+
if (labels[i]->getWidth() > maxWidth){
103+
maxWidth = labels[i]->getWidth();
104+
}
105+
}
106+
return maxWidth;
107+
}
108+
109+
Number UIMultilineLabel::getHeight(){
110+
Number maxHeight = 0;
111+
for (int i = 0; i < labels.size(); i++) {
112+
if (labels[i]->getHeight() > maxHeight){
113+
maxHeight = labels[i]->getHeight();
114+
}
115+
}
116+
return maxHeight;
117+
}
118+
99119
UIMultilineLabel::~UIMultilineLabel() {
100120
if(!ownsChildren) {
101121
clearLabels();
102122
}
103123
}
104124

105-
106125
UILabel::UILabel(const String& text, int size, const String& fontName, int amode) : UIElement() {
107126

108127
Config *conf = CoreServices::getInstance()->getConfig();

0 commit comments

Comments
 (0)