ソースを参照

Fix UIMultilineLabels to return the correct width and height.

Joachim Meyer 11 年 前
コミット
49b533b922

+ 11 - 3
Modules/Contents/UI/Include/PolyUIElement.h

@@ -149,6 +149,16 @@ namespace Polycode {
 		*/
 		void setColor(Color color);
 
+		/**
+		* @return the max width as a Number
+		*/
+		Number getWidth();
+
+		/**
+		* @return the max height as a Number
+		*/
+		Number getHeight();
+
         ~UIMultilineLabel();
     protected:
         
@@ -160,9 +170,7 @@ namespace Polycode {
         void clearLabels();
         std::vector<UILabel*> labels;
 	};
-    
-
-	
+    	
 	class _PolyExport UIImage : public UIRect {
 		public:
 			UIImage(String imagePath);

+ 20 - 1
Modules/Contents/UI/Source/PolyUIElement.cpp

@@ -96,13 +96,32 @@ void UIMultilineLabel::clearLabels() {
     labels.clear();
 }
 
+Number UIMultilineLabel::getWidth(){
+	Number maxWidth = 0;
+	for (int i = 0; i < labels.size(); i++) {
+		if (labels[i]->getWidth() > maxWidth){
+			maxWidth = labels[i]->getWidth();
+		}
+	}
+	return maxWidth;
+}
+
+Number UIMultilineLabel::getHeight(){
+	Number maxHeight = 0;
+	for (int i = 0; i < labels.size(); i++) {
+		if (labels[i]->getHeight() > maxHeight){
+			maxHeight = labels[i]->getHeight();
+		}
+	}
+	return maxHeight;
+}
+
 UIMultilineLabel::~UIMultilineLabel() {
     if(!ownsChildren) {
         clearLabels();
     }
 }
 
-
 UILabel::UILabel(const String& text, int size, const String& fontName, int amode) : UIElement() {
 
 	Config *conf = CoreServices::getInstance()->getConfig();