소스 검색

Update button.ts

Added static "CreateImageWithCenterTextButton" with centered text and full-size image background.
Which i think is a very common button setup in any game :)

I used zIndex to render text infront of image instead of adding it as second control.
this way we keep consistency with other text buttons, and can change .text value in the same way & child id, e.g. button.children[0].text

https://www.babylonjs-playground.com/#XCPP9Y#288
aWeirdo 7 년 전
부모
커밋
5732dc81ca
1개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 19 1
      gui/src/controls/button.ts

+ 19 - 1
gui/src/controls/button.ts

@@ -136,5 +136,23 @@ module BABYLON.GUI {
 
             return result;
         }
+        
+        public static CreateImageWithCenterTextButton(name: string, text: string, imageUrl: string): Button {
+            var result = new Button(name);
+
+            // Adding text
+            var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
+            textBlock.textWrapping = true;
+            textBlock.zIndex = 10; 
+		    textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
+            result.addControl(textBlock);   
+
+            // Adding image
+            var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
+            iconImage.stretch = BABYLON.GUI.Image.STRETCH_FILL;
+            result.addControl(iconImage);            
+
+            return result;
+        }
     }    
-}
+}