import { Nullable } from "babylonjs/types" ; import { Vector2 } from "babylonjs/Maths/math.vector" ; import { Button } from "./button" ; import { Control } from "./control" ; import { RegisterClass } from 'babylonjs/Misc/typeStore' ; import { PointerInfoBase } from 'babylonjs/Events/pointerEvents' ; import { IFocusableControl } from "./focusableControl" ; import { Observable } from 'babylonjs/Misc/observable' ; import { IKeyboardEvent } from "babylonjs/Events/deviceInputEvents" ; since export class FocusableButton extends Button implements IFocusableControl { /** Highlight color when button is focused */ public focusedColor : Nullable < string > = null ; private _isFocused = false ; private _unfocusedColor : Nullable < string > = null ; /** Observable raised when the control gets the focus */ public onFocusObservable = new Observable < Button > ( ) ; /** Observable raised when the control loses the focus */ public onBlurObservable = new Observable < Button > ( ) ; /** Observable raised when a key event was processed */ public onKeyboardEventProcessedObservable = new Observable < IKeyboardEvent > ( ) ; constructor ( public name ? ) { super ( name ) ; this . _unfocusedColor = this . color ; } hidden public onBlur ( ) { if ( this . _isFocused ) { this . _isFocused = false ; if ( this . focusedColor && this . _unfocusedColor != null ) { this . color = this . _unfocusedColor ; } this . onBlurObservable . notifyObservers ( this ) ; } } hidden public onFocus ( ) { this . _isFocused = true ; if ( this . focusedColor ) { this . _unfocusedColor = this . color ; this . color = this . focusedColor ; } this . onFocusObservable . notifyObservers ( this ) ; } returns public keepsFocusWith ( ) { return null ; } /**
     * Function to focus a button programmatically
     */ public focus ( ) { this . _host . moveFocusToControl ( this ) ; } /**
     * Function to unfocus a button programmatically
     */ public blur ( ) { this . _host . focusedControl = null ; } param evt public processKeyboard ( evt ) { this . onKeyboardEventProcessedObservable . notifyObservers ( evt , - 1 , this ) ; } hidden public _onPointerDown ( target , coordinates , pointerId , buttonIndex , pi ) { if ( ! this . isReadOnly ) { this . focus ( ) ; } return super . _onPointerDown ( target , coordinates , pointerId , buttonIndex , pi ) ; } hidden public displose ( ) { super . dispose ( ) ; this . onBlurObservable . clear ( ) ; this . onFocusObservable . clear ( ) ; this . onKeyboardEventProcessedObservable . clear ( ) ; } } RegisterClass ( "BABYLON.GUI.FocusableButton" , FocusableButton ) ;