@@ -28,7 +28,7 @@ public record struct ColorThreshold(double Threshold, Color Color);
2828 /// A horizontal bar graph control for visualizing percentage-based data.
2929 /// Displays a filled/unfilled bar with optional label, value, and custom colors.
3030 /// </summary>
31- public class BarGraphControl : IWindowControl , IDOMPaintable
31+ public class BarGraphControl : BaseControl
3232 {
3333 private const int DEFAULT_BAR_WIDTH = 20 ;
3434 private const char FILLED_CHAR = '█' ;
@@ -39,30 +39,19 @@ public class BarGraphControl : IWindowControl, IDOMPaintable
3939 private IContainer ? _container ;
4040 private Color _filledColor = Color . Cyan1 ;
4141 private Color ? _foregroundColorValue ;
42- private HorizontalAlignment _horizontalAlignment = HorizontalAlignment . Left ;
4342 private string _label = string . Empty ;
4443 private int ? _labelWidth ;
45- private Margin _margin = new Margin ( 0 , 0 , 0 , 0 ) ;
4644 private double _maxValue = 100.0 ;
4745 private bool _showLabel = true ;
4846 private bool _showValue = true ;
49- private StickyPosition _stickyPosition = StickyPosition . None ;
5047 private Color _unfilledColor = Color . Grey35 ;
5148 private double _value ;
5249 private string _valueFormat = "F1" ;
5350 private List < ColorThreshold > ? _colorThresholds ;
54- private VerticalAlignment _verticalAlignment = VerticalAlignment . Top ;
55- private bool _visible = true ;
56- private int ? _width ;
5751
5852 // Gradient support
5953 private ColorGradient ? _smoothGradient ;
6054
61- private int _actualX ;
62- private int _actualY ;
63- private int _actualWidth ;
64- private int _actualHeight ;
65-
6655 /// <summary>
6756 /// Initializes a new instance of the <see cref="BarGraphControl"/> class.
6857 /// </summary>
@@ -279,25 +268,13 @@ public ColorGradient? SmoothGradient
279268 }
280269 }
281270
282- #region IWindowControl Implementation
283-
284- /// <inheritdoc/>
285- public int ? ContentWidth => _width ;
286-
287- /// <inheritdoc/>
288- public int ActualX => _actualX ;
289-
290- /// <inheritdoc/>
291- public int ActualY => _actualY ;
271+ #region BaseControl Overrides
292272
293273 /// <inheritdoc/>
294- public int ActualWidth => _actualWidth ;
274+ public override int ? ContentWidth => Width ;
295275
296276 /// <inheritdoc/>
297- public int ActualHeight => _actualHeight ;
298-
299- /// <inheritdoc/>
300- public IContainer ? Container
277+ public override IContainer ? Container
301278 {
302279 get => _container ;
303280 set
@@ -308,94 +285,46 @@ public IContainer? Container
308285 }
309286
310287 /// <inheritdoc/>
311- public HorizontalAlignment HorizontalAlignment
288+ public override Margin Margin
312289 {
313- get => _horizontalAlignment ;
314- set => PropertySetterHelper . SetEnumProperty ( ref _horizontalAlignment , value , Container ) ;
315- }
316-
317- /// <inheritdoc/>
318- public Margin Margin
319- {
320- get => _margin ;
290+ get => base . Margin ;
321291 set
322292 {
323- _margin = value ;
324- Container ? . Invalidate ( true ) ;
293+ base . Margin = value ;
325294 }
326295 }
327296
328297 /// <inheritdoc/>
329- public string ? Name { get ; set ; }
330-
331- /// <inheritdoc/>
332- public StickyPosition StickyPosition
333- {
334- get => _stickyPosition ;
335- set => PropertySetterHelper . SetEnumProperty ( ref _stickyPosition , value , Container ) ;
336- }
337-
338- /// <inheritdoc/>
339- public object ? Tag { get ; set ; }
340-
341- /// <inheritdoc/>
342- public VerticalAlignment VerticalAlignment
343- {
344- get => _verticalAlignment ;
345- set => PropertySetterHelper . SetEnumProperty ( ref _verticalAlignment , value , Container ) ;
346- }
347-
348- /// <inheritdoc/>
349- public bool Visible
298+ public override int ? Width
350299 {
351- get => _visible ;
352- set => PropertySetterHelper . SetBoolProperty ( ref _visible , value , Container ) ;
353- }
354-
355- /// <inheritdoc/>
356- public int ? Width
357- {
358- get => _width ;
300+ get => base . Width ;
359301 set
360302 {
361303 var validatedValue = value . HasValue ? Math . Max ( 1 , value . Value ) : ( int ? ) null ;
362- if ( _width != validatedValue )
304+ if ( base . Width != validatedValue )
363305 {
364- _width = validatedValue ;
365- Container ? . Invalidate ( true ) ;
306+ base . Width = validatedValue ;
366307 }
367308 }
368309 }
369310
370311 /// <inheritdoc/>
371- public void Dispose ( )
372- {
373- Container = null ;
374- }
375-
376- /// <inheritdoc/>
377- public Size GetLogicalContentSize ( )
312+ public override Size GetLogicalContentSize ( )
378313 {
379314 int contentWidth = CalculateContentWidth ( ) ;
380- return new Size ( contentWidth + _margin . Left + _margin . Right , 1 + _margin . Top + _margin . Bottom ) ;
381- }
382-
383- /// <inheritdoc/>
384- public void Invalidate ( )
385- {
386- Container ? . Invalidate ( false ) ;
315+ return new Size ( contentWidth + Margin . Left + Margin . Right , 1 + Margin . Top + Margin . Bottom ) ;
387316 }
388317
389318 #endregion
390319
391320 #region IDOMPaintable Implementation
392321
393322 /// <inheritdoc/>
394- public LayoutSize MeasureDOM ( LayoutConstraints constraints )
323+ public override LayoutSize MeasureDOM ( LayoutConstraints constraints )
395324 {
396325 int contentWidth = CalculateContentWidth ( ) ;
397- int width = contentWidth + _margin . Left + _margin . Right ;
398- int height = 1 + _margin . Top + _margin . Bottom ;
326+ int width = contentWidth + Margin . Left + Margin . Right ;
327+ int height = 1 + Margin . Top + Margin . Bottom ;
399328
400329 return new LayoutSize (
401330 Math . Clamp ( width , constraints . MinWidth , constraints . MaxWidth ) ,
@@ -404,19 +333,16 @@ public LayoutSize MeasureDOM(LayoutConstraints constraints)
404333 }
405334
406335 /// <inheritdoc/>
407- public void PaintDOM ( CharacterBuffer buffer , LayoutRect bounds , LayoutRect clipRect , Color defaultFg , Color defaultBg )
336+ public override void PaintDOM ( CharacterBuffer buffer , LayoutRect bounds , LayoutRect clipRect , Color defaultFg , Color defaultBg )
408337 {
409- _actualX = bounds . X ;
410- _actualY = bounds . Y ;
411- _actualWidth = bounds . Width ;
412- _actualHeight = bounds . Height ;
338+ SetActualBounds ( bounds ) ;
413339
414340 // Resolve colors
415341 Color bgColor = _backgroundColorValue ?? Container ? . BackgroundColor ?? defaultBg ;
416342 Color fgColor = _foregroundColorValue ?? Container ? . ForegroundColor ?? defaultFg ;
417343
418- int startX = bounds . X + _margin . Left ;
419- int startY = bounds . Y + _margin . Top ;
344+ int startX = bounds . X + Margin . Left ;
345+ int startY = bounds . Y + Margin . Top ;
420346 int paintY = startY ;
421347
422348 if ( paintY < clipRect . Y || paintY >= clipRect . Bottom || paintY >= bounds . Bottom )
0 commit comments