Ver código fonte

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 anos atrás
pai
commit
5732dc81ca
1 arquivos alterados com 19 adições e 1 exclusões
  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;
+        }
     }    
-}
+}