@@ -4,7 +4,9 @@ enum ToolbarColorAttribute {
44 //% block="selected outline"
55 BoxSelectedOutline ,
66 //% block="background"
7- BoxBackground
7+ BoxBackground ,
8+ //% block="text"
9+ BoxText
810}
911
1012enum InventoryColorAttribute {
@@ -164,6 +166,7 @@ namespace Inventory {
164166 private _box_outline_color : number = 12 ;
165167 private _box_selected_outline_color : number = 5 ;
166168 private _box_background_color : number = 13 ;
169+ private _box_text_color : number = 12 ;
167170
168171 /**
169172 * Make a toolbar.
@@ -297,6 +300,8 @@ namespace Inventory {
297300 this . _box_selected_outline_color = color ;
298301 } else if ( attribute == ToolbarColorAttribute . BoxBackground ) {
299302 this . _box_background_color = color ;
303+ } else if ( attribute == ToolbarColorAttribute . BoxText ) {
304+ this . _box_text_color = color ;
300305 }
301306 this . update ( ) ;
302307 }
@@ -316,6 +321,8 @@ namespace Inventory {
316321 return this . _box_selected_outline_color ;
317322 } else if ( attribute == ToolbarColorAttribute . BoxBackground ) {
318323 return this . _box_background_color ;
324+ } else if ( attribute == ToolbarColorAttribute . BoxText ) {
325+ return this . _box_text_color ;
319326 }
320327 return - 1 ;
321328 }
@@ -344,11 +351,10 @@ namespace Inventory {
344351 box_size ,
345352 this . _box_background_color
346353 )
354+ let x : number = ( ( box_size + padding ) * index ) + 2 ;
355+ let y : number = 2 ;
347356 if ( index < this . items . length ) {
348- spriteutils . drawTransparentImage (
349- this . items [ index ] . image , new_image ,
350- ( ( box_size + padding ) * index ) + 2 , 2
351- )
357+ spriteutils . drawTransparentImage ( this . items [ index ] . image , new_image , x , y )
352358 }
353359 new_image . drawRect (
354360 ( box_size + padding ) * index ,
@@ -357,10 +363,31 @@ namespace Inventory {
357363 box_size ,
358364 index == this . selected ? this . _box_selected_outline_color : this . _box_outline_color
359365 )
360-
366+ if ( index < this . items . length ) {
367+ this . print_right_aligned ( new_image , this . items [ index ] . tooltip ,
368+ x + box_size - 3 , y + ( box_size - 5 ) - 4 , this . _box_text_color ,
369+ true ) ;
370+ }
361371 }
362372 this . setImage ( new_image ) ;
363373 }
374+
375+ /**
376+ * Print some text right-aligned
377+ * @param target: The image to draw too.
378+ * @param text: The text to draw.
379+ * @param right: the X coordinate of the right of the text.
380+ * @param y: The Y coordinate of the text.
381+ * @param color: The color of the text.
382+ * @param use_small_font: Whether to use the 5x5 instead of the 5x8 font.
383+ */
384+ private print_right_aligned ( target : Image , text : string ,
385+ right : number , y : number ,
386+ color : number , use_small_font : boolean = false ) {
387+ let text_length_px : number = text . length * 6 ;
388+ let label_x : number = right - text_length_px ;
389+ target . print ( text , label_x , y , color , use_small_font ? image . font5 : image . font8 ) ;
390+ }
364391 }
365392
366393 /**
@@ -628,13 +655,22 @@ namespace Inventory {
628655 }
629656 spriteutils . drawTransparentImage ( this . items [ index ] . image , new_image , x , y ) ;
630657 this . print_right_aligned ( new_image , this . items [ index ] . tooltip ,
631- x + box_size , y + ( box_size - 3 ) , this . _inv_text_color ,
658+ x + box_size , y + ( box_size - 5 ) - 1 , this . _inv_text_color ,
632659 true ) ;
633660 }
634661 }
635662 this . setImage ( new_image ) ;
636663 }
637664
665+ /**
666+ * Print some text right-aligned
667+ * @param target: The image to draw too.
668+ * @param text: The text to draw.
669+ * @param right: the X coordinate of the right of the text.
670+ * @param y: The Y coordinate of the text.
671+ * @param color: The color of the text.
672+ * @param use_small_font: Whether to use the 5x5 instead of the 5x8 font.
673+ */
638674 private print_right_aligned ( target : Image , text : string ,
639675 right : number , y : number ,
640676 color : number , use_small_font : boolean = false ) {
0 commit comments