@babylonjs/gui 7.34.3 → 7.35.0
Sign up to get free protection for your applications and to get access to all the features.
- package/2D/FrameGraph/guiTask.js.map +1 -1
- package/2D/FrameGraph/renderGraphGUIBlock.js.map +1 -1
- package/2D/adtInstrumentation.js.map +1 -1
- package/2D/advancedDynamicTexture.d.ts +1 -1
- package/2D/advancedDynamicTexture.js.map +1 -1
- package/2D/controls/button.js.map +1 -1
- package/2D/controls/checkbox.js.map +1 -1
- package/2D/controls/colorpicker.js.map +1 -1
- package/2D/controls/container.js.map +1 -1
- package/2D/controls/control.js.map +1 -1
- package/2D/controls/displayGrid.js.map +1 -1
- package/2D/controls/ellipse.js.map +1 -1
- package/2D/controls/focusableButton.js.map +1 -1
- package/2D/controls/gradient/BaseGradient.js.map +1 -1
- package/2D/controls/grid.js.map +1 -1
- package/2D/controls/image.js.map +1 -1
- package/2D/controls/inputPassword.js.map +1 -1
- package/2D/controls/inputText.js.map +1 -1
- package/2D/controls/inputTextArea.js.map +1 -1
- package/2D/controls/line.js.map +1 -1
- package/2D/controls/multiLine.js.map +1 -1
- package/2D/controls/radioButton.js.map +1 -1
- package/2D/controls/rectangle.js.map +1 -1
- package/2D/controls/scrollViewers/scrollViewer.js.map +1 -1
- package/2D/controls/scrollViewers/scrollViewerWindow.js.map +1 -1
- package/2D/controls/selector.js.map +1 -1
- package/2D/controls/sliders/baseSlider.js.map +1 -1
- package/2D/controls/sliders/imageBasedSlider.js.map +1 -1
- package/2D/controls/sliders/imageScrollBar.js.map +1 -1
- package/2D/controls/sliders/scrollBar.js.map +1 -1
- package/2D/controls/sliders/slider.js.map +1 -1
- package/2D/controls/stackPanel.js.map +1 -1
- package/2D/controls/statics.js.map +1 -1
- package/2D/controls/textBlock.js.map +1 -1
- package/2D/controls/textWrapper.js.map +1 -1
- package/2D/controls/toggleButton.js.map +1 -1
- package/2D/controls/virtualKeyboard.js.map +1 -1
- package/2D/math2D.js.map +1 -1
- package/2D/measure.js.map +1 -1
- package/2D/multiLinePoint.js.map +1 -1
- package/2D/style.js.map +1 -1
- package/2D/valueAndUnit.js.map +1 -1
- package/2D/xmlLoader.js.map +1 -1
- package/3D/behaviors/defaultBehavior.js.map +1 -1
- package/3D/controls/MRTK3/touchHolographicButton.js.map +1 -1
- package/3D/controls/button3D.js.map +1 -1
- package/3D/controls/container3D.js.map +1 -1
- package/3D/controls/contentDisplay3D.js.map +1 -1
- package/3D/controls/control3D.js.map +1 -1
- package/3D/controls/cylinderPanel.js.map +1 -1
- package/3D/controls/holographicBackplate.js.map +1 -1
- package/3D/controls/holographicButton.js.map +1 -1
- package/3D/controls/holographicSlate.js.map +1 -1
- package/3D/controls/meshButton3D.js.map +1 -1
- package/3D/controls/nearMenu.js.map +1 -1
- package/3D/controls/planePanel.js.map +1 -1
- package/3D/controls/scatterPanel.js.map +1 -1
- package/3D/controls/slider3D.js.map +1 -1
- package/3D/controls/spherePanel.js.map +1 -1
- package/3D/controls/stackPanel3D.js.map +1 -1
- package/3D/controls/touchButton3D.js.map +1 -1
- package/3D/controls/touchHolographicButton.js.map +1 -1
- package/3D/controls/touchHolographicMenu.js.map +1 -1
- package/3D/controls/touchMeshButton3D.js.map +1 -1
- package/3D/controls/volumeBasedPanel.js.map +1 -1
- package/3D/gizmos/gizmoHandle.js.map +1 -1
- package/3D/gizmos/slateGizmo.js.map +1 -1
- package/3D/gui3DManager.js.map +1 -1
- package/3D/materials/fluent/fluentMaterial.js.map +1 -1
- package/3D/materials/fluentBackplate/fluentBackplateMaterial.js.map +1 -1
- package/3D/materials/fluentButton/fluentButtonMaterial.js.map +1 -1
- package/3D/materials/handle/handleMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlBackglowMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlBackplateMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlFrontplateMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlInnerquadMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlSliderBarMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlSliderThumbMaterial.js.map +1 -1
- package/legacy/legacy.js.map +1 -1
- package/package.json +2 -2
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../../../../dev/gui/src/2D/controls/button.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,0CAA4B;AAKpD;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;IAmBjC;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAGD;;OAEG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,YAA4B,IAAa;QACrC,KAAK,CAAC,IAAI,CAAC,CAAC;QADY,SAAI,GAAJ,IAAI,CAAS;QAGrC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAE7B,IAAI,UAAU,GAAqB,IAAI,CAAC;QAExC,IAAI,CAAC,qBAAqB,GAAG,GAAG,EAAE;YAC9B,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC;YACxB,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC;QACtB,CAAC,CAAC;QAEF,IAAI,CAAC,mBAAmB,GAAG,GAAG,EAAE;YAC5B,IAAI,UAAU,KAAK,IAAI,EAAE;gBACrB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;aAC3B;QACL,CAAC,CAAC;QAEF,IAAI,CAAC,oBAAoB,GAAG,GAAG,EAAE;YAC7B,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;YACpB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AAM,CAAC,UAAU,GAAG,SAAS,CAAC;QAE9B,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AACD,aAAa,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { Vector2 } from \"core/Maths/math.vector\";\r\n\r\nimport { Rectangle } from \"./rectangle\";\r\nimport { Control } from \"./control\";\r\nimport { TextBlock } from \"./textBlock\";\r\nimport { Image } from \"./image\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport type { PointerInfoBase } from \"core/Events/pointerEvents\";\r\nimport type { AdvancedDynamicTexture } from \"../advancedDynamicTexture\";\r\nimport type { ICanvasRenderingContext } from \"core/Engines/ICanvas\";\r\n\r\n/**\r\n * Class used to create 2D buttons\r\n */\r\nexport class Button extends Rectangle {\r\n /**\r\n * Function called to generate a pointer enter animation\r\n */\r\n public pointerEnterAnimation: () => void;\r\n /**\r\n * Function called to generate a pointer out animation\r\n */\r\n public pointerOutAnimation: () => void;\r\n /**\r\n * Function called to generate a pointer down animation\r\n */\r\n public pointerDownAnimation: () => void;\r\n /**\r\n * Function called to generate a pointer up animation\r\n */\r\n public pointerUpAnimation: () => void;\r\n\r\n private _image: Nullable<Image>;\r\n /**\r\n * Returns the image part of the button (if any)\r\n */\r\n public get image(): Nullable<Image> {\r\n return this._image;\r\n }\r\n\r\n private _textBlock: Nullable<TextBlock>;\r\n /**\r\n * Returns the TextBlock part of the button (if any)\r\n */\r\n public get textBlock(): Nullable<TextBlock> {\r\n return this._textBlock;\r\n }\r\n\r\n /**\r\n * Creates a new Button\r\n * @param name defines the name of the button\r\n */\r\n constructor(public override name?: string) {\r\n super(name);\r\n\r\n this.thickness = 1;\r\n this.isPointerBlocker = true;\r\n\r\n let alphaStore: Nullable<number> = null;\r\n\r\n this.pointerEnterAnimation = () => {\r\n alphaStore = this.alpha;\r\n this.alpha -= 0.1;\r\n };\r\n\r\n this.pointerOutAnimation = () => {\r\n if (alphaStore !== null) {\r\n this.alpha = alphaStore;\r\n }\r\n };\r\n\r\n this.pointerDownAnimation = () => {\r\n this.scaleX -= 0.05;\r\n this.scaleY -= 0.05;\r\n };\r\n\r\n this.pointerUpAnimation = () => {\r\n this.scaleX += 0.05;\r\n this.scaleY += 0.05;\r\n };\r\n }\r\n\r\n protected override _getTypeName(): string {\r\n return \"Button\";\r\n }\r\n\r\n // While being a container, the button behaves like a control.\r\n /**\r\n * @internal\r\n */\r\n public override _processPicking(x: number, y: number, pi: PointerInfoBase, type: number, pointerId: number, buttonIndex: number, deltaX?: number, deltaY?: number): boolean {\r\n if (!this._isEnabled || !this.isHitTestVisible || !this.isVisible || this.notRenderable) {\r\n return false;\r\n }\r\n\r\n if (!super.contains(x, y)) {\r\n return false;\r\n }\r\n\r\n if (this.delegatePickingToChildren) {\r\n let contains = false;\r\n for (let index = this._children.length - 1; index >= 0; index--) {\r\n const child = this._children[index];\r\n if (child.isEnabled && child.isHitTestVisible && child.isVisible && !child.notRenderable && child.contains(x, y)) {\r\n contains = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!contains) {\r\n return false;\r\n }\r\n }\r\n\r\n this._processObservables(type, x, y, pi, pointerId, buttonIndex, deltaX, deltaY);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerEnter(target: Control, pi: PointerInfoBase): boolean {\r\n if (!super._onPointerEnter(target, pi)) {\r\n return false;\r\n }\r\n\r\n if (!this.isReadOnly && this.pointerEnterAnimation) {\r\n this.pointerEnterAnimation();\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerOut(target: Control, pi: PointerInfoBase, force = false): void {\r\n if (!this.isReadOnly && this.pointerOutAnimation) {\r\n this.pointerOutAnimation();\r\n }\r\n\r\n super._onPointerOut(target, pi, force);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerDown(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, pi: PointerInfoBase): boolean {\r\n if (!super._onPointerDown(target, coordinates, pointerId, buttonIndex, pi)) {\r\n return false;\r\n }\r\n\r\n if (!this.isReadOnly && this.pointerDownAnimation) {\r\n this.pointerDownAnimation();\r\n }\r\n\r\n return true;\r\n }\r\n\r\n protected override _getRectangleFill(context: ICanvasRenderingContext) {\r\n if (this.isEnabled) {\r\n return this._getBackgroundColor(context);\r\n } else {\r\n return this._disabledColor;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerUp(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, notifyClick: boolean, pi: PointerInfoBase): void {\r\n if (!this.isReadOnly && this.pointerUpAnimation) {\r\n this.pointerUpAnimation();\r\n }\r\n\r\n super._onPointerUp(target, coordinates, pointerId, buttonIndex, notifyClick, pi);\r\n }\r\n\r\n /**\r\n * Serializes the current button\r\n * @param serializationObject defines the JSON serialized object\r\n * @param force force serialization even if isSerializable === false\r\n */\r\n public override serialize(serializationObject: any, force: boolean) {\r\n super.serialize(serializationObject, force);\r\n if (!this.isSerializable && !force) {\r\n return;\r\n }\r\n\r\n if (this._textBlock) {\r\n serializationObject.textBlockName = this._textBlock.name;\r\n }\r\n if (this._image) {\r\n serializationObject.imageName = this._image.name;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _parseFromContent(serializedObject: any, host: AdvancedDynamicTexture) {\r\n super._parseFromContent(serializedObject, host);\r\n\r\n if (serializedObject.textBlockName) {\r\n this._textBlock = this.getChildByName(serializedObject.textBlockName) as Nullable<TextBlock>;\r\n }\r\n\r\n if (serializedObject.imageName) {\r\n this._image = this.getChildByName(serializedObject.imageName) as Nullable<Image>;\r\n }\r\n }\r\n\r\n // Statics\r\n /**\r\n * Creates a new button made with an image and a text\r\n * @param name defines the name of the button\r\n * @param text defines the text of the button\r\n * @param imageUrl defines the url of the image\r\n * @returns a new Button\r\n */\r\n public static CreateImageButton(name: string, text: string, imageUrl: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding text\r\n const textBlock = new TextBlock(name + \"_button\", text);\r\n textBlock.textWrapping = true;\r\n textBlock.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;\r\n textBlock.paddingLeft = \"20%\";\r\n result.addControl(textBlock);\r\n\r\n // Adding image\r\n const iconImage = new Image(name + \"_icon\", imageUrl);\r\n iconImage.width = \"20%\";\r\n iconImage.stretch = Image.STRETCH_UNIFORM;\r\n iconImage.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;\r\n result.addControl(iconImage);\r\n\r\n // Store\r\n result._image = iconImage;\r\n result._textBlock = textBlock;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new button made with an image\r\n * @param name defines the name of the button\r\n * @param imageUrl defines the url of the image\r\n * @returns a new Button\r\n */\r\n public static CreateImageOnlyButton(name: string, imageUrl: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding image\r\n const iconImage = new Image(name + \"_icon\", imageUrl);\r\n iconImage.stretch = Image.STRETCH_FILL;\r\n iconImage.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;\r\n result.addControl(iconImage);\r\n\r\n // Store\r\n result._image = iconImage;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new button made with a text\r\n * @param name defines the name of the button\r\n * @param text defines the text of the button\r\n * @returns a new Button\r\n */\r\n public static CreateSimpleButton(name: string, text: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding text\r\n const textBlock = new TextBlock(name + \"_button\", text);\r\n textBlock.textWrapping = true;\r\n textBlock.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;\r\n result.addControl(textBlock);\r\n\r\n // Store\r\n result._textBlock = textBlock;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new button made with an image and a centered text\r\n * @param name defines the name of the button\r\n * @param text defines the text of the button\r\n * @param imageUrl defines the url of the image\r\n * @returns a new Button\r\n */\r\n public static CreateImageWithCenterTextButton(name: string, text: string, imageUrl: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding image\r\n const iconImage = new Image(name + \"_icon\", imageUrl);\r\n iconImage.stretch = Image.STRETCH_FILL;\r\n result.addControl(iconImage);\r\n\r\n // Adding text\r\n const textBlock = new TextBlock(name + \"_button\", text);\r\n textBlock.textWrapping = true;\r\n textBlock.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;\r\n result.addControl(textBlock);\r\n\r\n // Store\r\n result._image = iconImage;\r\n result._textBlock = textBlock;\r\n\r\n return result;\r\n }\r\n}\r\nRegisterClass(\"BABYLON.GUI.Button\", Button);\r\n"]}
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../../../../dev/gui/src/2D/controls/button.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,0CAA4B;AAKpD;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;IAmBjC;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAGD;;OAEG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,YAA4B,IAAa;QACrC,KAAK,CAAC,IAAI,CAAC,CAAC;QADY,SAAI,GAAJ,IAAI,CAAS;QAGrC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAE7B,IAAI,UAAU,GAAqB,IAAI,CAAC;QAExC,IAAI,CAAC,qBAAqB,GAAG,GAAG,EAAE;YAC9B,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC;YAC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AI,CAAC,IAAI,CAAC,CAAC;QAE9B,eAAe;QACf,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC,IAAI,GAAG,OAAO,EAAE,QAAQ,CAAC,CAAC;QACtD,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC;QACvC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAE7B,cAAc;QACd,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,GAAG,SAAS,EAAE,IAAI,CAAC,CAAC;QACxD,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC;QAC9B,SAAS,CAAC,uBAAuB,GAAG,OAAO,CAAC,2BAA2B,CAAC;QACxE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAE7B,QAAQ;QACR,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC;QAC1B,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;QAE9B,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AACD,aAAa,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { Vector2 } from \"core/Maths/math.vector\";\r\n\r\nimport { Rectangle } from \"./rectangle\";\r\nimport { Control } from \"./control\";\r\nimport { TextBlock } from \"./textBlock\";\r\nimport { Image } from \"./image\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport type { PointerInfoBase } from \"core/Events/pointerEvents\";\r\nimport type { AdvancedDynamicTexture } from \"../advancedDynamicTexture\";\r\nimport type { ICanvasRenderingContext } from \"core/Engines/ICanvas\";\r\n\r\n/**\r\n * Class used to create 2D buttons\r\n */\r\nexport class Button extends Rectangle {\r\n /**\r\n * Function called to generate a pointer enter animation\r\n */\r\n public pointerEnterAnimation: () => void;\r\n /**\r\n * Function called to generate a pointer out animation\r\n */\r\n public pointerOutAnimation: () => void;\r\n /**\r\n * Function called to generate a pointer down animation\r\n */\r\n public pointerDownAnimation: () => void;\r\n /**\r\n * Function called to generate a pointer up animation\r\n */\r\n public pointerUpAnimation: () => void;\r\n\r\n private _image: Nullable<Image>;\r\n /**\r\n * Returns the image part of the button (if any)\r\n */\r\n public get image(): Nullable<Image> {\r\n return this._image;\r\n }\r\n\r\n private _textBlock: Nullable<TextBlock>;\r\n /**\r\n * Returns the TextBlock part of the button (if any)\r\n */\r\n public get textBlock(): Nullable<TextBlock> {\r\n return this._textBlock;\r\n }\r\n\r\n /**\r\n * Creates a new Button\r\n * @param name defines the name of the button\r\n */\r\n constructor(public override name?: string) {\r\n super(name);\r\n\r\n this.thickness = 1;\r\n this.isPointerBlocker = true;\r\n\r\n let alphaStore: Nullable<number> = null;\r\n\r\n this.pointerEnterAnimation = () => {\r\n alphaStore = this.alpha;\r\n this.alpha -= 0.1;\r\n };\r\n\r\n this.pointerOutAnimation = () => {\r\n if (alphaStore !== null) {\r\n this.alpha = alphaStore;\r\n }\r\n };\r\n\r\n this.pointerDownAnimation = () => {\r\n this.scaleX -= 0.05;\r\n this.scaleY -= 0.05;\r\n };\r\n\r\n this.pointerUpAnimation = () => {\r\n this.scaleX += 0.05;\r\n this.scaleY += 0.05;\r\n };\r\n }\r\n\r\n protected override _getTypeName(): string {\r\n return \"Button\";\r\n }\r\n\r\n // While being a container, the button behaves like a control.\r\n /**\r\n * @internal\r\n */\r\n public override _processPicking(x: number, y: number, pi: PointerInfoBase, type: number, pointerId: number, buttonIndex: number, deltaX?: number, deltaY?: number): boolean {\r\n if (!this._isEnabled || !this.isHitTestVisible || !this.isVisible || this.notRenderable) {\r\n return false;\r\n }\r\n\r\n if (!super.contains(x, y)) {\r\n return false;\r\n }\r\n\r\n if (this.delegatePickingToChildren) {\r\n let contains = false;\r\n for (let index = this._children.length - 1; index >= 0; index--) {\r\n const child = this._children[index];\r\n if (child.isEnabled && child.isHitTestVisible && child.isVisible && !child.notRenderable && child.contains(x, y)) {\r\n contains = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!contains) {\r\n return false;\r\n }\r\n }\r\n\r\n this._processObservables(type, x, y, pi, pointerId, buttonIndex, deltaX, deltaY);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerEnter(target: Control, pi: PointerInfoBase): boolean {\r\n if (!super._onPointerEnter(target, pi)) {\r\n return false;\r\n }\r\n\r\n if (!this.isReadOnly && this.pointerEnterAnimation) {\r\n this.pointerEnterAnimation();\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerOut(target: Control, pi: PointerInfoBase, force = false): void {\r\n if (!this.isReadOnly && this.pointerOutAnimation) {\r\n this.pointerOutAnimation();\r\n }\r\n\r\n super._onPointerOut(target, pi, force);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerDown(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, pi: PointerInfoBase): boolean {\r\n if (!super._onPointerDown(target, coordinates, pointerId, buttonIndex, pi)) {\r\n return false;\r\n }\r\n\r\n if (!this.isReadOnly && this.pointerDownAnimation) {\r\n this.pointerDownAnimation();\r\n }\r\n\r\n return true;\r\n }\r\n\r\n protected override _getRectangleFill(context: ICanvasRenderingContext) {\r\n if (this.isEnabled) {\r\n return this._getBackgroundColor(context);\r\n } else {\r\n return this._disabledColor;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerUp(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, notifyClick: boolean, pi: PointerInfoBase): void {\r\n if (!this.isReadOnly && this.pointerUpAnimation) {\r\n this.pointerUpAnimation();\r\n }\r\n\r\n super._onPointerUp(target, coordinates, pointerId, buttonIndex, notifyClick, pi);\r\n }\r\n\r\n /**\r\n * Serializes the current button\r\n * @param serializationObject defines the JSON serialized object\r\n * @param force force serialization even if isSerializable === false\r\n */\r\n public override serialize(serializationObject: any, force: boolean) {\r\n super.serialize(serializationObject, force);\r\n if (!this.isSerializable && !force) {\r\n return;\r\n }\r\n\r\n if (this._textBlock) {\r\n serializationObject.textBlockName = this._textBlock.name;\r\n }\r\n if (this._image) {\r\n serializationObject.imageName = this._image.name;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _parseFromContent(serializedObject: any, host: AdvancedDynamicTexture) {\r\n super._parseFromContent(serializedObject, host);\r\n\r\n if (serializedObject.textBlockName) {\r\n this._textBlock = this.getChildByName(serializedObject.textBlockName) as Nullable<TextBlock>;\r\n }\r\n\r\n if (serializedObject.imageName) {\r\n this._image = this.getChildByName(serializedObject.imageName) as Nullable<Image>;\r\n }\r\n }\r\n\r\n // Statics\r\n /**\r\n * Creates a new button made with an image and a text\r\n * @param name defines the name of the button\r\n * @param text defines the text of the button\r\n * @param imageUrl defines the url of the image\r\n * @returns a new Button\r\n */\r\n public static CreateImageButton(name: string, text: string, imageUrl: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding text\r\n const textBlock = new TextBlock(name + \"_button\", text);\r\n textBlock.textWrapping = true;\r\n textBlock.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;\r\n textBlock.paddingLeft = \"20%\";\r\n result.addControl(textBlock);\r\n\r\n // Adding image\r\n const iconImage = new Image(name + \"_icon\", imageUrl);\r\n iconImage.width = \"20%\";\r\n iconImage.stretch = Image.STRETCH_UNIFORM;\r\n iconImage.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;\r\n result.addControl(iconImage);\r\n\r\n // Store\r\n result._image = iconImage;\r\n result._textBlock = textBlock;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new button made with an image\r\n * @param name defines the name of the button\r\n * @param imageUrl defines the url of the image\r\n * @returns a new Button\r\n */\r\n public static CreateImageOnlyButton(name: string, imageUrl: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding image\r\n const iconImage = new Image(name + \"_icon\", imageUrl);\r\n iconImage.stretch = Image.STRETCH_FILL;\r\n iconImage.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;\r\n result.addControl(iconImage);\r\n\r\n // Store\r\n result._image = iconImage;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new button made with a text\r\n * @param name defines the name of the button\r\n * @param text defines the text of the button\r\n * @returns a new Button\r\n */\r\n public static CreateSimpleButton(name: string, text: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding text\r\n const textBlock = new TextBlock(name + \"_button\", text);\r\n textBlock.textWrapping = true;\r\n textBlock.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;\r\n result.addControl(textBlock);\r\n\r\n // Store\r\n result._textBlock = textBlock;\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new button made with an image and a centered text\r\n * @param name defines the name of the button\r\n * @param text defines the text of the button\r\n * @param imageUrl defines the url of the image\r\n * @returns a new Button\r\n */\r\n public static CreateImageWithCenterTextButton(name: string, text: string, imageUrl: string): Button {\r\n const result = new this(name);\r\n\r\n // Adding image\r\n const iconImage = new Image(name + \"_icon\", imageUrl);\r\n iconImage.stretch = Image.STRETCH_FILL;\r\n result.addControl(iconImage);\r\n\r\n // Adding text\r\n const textBlock = new TextBlock(name + \"_button\", text);\r\n textBlock.textWrapping = true;\r\n textBlock.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;\r\n result.addControl(textBlock);\r\n\r\n // Store\r\n result._image = iconImage;\r\n result._textBlock = textBlock;\r\n\r\n return result;\r\n }\r\n}\r\nRegisterClass(\"BABYLON.GUI.Button\", Button);\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../../../../dev/gui/src/2D/controls/checkbox.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,2CAA6B;AAGlD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,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C/B,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC;QACpB,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC;QACvB,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC;QAC3B,MAAM,CAAC,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,CAAC;QACnE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC;QACvB,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA9KG;IADC,SAAS,EAAE;yCAGX;AAkBD;IADC,SAAS,EAAE;8CAGX;AAeD;IADC,SAAS,EAAE;0CAGX;AAaD;IADC,SAAS,EAAE;yCAGX;AAyHL,aAAa,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["import { Observable } from \"core/Misc/observable\";\r\nimport type { Vector2 } from \"core/Maths/math.vector\";\r\n\r\nimport { Control } from \"./control\";\r\nimport { StackPanel } from \"./stackPanel\";\r\nimport { TextBlock } from \"./textBlock\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport type { PointerInfoBase } from \"core/Events/pointerEvents\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport type { ICanvasRenderingContext } from \"core/Engines/ICanvas\";\r\n\r\n/**\r\n * Class used to represent a 2D checkbox\r\n */\r\nexport class Checkbox extends Control {\r\n private _isChecked = false;\r\n private _background = \"black\";\r\n private _checkSizeRatio = 0.8;\r\n private _thickness = 1;\r\n\r\n /** Gets or sets border thickness */\r\n @serialize()\r\n public get thickness(): number {\r\n return this._thickness;\r\n }\r\n\r\n public set thickness(value: number) {\r\n if (this._thickness === value) {\r\n return;\r\n }\r\n\r\n this._thickness = value;\r\n this._markAsDirty();\r\n }\r\n\r\n /**\r\n * Observable raised when isChecked property changes\r\n */\r\n public onIsCheckedChangedObservable = new Observable<boolean>();\r\n\r\n /** Gets or sets a value indicating the ratio between overall size and check size */\r\n @serialize()\r\n public get checkSizeRatio(): number {\r\n return this._checkSizeRatio;\r\n }\r\n\r\n public set checkSizeRatio(value: number) {\r\n value = Math.max(Math.min(1, value), 0);\r\n\r\n if (this._checkSizeRatio === value) {\r\n return;\r\n }\r\n\r\n this._checkSizeRatio = value;\r\n this._markAsDirty();\r\n }\r\n\r\n /** Gets or sets background color */\r\n @serialize()\r\n public get background(): string {\r\n return this._background;\r\n }\r\n\r\n public set background(value: string) {\r\n if (this._background === value) {\r\n return;\r\n }\r\n\r\n this._background = value;\r\n this._markAsDirty();\r\n }\r\n\r\n /** Gets or sets a boolean indicating if the checkbox is checked or not */\r\n @serialize()\r\n public get isChecked(): boolean {\r\n return this._isChecked;\r\n }\r\n\r\n public set isChecked(value: boolean) {\r\n if (this._isChecked === value) {\r\n return;\r\n }\r\n\r\n this._isChecked = value;\r\n this._markAsDirty();\r\n\r\n this.onIsCheckedChangedObservable.notifyObservers(value);\r\n }\r\n\r\n /**\r\n * Creates a new CheckBox\r\n * @param name defines the control name\r\n */\r\n constructor(public override name?: string) {\r\n super(name);\r\n this.isPointerBlocker = true;\r\n }\r\n\r\n protected override _getTypeName(): string {\r\n return \"Checkbox\";\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _draw(context: ICanvasRenderingContext): void {\r\n context.save();\r\n\r\n this._applyStates(context);\r\n const actualWidth = this._currentMeasure.width - this._thickness;\r\n const actualHeight = this._currentMeasure.height - this._thickness;\r\n\r\n if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {\r\n context.shadowColor = this.shadowColor;\r\n context.shadowBlur = this.shadowBlur;\r\n context.shadowOffsetX = this.shadowOffsetX;\r\n context.shadowOffsetY = this.shadowOffsetY;\r\n }\r\n\r\n context.fillStyle = this._isEnabled ? this._background : this._disabledColor;\r\n context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);\r\n\r\n if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {\r\n context.shadowBlur = 0;\r\n context.shadowOffsetX = 0;\r\n context.shadowOffsetY = 0;\r\n }\r\n\r\n if (this._isChecked) {\r\n // Color is white if not set\r\n context.fillStyle = this._isEnabled ? (this.color ? this.color : \"#ffffff\") : this._disabledColorItem;\r\n const offsetWidth = actualWidth * this._checkSizeRatio;\r\n const offsetHeight = actualHeight * this._checkSizeRatio;\r\n\r\n context.fillRect(\r\n this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2,\r\n this._currentMeasure.top + this._thickness / 2 + (actualHeight - offsetHeight) / 2,\r\n offsetWidth,\r\n offsetHeight\r\n );\r\n }\r\n\r\n context.strokeStyle = this.color;\r\n context.lineWidth = this._thickness;\r\n\r\n context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);\r\n\r\n context.restore();\r\n }\r\n\r\n // Events\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerDown(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, pi: PointerInfoBase): boolean {\r\n if (!super._onPointerDown(target, coordinates, pointerId, buttonIndex, pi)) {\r\n return false;\r\n }\r\n\r\n if (!this.isReadOnly) {\r\n this.isChecked = !this.isChecked;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Utility function to easily create a checkbox with a header\r\n * @param title defines the label to use for the header\r\n * @param onValueChanged defines the callback to call when value changes\r\n * @returns a StackPanel containing the checkbox and a textBlock\r\n */\r\n public static AddCheckBoxWithHeader(title: string, onValueChanged: (value: boolean) => void): StackPanel {\r\n const panel = new StackPanel();\r\n panel.isVertical = false;\r\n panel.height = \"30px\";\r\n\r\n const checkbox = new Checkbox();\r\n checkbox.width = \"20px\";\r\n checkbox.height = \"20px\";\r\n checkbox.isChecked = true;\r\n checkbox.color = \"green\";\r\n checkbox.onIsCheckedChangedObservable.add(onValueChanged);\r\n panel.addControl(checkbox);\r\n\r\n const header = new TextBlock();\r\n header.text = title;\r\n header.width = \"180px\";\r\n header.paddingLeft = \"5px\";\r\n header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;\r\n header.color = \"white\";\r\n panel.addControl(header);\r\n\r\n return panel;\r\n }\r\n}\r\nRegisterClass(\"BABYLON.GUI.Checkbox\", Checkbox);\r\n"]}
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../../../../dev/gui/src/2D/controls/checkbox.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,2CAA6B;AAGlD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,0CAA4B;AAEpD,OAAO,EAAE,SAAS,EAAE,2CAA6B;AAGjD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,OAAO;IAMjC,qCAAqC;IAErC,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,IAAW,SAAS,CAAC,KAAa;QAC9B,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;YAC5B,OAAO;QACX,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAOD,oFAAoF;IAEpF,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,IAAW,cAAc,CAAC,KAAa;QACnC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;YACjC,OAAO;QACX,CAAC;QAED,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,YAAY,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AM,CAAC,qBAAqB,CAAC,KAAa,EAAE,cAAwC;QACvF,MAAM,KAAK,GAAG,IAAI,UAAU,EAAE,CAAC;QAC/B,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;QACzB,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAEtB,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAChC,QAAQ,CAAC,KAAK,GAAG,MAAM,CAAC;QACxB,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;QAC1B,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC;QACzB,QAAQ,CAAC,4BAA4B,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1D,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAE3B,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC;QACpB,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC;QACvB,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC;QAC3B,MAAM,CAAC,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,CAAC;QACnE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC;QACvB,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA9KG;IADC,SAAS,EAAE;yCAGX;AAkBD;IADC,SAAS,EAAE;8CAGX;AAeD;IADC,SAAS,EAAE;0CAGX;AAaD;IADC,SAAS,EAAE;yCAGX;AAyHL,aAAa,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["import { Observable } from \"core/Misc/observable\";\r\nimport type { Vector2 } from \"core/Maths/math.vector\";\r\n\r\nimport { Control } from \"./control\";\r\nimport { StackPanel } from \"./stackPanel\";\r\nimport { TextBlock } from \"./textBlock\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport type { PointerInfoBase } from \"core/Events/pointerEvents\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport type { ICanvasRenderingContext } from \"core/Engines/ICanvas\";\r\n\r\n/**\r\n * Class used to represent a 2D checkbox\r\n */\r\nexport class Checkbox extends Control {\r\n private _isChecked = false;\r\n private _background = \"black\";\r\n private _checkSizeRatio = 0.8;\r\n private _thickness = 1;\r\n\r\n /** Gets or sets border thickness */\r\n @serialize()\r\n public get thickness(): number {\r\n return this._thickness;\r\n }\r\n\r\n public set thickness(value: number) {\r\n if (this._thickness === value) {\r\n return;\r\n }\r\n\r\n this._thickness = value;\r\n this._markAsDirty();\r\n }\r\n\r\n /**\r\n * Observable raised when isChecked property changes\r\n */\r\n public onIsCheckedChangedObservable = new Observable<boolean>();\r\n\r\n /** Gets or sets a value indicating the ratio between overall size and check size */\r\n @serialize()\r\n public get checkSizeRatio(): number {\r\n return this._checkSizeRatio;\r\n }\r\n\r\n public set checkSizeRatio(value: number) {\r\n value = Math.max(Math.min(1, value), 0);\r\n\r\n if (this._checkSizeRatio === value) {\r\n return;\r\n }\r\n\r\n this._checkSizeRatio = value;\r\n this._markAsDirty();\r\n }\r\n\r\n /** Gets or sets background color */\r\n @serialize()\r\n public get background(): string {\r\n return this._background;\r\n }\r\n\r\n public set background(value: string) {\r\n if (this._background === value) {\r\n return;\r\n }\r\n\r\n this._background = value;\r\n this._markAsDirty();\r\n }\r\n\r\n /** Gets or sets a boolean indicating if the checkbox is checked or not */\r\n @serialize()\r\n public get isChecked(): boolean {\r\n return this._isChecked;\r\n }\r\n\r\n public set isChecked(value: boolean) {\r\n if (this._isChecked === value) {\r\n return;\r\n }\r\n\r\n this._isChecked = value;\r\n this._markAsDirty();\r\n\r\n this.onIsCheckedChangedObservable.notifyObservers(value);\r\n }\r\n\r\n /**\r\n * Creates a new CheckBox\r\n * @param name defines the control name\r\n */\r\n constructor(public override name?: string) {\r\n super(name);\r\n this.isPointerBlocker = true;\r\n }\r\n\r\n protected override _getTypeName(): string {\r\n return \"Checkbox\";\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _draw(context: ICanvasRenderingContext): void {\r\n context.save();\r\n\r\n this._applyStates(context);\r\n const actualWidth = this._currentMeasure.width - this._thickness;\r\n const actualHeight = this._currentMeasure.height - this._thickness;\r\n\r\n if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {\r\n context.shadowColor = this.shadowColor;\r\n context.shadowBlur = this.shadowBlur;\r\n context.shadowOffsetX = this.shadowOffsetX;\r\n context.shadowOffsetY = this.shadowOffsetY;\r\n }\r\n\r\n context.fillStyle = this._isEnabled ? this._background : this._disabledColor;\r\n context.fillRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);\r\n\r\n if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {\r\n context.shadowBlur = 0;\r\n context.shadowOffsetX = 0;\r\n context.shadowOffsetY = 0;\r\n }\r\n\r\n if (this._isChecked) {\r\n // Color is white if not set\r\n context.fillStyle = this._isEnabled ? (this.color ? this.color : \"#ffffff\") : this._disabledColorItem;\r\n const offsetWidth = actualWidth * this._checkSizeRatio;\r\n const offsetHeight = actualHeight * this._checkSizeRatio;\r\n\r\n context.fillRect(\r\n this._currentMeasure.left + this._thickness / 2 + (actualWidth - offsetWidth) / 2,\r\n this._currentMeasure.top + this._thickness / 2 + (actualHeight - offsetHeight) / 2,\r\n offsetWidth,\r\n offsetHeight\r\n );\r\n }\r\n\r\n context.strokeStyle = this.color;\r\n context.lineWidth = this._thickness;\r\n\r\n context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, actualWidth, actualHeight);\r\n\r\n context.restore();\r\n }\r\n\r\n // Events\r\n\r\n /**\r\n * @internal\r\n */\r\n public override _onPointerDown(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, pi: PointerInfoBase): boolean {\r\n if (!super._onPointerDown(target, coordinates, pointerId, buttonIndex, pi)) {\r\n return false;\r\n }\r\n\r\n if (!this.isReadOnly) {\r\n this.isChecked = !this.isChecked;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Utility function to easily create a checkbox with a header\r\n * @param title defines the label to use for the header\r\n * @param onValueChanged defines the callback to call when value changes\r\n * @returns a StackPanel containing the checkbox and a textBlock\r\n */\r\n public static AddCheckBoxWithHeader(title: string, onValueChanged: (value: boolean) => void): StackPanel {\r\n const panel = new StackPanel();\r\n panel.isVertical = false;\r\n panel.height = \"30px\";\r\n\r\n const checkbox = new Checkbox();\r\n checkbox.width = \"20px\";\r\n checkbox.height = \"20px\";\r\n checkbox.isChecked = true;\r\n checkbox.color = \"green\";\r\n checkbox.onIsCheckedChangedObservable.add(onValueChanged);\r\n panel.addControl(checkbox);\r\n\r\n const header = new TextBlock();\r\n header.text = title;\r\n header.width = \"180px\";\r\n header.paddingLeft = \"5px\";\r\n header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;\r\n header.color = \"white\";\r\n panel.addControl(header);\r\n\r\n return panel;\r\n }\r\n}\r\nRegisterClass(\"BABYLON.GUI.Checkbox\", Checkbox);\r\n"]}
|