@@ -198,7 +198,8 @@ def bar(self, val, max_val=100, y_offset=0, color=LIGHT):
198198 if fill_w > 0 :
199199 self ._fill_rect (bx , by , fill_w , bar_h , color )
200200
201- def gauge (self , val , min_val = 0 , max_val = 100 , unit = None , color = LIGHT ):
201+
202+ def gauge (self , val , min_val = 0 , max_val = 100 , color = LIGHT ):
202203 """Draw a circular arc gauge (270 deg, gap at bottom).
203204
204205 The arc is drawn close to the screen border. Call gauge() before
@@ -217,28 +218,7 @@ def gauge(self, val, min_val=0, max_val=100, unit=None, color=LIGHT):
217218 # Filled arc
218219 if ratio > 0 :
219220 self ._draw_arc (cx , cy , r , start_angle , int (sweep * ratio ),
220- color , arc_w )
221-
222- # Value + unit centered as a block
223- text = str (val )
224- char_h = self .CHAR_H * 2 # scale=2
225- tw = len (text ) * self .CHAR_W * 2
226- if unit :
227- gap = char_h // 3
228- unit_h = self .CHAR_H
229- block_h = char_h + gap + unit_h
230- vy = cy - block_h // 2
231- else :
232- vy = cy - char_h // 2
233- vx = cx - tw // 2
234- self ._draw_scaled_text (text , vx , vy , WHITE , 2 )
235- if unit :
236- ux = cx - len (unit ) * self .CHAR_W // 2
237- uy = vy + char_h + gap
238- if hasattr (self ._d , 'draw_medium_text' ):
239- self ._d .draw_medium_text (unit , ux , uy , LIGHT )
240- else :
241- self ._d .text (unit , ux , uy , LIGHT )
221+ color , arc_w + 2 ) # +1 to fill gaps between segments
242222
243223 # Min/max labels at arc endpoints (slightly inward to stay visible)
244224 min_t = str (int (min_val ))
@@ -592,20 +572,37 @@ def _draw_scaled_text(self, text, x, y, color, scale):
592572 self ._d .text (text , x , y , color )
593573
594574 def _draw_arc (self , cx , cy , r , start_deg , sweep_deg , color , width = 3 ):
595- """Draw a thick arc using individual pixels ."""
575+ """Draw a thick arc."""
596576 if hasattr (self ._d , 'draw_arc' ):
597577 self ._d .draw_arc (cx , cy , r , start_deg , sweep_deg , color , width )
598578 return
599- steps = max (sweep_deg , 60 )
579+
580+ # Number of steps based on arc length, with oversampling to avoid gaps
581+ arc_len = abs (math .radians (sweep_deg ) * r )
582+ steps = max (int (arc_len * 2 ), 1 ) # Oversample to avoid gaps
600583 half_w = width // 2
584+
585+ prev_points = None
586+
601587 for i in range (steps + 1 ):
602588 angle = math .radians (start_deg + i * sweep_deg / steps )
589+
590+ curr_points = []
603591 for dr in range (- half_w , half_w + 1 ):
604- x = int (cx + (r + dr ) * math .cos (angle ))
605- y = int (cy + (r + dr ) * math .sin (angle ))
606- if 0 <= x < self .width and 0 <= y < self .height :
592+ rr = r + dr
593+ x = round (cx + rr * math .cos (angle ))
594+ y = round (cy + rr * math .sin (angle ))
595+ curr_points .append ((x , y ))
596+
597+ if prev_points is None and 0 <= x < self .width and 0 <= y < self .height :
607598 self ._d .pixel (x , y , color )
608599
600+ if prev_points is not None :
601+ for (x0 , y0 ), (x1 , y1 ) in zip (prev_points , curr_points ):
602+ self ._line (x0 , y0 , x1 , y1 , color )
603+
604+ prev_points = curr_points
605+
609606 def _draw_circle (self , cx , cy , r , color ):
610607 """Bresenham circle."""
611608 x , y , d = r , 0 , 1 - r
0 commit comments