@@ -858,6 +858,90 @@ namespace microcode {
858858 }
859859
860860
861+ export class TextButton {
862+ public bounds : Bounds ;
863+ private text : string ;
864+ private callback : ( x : any ) => void ;
865+ private colour : number ;
866+ private textColour : number ;
867+
868+ constructor ( opts : {
869+ text : string ,
870+ callback : ( x : any ) => void ,
871+ x ?: number ,
872+ y ?: number
873+ colour ?: number ,
874+ textColour ?: number
875+ } ) {
876+ this . text = opts . text ;
877+
878+ const x = ( opts . x != null ) ? opts . x : 0 ;
879+ const y = ( opts . y != null ) ? opts . y : 0 ;
880+ this . bounds = new Bounds ( { top : y , left : x , width : ( font . charWidth * this . text . length ) , height : font . charHeight + 2 } ) ;
881+ this . callback = opts . callback ;
882+ this . colour = ( opts . colour != null ) ? opts . colour : 6 ;
883+ this . textColour = ( opts . textColour != null ) ? opts . textColour : 1 ;
884+ }
885+
886+ draw ( ) {
887+ this . bounds . fillRect ( this . colour ) ;
888+ screen ( ) . print (
889+ this . text ,
890+ this . bounds . left + ( screen ( ) . width >> 1 ) + 1 ,
891+ this . bounds . top + ( screen ( ) . height >> 1 ) + 1 ,
892+ this . textColour
893+ )
894+ }
895+ }
896+
897+
898+ export class TextButtonCollection extends GUIComponentAbstract {
899+ private textBtns : TextButton [ ] ;
900+
901+ constructor ( opts : {
902+ alignment : GUIComponentAlignment ,
903+ isActive : boolean ,
904+ textBtns : TextButton [ ] ,
905+ isHidden ?: boolean ,
906+ xOffset ?: number ,
907+ yOffset ?: number ,
908+ xScaling ?: number ,
909+ yScaling ?: number ,
910+ colour ?: number ,
911+ border ?: boolean ,
912+ title ?: string ,
913+ text ?: string | string [ ]
914+ } ) {
915+ super ( {
916+ alignment : opts . alignment ,
917+ xOffset : ( opts . xOffset != null ) ? opts . xOffset : 0 ,
918+ yOffset : ( opts . yOffset != null ) ? opts . yOffset : 0 ,
919+ width : GUIComponentAbstract . DEFAULT_WIDTH ,
920+ height : GUIComponentAbstract . DEFAULT_HEIGHT ,
921+ isActive : opts . isActive ,
922+ isHidden : opts . isHidden ,
923+ xScaling : opts . xScaling ,
924+ yScaling : opts . yScaling ,
925+ colour : opts . colour ,
926+ border : opts . border
927+ } ) ;
928+
929+ this . textBtns = ( opts . textBtns != null ) ? opts . textBtns : [ ] ;
930+
931+ this . textBtns . forEach ( btn => {
932+ btn . bounds . left += this . bounds . left ;
933+ btn . bounds . top += this . bounds . top ;
934+ } )
935+ }
936+
937+ draw ( ) {
938+ super . draw ( ) ;
939+
940+ this . textBtns . forEach ( btn => btn . draw ( ) )
941+ }
942+ }
943+
944+
861945 /**
862946 * Holds other components,
863947 * One component is active at a time
0 commit comments