@@ -143,6 +143,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
143143
144144 for (uint8_t i = 0 ; i < this -> curItems ; i ++ ) {
145145 double value = this -> values [i ];
146+ int actualWidth = 0 ;
146147
147148 // ignore extremely small values
148149 if ((value / this -> total ) * wsub < 0.5 ){
@@ -151,16 +152,17 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
151152 }
152153 if (isPositive (value ) && this -> total > 0.0 ) {
153154 value = MINIMUM (value , this -> total );
154- blockSizes [i ] = ceil ((value / this -> total ) * wsub );
155+ actualWidth = ceil ((value / this -> total ) * wsub );
156+ blockSizes [i ] = ceil ((value / this -> total ) * w );
155157 } else {
156158 blockSizes [i ] = 0 ;
157159 }
158160 int nextOffset = offset + blockSizes [i ];
159161 // (Control against invalid values)
160- nextOffset = CLAMP (nextOffset , 0 , wsub );
162+ nextOffset = CLAMP (nextOffset , 0 , w );
161163
162164
163- for (int j = offset / barLen ; j < nextOffset / barLen ; j ++ ){
165+ for (int j = offset ; j < nextOffset ; j ++ ){
164166 if (RichString_getCharVal (bar , startPos + j ) == ' ' ) {
165167 if (CRT_colorScheme == COLORSCHEME_MONOCHROME ) {
166168 assert (i < strlen (BarMeterMode_characters ));
@@ -173,7 +175,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
173175 }
174176 }
175177
176- RichString_setChar (& bar , startPos + nextOffset / barLen , barChar [blockSizes [ i ] % barLen ]);
178+ RichString_setChar (& bar , startPos + nextOffset - 1 , barChar [actualWidth % barLen ]);
177179
178180 offset = nextOffset ;
179181 }
@@ -182,9 +184,9 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
182184 offset = 0 ;
183185 for (uint8_t i = 0 ; i < this -> curItems ; i ++ ) {
184186 int attr = this -> curAttributes ? this -> curAttributes [i ] : Meter_attributes (this )[i ];
185- RichString_setAttrn (& bar , CRT_colors [attr ], startPos + offset , ceil (( double ) blockSizes [i ]/ barLen ));
186- RichString_printoffnVal (bar , y , x + offset , startPos + offset , MINIMUM (ceil (( double ) blockSizes [i ]/ barLen ), w - offset ));
187- offset += ceil ((double )blockSizes [i ]/ barLen );
187+ RichString_setAttrn (& bar , CRT_colors [attr ], startPos + offset , ceil (blockSizes [i ]));
188+ RichString_printoffnVal (bar , y , x + offset , startPos + offset , MINIMUM (ceil (blockSizes [i ]), w - offset ));
189+ offset += ceil ((double )blockSizes [i ]);
188190 offset = CLAMP (offset , 0 , w );
189191 }
190192 if (offset < w ) {
0 commit comments