@@ -1265,6 +1265,10 @@ namespace microgui {
12651265 border : opts . border
12661266 } )
12671267
1268+ // Set to null in case the opts.btns are [[]].
1269+ // This is checked before drawing.
1270+ this . cursorBounds = null ;
1271+
12681272 if ( opts . btns != null ) {
12691273 this . btns = opts . btns ;
12701274
@@ -1281,16 +1285,26 @@ namespace microgui {
12811285 this . numberOfCols = this . btns . map ( row => row . length )
12821286 this . numberOfRows = this . btns . length
12831287
1284- this . cursorBounds = new Bounds ( {
1285- width : this . btns [ 0 ] [ 0 ] . width + 4 ,
1286- height : this . btns [ 0 ] [ 0 ] . height + 4 ,
1287- left : this . btns [ 0 ] [ 0 ] . xfrm . localPos . x - ( this . btns [ 0 ] [ 0 ] . width >> 1 ) - 2 ,
1288- top : this . btns [ 0 ] [ 0 ] . xfrm . localPos . y - ( this . btns [ 0 ] [ 0 ] . height >> 1 ) - 2
1289- } )
1290- this . cursorOutlineColour = ( opts . cursorColour != null ) ? opts . cursorColour : 9 ; // Default is light blue
1291- this . cursorRow = 0 ;
1292- this . cursorCol = 0 ;
1288+ // Its possible the programmer makes the first row empty and fills it later:
1289+ let startingRow = null ;
1290+ for ( let i = 0 ; i < this . numberOfRows ; i ++ ) {
1291+ if ( this . numberOfCols [ i ] > 0 ) {
1292+ startingRow = i ;
1293+ break ;
1294+ }
1295+ }
12931296
1297+ if ( startingRow != null ) {
1298+ this . cursorBounds = new Bounds ( {
1299+ width : this . btns [ 0 ] [ 0 ] . width + 4 ,
1300+ height : this . btns [ 0 ] [ 0 ] . height + 4 ,
1301+ left : this . btns [ 0 ] [ 0 ] . xfrm . localPos . x - ( this . btns [ 0 ] [ 0 ] . width >> 1 ) - 2 ,
1302+ top : this . btns [ 0 ] [ 0 ] . xfrm . localPos . y - ( this . btns [ 0 ] [ 0 ] . height >> 1 ) - 2
1303+ } )
1304+ this . cursorOutlineColour = ( opts . cursorColour != null ) ? opts . cursorColour : 9 ; // Default is light blue
1305+ this . cursorRow = startingRow ;
1306+ this . cursorCol = 0 ;
1307+ }
12941308 if ( this . isActive )
12951309 this . bindShieldButtons ( )
12961310 }
@@ -1426,13 +1440,13 @@ namespace microgui {
14261440 draw ( ) {
14271441 if ( ! this . isHidden ) {
14281442 super . draw ( )
1429- if ( this . isActive ) {
1443+ if ( this . isActive && this . cursorBounds != null ) {
14301444 this . drawCursor ( )
14311445 }
14321446
14331447 this . btns . forEach ( btnRow => btnRow . forEach ( btn => btn . draw ( ) ) )
14341448
1435- if ( this . isActive ) {
1449+ if ( this . isActive && this . cursorBounds != null ) {
14361450 this . drawCursorText ( )
14371451 }
14381452 }
0 commit comments