@@ -22,7 +22,9 @@ enum ItemTextAttribute {
2222 //% block="name"
2323 Name ,
2424 //% block="description"
25- Description
25+ Description ,
26+ //% block="tooltip"
27+ Tooltip
2628}
2729
2830enum ToolbarNumberAttribute {
@@ -53,6 +55,7 @@ namespace Inventory {
5355 public name : string ;
5456 public image : Image ;
5557 public description : string ;
58+ public tooltip : string = ""
5659
5760 /**
5861 * Make a simple item.
@@ -81,6 +84,8 @@ namespace Inventory {
8184 this . name = value ;
8285 } else if ( attribute == ItemTextAttribute . Description ) {
8386 this . description = value ;
87+ } else if ( attribute == ItemTextAttribute . Tooltip ) {
88+ this . tooltip = value ;
8489 }
8590 }
8691
@@ -97,6 +102,8 @@ namespace Inventory {
97102 return this . name ;
98103 } else if ( attribute == ItemTextAttribute . Description ) {
99104 return this . description ;
105+ } else if ( attribute == ItemTextAttribute . Tooltip ) {
106+ return this . tooltip ;
100107 }
101108 return "" ;
102109 }
@@ -605,9 +612,7 @@ namespace Inventory {
605612 new_image . print ( this . text , 2 , 2 , this . _inv_text_color ) ;
606613 if ( this . selected < this . items . length && this . selected != - 1 ) {
607614 let text : string = this . items [ this . selected ] . name ;
608- let text_length_px : number = text . length * 6 ;
609- let label_x : number = width - 2 - text_length_px ;
610- new_image . print ( text , label_x , 2 , this . _inv_text_color ) ;
615+ this . print_right_aligned ( new_image , text , width - 2 , 2 , this . _inv_text_color , false ) ;
611616 }
612617 new_image . drawLine ( 2 , 11 , width - 3 , 11 , this . _inv_outline_color ) ;
613618 for ( let index = 0 ; index < this . max_items ; index ++ ) {
@@ -622,10 +627,21 @@ namespace Inventory {
622627 this . _inv_selected_outline_color ) ;
623628 }
624629 spriteutils . drawTransparentImage ( this . items [ index ] . image , new_image , x , y ) ;
630+ this . print_right_aligned ( new_image , this . items [ index ] . tooltip ,
631+ x + box_size , y + ( box_size - 3 ) , this . _inv_text_color ,
632+ true ) ;
625633 }
626634 }
627635 this . setImage ( new_image ) ;
628636 }
637+
638+ private print_right_aligned ( target : Image , text : string ,
639+ right : number , y : number ,
640+ color : number , use_small_font : boolean = false ) {
641+ let text_length_px : number = text . length * 6 ;
642+ let label_x : number = right - text_length_px ;
643+ target . print ( text , label_x , y , color , use_small_font ? image . font5 : image . font8 ) ;
644+ }
629645 }
630646
631647 /**
0 commit comments