presentar-terminal 0.3.5

Terminal backend for Presentar UI framework with zero-allocation rendering
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
//! Arc/circular gauge widget.
//!
//! Displays a value as an arc gauge using Unicode box-drawing characters.
//! Useful for compact metric displays like CPU temperature or utilization.

use presentar_core::{
    Brick, BrickAssertion, BrickBudget, BrickVerification, Canvas, Color, Constraints, Event,
    LayoutResult, Point, Rect, Size, TextStyle, TypeId, Widget,
};
use std::any::Any;
use std::time::Duration;

/// Gauge display mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum GaugeMode {
    /// Full arc (360° - ╭───╮).
    #[default]
    Arc,
    /// Quarter arc (90° - bottom-right corner).
    Quarter,
    /// Half arc (180° - bottom semicircle ╰───╯).
    Half,
    /// Three-quarter arc (270° - U-shape open at top-left).
    ThreeQuarter,
    /// Vertical bar with ticks.
    Vertical,
    /// Compact single-line.
    Compact,
}

/// Arc gauge widget using Unicode characters.
#[derive(Debug, Clone)]
pub struct Gauge {
    /// Current value.
    value: f64,
    /// Maximum value.
    max: f64,
    /// Gauge label.
    label: Option<String>,
    /// Display mode.
    mode: GaugeMode,
    /// Gauge color.
    color: Color,
    /// Warning threshold (percentage).
    warn_threshold: f64,
    /// Critical threshold (percentage).
    critical_threshold: f64,
    /// Show value text.
    show_value: bool,
    /// Unit suffix (e.g., "°C", "%").
    unit: Option<String>,
    /// Cached bounds.
    bounds: Rect,
}

impl Default for Gauge {
    fn default() -> Self {
        Self::new(0.0, 100.0)
    }
}

impl Gauge {
    /// Create a new gauge with value and max.
    #[must_use]
    pub fn new(value: f64, max: f64) -> Self {
        Self {
            value: value.clamp(0.0, max),
            max,
            label: None,
            mode: GaugeMode::default(),
            color: Color::new(0.3, 0.7, 1.0, 1.0),
            warn_threshold: 70.0,
            critical_threshold: 90.0,
            show_value: true,
            unit: None,
            bounds: Rect::default(),
        }
    }

    /// Create a percentage gauge (0-100).
    #[must_use]
    pub fn percentage(value: f64) -> Self {
        Self::new(value, 100.0).with_unit("%")
    }

    /// Create a temperature gauge.
    #[must_use]
    pub fn temperature(value: f64, max: f64) -> Self {
        Self::new(value, max)
            .with_unit("°C")
            .with_thresholds(60.0, 80.0)
    }

    /// Set the label.
    #[must_use]
    pub fn with_label(mut self, label: impl Into<String>) -> Self {
        self.label = Some(label.into());
        self
    }

    /// Set the display mode.
    #[must_use]
    pub fn with_mode(mut self, mode: GaugeMode) -> Self {
        self.mode = mode;
        self
    }

    /// Set the color.
    #[must_use]
    pub fn with_color(mut self, color: Color) -> Self {
        self.color = color;
        self
    }

    /// Set warning and critical thresholds.
    #[must_use]
    pub fn with_thresholds(mut self, warn: f64, critical: f64) -> Self {
        self.warn_threshold = warn;
        self.critical_threshold = critical;
        self
    }

    /// Set whether to show value text.
    #[must_use]
    pub fn with_value_display(mut self, show: bool) -> Self {
        self.show_value = show;
        self
    }

    /// Set unit suffix.
    #[must_use]
    pub fn with_unit(mut self, unit: impl Into<String>) -> Self {
        self.unit = Some(unit.into());
        self
    }

    /// Update the value.
    pub fn set_value(&mut self, value: f64) {
        self.value = value.clamp(0.0, self.max);
    }

    /// Get current value.
    #[must_use]
    pub fn value(&self) -> f64 {
        self.value
    }

    /// Get percentage (0-100).
    #[must_use]
    pub fn percent(&self) -> f64 {
        if self.max == 0.0 {
            0.0
        } else {
            (self.value / self.max * 100.0).clamp(0.0, 100.0)
        }
    }

    /// Get current color based on thresholds.
    #[must_use]
    pub fn current_color(&self) -> Color {
        let pct = self.percent();
        if pct >= self.critical_threshold {
            Color::new(1.0, 0.3, 0.3, 1.0) // Red
        } else if pct >= self.warn_threshold {
            Color::new(1.0, 0.7, 0.2, 1.0) // Orange
        } else {
            self.color
        }
    }

    fn render_arc(&self, canvas: &mut dyn Canvas) {
        let width = self.bounds.width as usize;
        let height = self.bounds.height as usize;

        if width < 5 || height < 3 {
            // Fall back to compact mode
            self.render_compact(canvas);
            return;
        }

        let color = self.current_color();
        let style = TextStyle {
            color,
            ..Default::default()
        };
        let dim_style = TextStyle {
            color: Color::new(0.3, 0.3, 0.3, 1.0),
            ..Default::default()
        };

        // Arc characters
        let pct = self.percent() / 100.0;
        let arc_width = width.saturating_sub(2);
        let filled = ((pct * arc_width as f64).round() as usize).min(arc_width);

        // Top of arc: ╭───╮
        let mut top = String::with_capacity(width);
        top.push('');
        for i in 0..arc_width {
            if i < filled {
                top.push('');
            } else {
                top.push('');
            }
        }
        top.push('');
        canvas.draw_text(&top, Point::new(self.bounds.x, self.bounds.y), &style);

        // Middle: │ value │
        if height > 2 {
            let value_text = if self.show_value {
                let unit = self.unit.as_deref().unwrap_or("");
                format!("{:.0}{}", self.value, unit)
            } else {
                String::new()
            };
            let padding = (arc_width.saturating_sub(value_text.len())) / 2;
            let mut middle = String::with_capacity(width);
            middle.push('');
            for _ in 0..padding {
                middle.push(' ');
            }
            middle.push_str(&value_text);
            for _ in 0..(arc_width - padding - value_text.len()) {
                middle.push(' ');
            }
            middle.push('');
            canvas.draw_text(
                &middle,
                Point::new(self.bounds.x, self.bounds.y + 1.0),
                &dim_style,
            );
        }

        // Bottom of arc: ╰───╯
        if height > 1 {
            let mut bottom = String::with_capacity(width);
            bottom.push('');
            for _ in 0..arc_width {
                bottom.push('');
            }
            bottom.push('');
            let y = if height > 2 {
                self.bounds.y + 2.0
            } else {
                self.bounds.y + 1.0
            };
            canvas.draw_text(&bottom, Point::new(self.bounds.x, y), &dim_style);
        }

        // Label below
        if let Some(ref label) = self.label {
            let label_y = self.bounds.y + height.min(3) as f32;
            if label_y < self.bounds.y + self.bounds.height {
                let label_style = TextStyle {
                    color: Color::new(0.6, 0.6, 0.6, 1.0),
                    ..Default::default()
                };
                canvas.draw_text(label, Point::new(self.bounds.x, label_y), &label_style);
            }
        }
    }

    fn render_vertical(&self, canvas: &mut dyn Canvas) {
        let height = (self.bounds.height as usize).saturating_sub(1);
        if height == 0 {
            return;
        }

        let color = self.current_color();
        let style = TextStyle {
            color,
            ..Default::default()
        };
        let dim_style = TextStyle {
            color: Color::new(0.3, 0.3, 0.3, 1.0),
            ..Default::default()
        };

        let pct = self.percent() / 100.0;
        let filled = ((pct * height as f64).round() as usize).min(height);

        // Draw vertical bar from bottom to top
        for i in 0..height {
            let y = self.bounds.y + (height - 1 - i) as f32;
            if i < filled {
                canvas.draw_text("", Point::new(self.bounds.x, y), &style);
            } else {
                canvas.draw_text("", Point::new(self.bounds.x, y), &dim_style);
            }
        }

        // Value at bottom
        if self.show_value {
            let unit = self.unit.as_deref().unwrap_or("");
            let value_text = format!("{:.0}{}", self.value, unit);
            canvas.draw_text(
                &value_text,
                Point::new(self.bounds.x + 2.0, self.bounds.y + height as f32),
                &style,
            );
        }
    }

    fn render_compact(&self, canvas: &mut dyn Canvas) {
        let color = self.current_color();
        let style = TextStyle {
            color,
            ..Default::default()
        };

        let unit = self.unit.as_deref().unwrap_or("");
        let label = self.label.as_deref().unwrap_or("");
        let text = if label.is_empty() {
            format!("{:.0}{}", self.value, unit)
        } else {
            format!("{}: {:.0}{}", label, self.value, unit)
        };

        canvas.draw_text(&text, Point::new(self.bounds.x, self.bounds.y), &style);
    }

    /// Render quarter arc (90° - bottom-right corner style).
    fn render_quarter(&self, canvas: &mut dyn Canvas) {
        let width = self.bounds.width as usize;
        let height = self.bounds.height as usize;

        if width < 3 || height < 2 {
            self.render_compact(canvas);
            return;
        }

        let color = self.current_color();
        let style = TextStyle {
            color,
            ..Default::default()
        };
        let dim_style = TextStyle {
            color: Color::new(0.3, 0.3, 0.3, 1.0),
            ..Default::default()
        };

        let pct = self.percent() / 100.0;
        let arc_width = width.saturating_sub(1);
        let filled = ((pct * arc_width as f64).round() as usize).min(arc_width);

        // Quarter arc: ───╮
        //        let mut top = String::with_capacity(width);
        for i in 0..arc_width {
            if i < filled {
                top.push('');
            } else {
                top.push('');
            }
        }
        top.push('');
        canvas.draw_text(&top, Point::new(self.bounds.x, self.bounds.y), &style);

        // Vertical part
        if height > 1 {
            let x_pos = self.bounds.x + arc_width as f32;
            canvas.draw_text("", Point::new(x_pos, self.bounds.y + 1.0), &dim_style);
        }

        // Value display
        if self.show_value && height > 1 {
            let unit = self.unit.as_deref().unwrap_or("");
            let value_text = format!("{:.0}{}", self.value, unit);
            canvas.draw_text(
                &value_text,
                Point::new(self.bounds.x, self.bounds.y + 1.0),
                &style,
            );
        }

        // Label
        if let Some(ref label) = self.label {
            if height > 2 {
                let label_style = TextStyle {
                    color: Color::new(0.6, 0.6, 0.6, 1.0),
                    ..Default::default()
                };
                canvas.draw_text(
                    label,
                    Point::new(self.bounds.x, self.bounds.y + 2.0),
                    &label_style,
                );
            }
        }
    }

    /// Render half arc (180° - bottom semicircle).
    fn render_half(&self, canvas: &mut dyn Canvas) {
        let width = self.bounds.width as usize;
        let height = self.bounds.height as usize;

        if width < 4 || height < 2 {
            self.render_compact(canvas);
            return;
        }

        let color = self.current_color();
        let style = TextStyle {
            color,
            ..Default::default()
        };

        let pct = self.percent() / 100.0;
        let arc_width = width.saturating_sub(2);
        let filled = ((pct * arc_width as f64).round() as usize).min(arc_width);

        // Half arc (bottom semicircle): ╰───╯
        let mut arc = String::with_capacity(width);
        arc.push('');
        for i in 0..arc_width {
            if i < filled {
                arc.push('');
            } else {
                arc.push('');
            }
        }
        arc.push('');
        canvas.draw_text(&arc, Point::new(self.bounds.x, self.bounds.y), &style);

        // Value above arc
        if self.show_value && height > 1 {
            let unit = self.unit.as_deref().unwrap_or("");
            let value_text = format!("{:.0}{}", self.value, unit);
            let padding = (arc_width.saturating_sub(value_text.len())) / 2;
            canvas.draw_text(
                &value_text,
                Point::new(self.bounds.x + 1.0 + padding as f32, self.bounds.y + 1.0),
                &style,
            );
        }

        // Label
        if let Some(ref label) = self.label {
            if height > 2 {
                let label_style = TextStyle {
                    color: Color::new(0.6, 0.6, 0.6, 1.0),
                    ..Default::default()
                };
                canvas.draw_text(
                    label,
                    Point::new(self.bounds.x, self.bounds.y + 2.0),
                    &label_style,
                );
            }
        }
    }

    /// Render three-quarter arc (270° - U-shape open at top-left).
    fn render_three_quarter(&self, canvas: &mut dyn Canvas) {
        let width = self.bounds.width as usize;
        let height = self.bounds.height as usize;

        if width < 4 || height < 3 {
            self.render_compact(canvas);
            return;
        }

        let color = self.current_color();
        let style = TextStyle {
            color,
            ..Default::default()
        };
        let dim_style = TextStyle {
            color: Color::new(0.3, 0.3, 0.3, 1.0),
            ..Default::default()
        };

        let pct = self.percent() / 100.0;
        let arc_width = width.saturating_sub(1);

        // Three-quarter arc: open at top-left
        // ────╮
        //        // ────╯

        // Top section (horizontal part with right corner)
        let top_filled = ((pct * arc_width as f64).round() as usize).min(arc_width);
        let mut top = String::with_capacity(width);
        for i in 0..arc_width {
            if i < top_filled {
                top.push('');
            } else {
                top.push('');
            }
        }
        top.push('');
        canvas.draw_text(&top, Point::new(self.bounds.x, self.bounds.y), &style);

        // Middle section (vertical bar on right)
        if height > 2 {
            let x_pos = self.bounds.x + arc_width as f32;
            canvas.draw_text("", Point::new(x_pos, self.bounds.y + 1.0), &dim_style);

            // Value in middle
            if self.show_value {
                let unit = self.unit.as_deref().unwrap_or("");
                let value_text = format!("{:.0}{}", self.value, unit);
                canvas.draw_text(
                    &value_text,
                    Point::new(self.bounds.x, self.bounds.y + 1.0),
                    &style,
                );
            }
        }

        // Bottom section (horizontal with right corner)
        let bottom_y = if height > 2 {
            self.bounds.y + 2.0
        } else {
            self.bounds.y + 1.0
        };
        let mut bottom = String::with_capacity(width);
        for _ in 0..arc_width {
            bottom.push('');
        }
        bottom.push('');
        canvas.draw_text(&bottom, Point::new(self.bounds.x, bottom_y), &dim_style);

        // Label
        if let Some(ref label) = self.label {
            if height > 3 {
                let label_style = TextStyle {
                    color: Color::new(0.6, 0.6, 0.6, 1.0),
                    ..Default::default()
                };
                canvas.draw_text(
                    label,
                    Point::new(self.bounds.x, self.bounds.y + 3.0),
                    &label_style,
                );
            }
        }
    }
}

impl Brick for Gauge {
    fn brick_name(&self) -> &'static str {
        "gauge"
    }

    fn assertions(&self) -> &[BrickAssertion] {
        static ASSERTIONS: &[BrickAssertion] = &[BrickAssertion::max_latency_ms(16)];
        ASSERTIONS
    }

    fn budget(&self) -> BrickBudget {
        BrickBudget::uniform(16)
    }

    fn verify(&self) -> BrickVerification {
        let mut passed = Vec::new();
        let mut failed = Vec::new();

        if self.value >= 0.0 && self.value <= self.max {
            passed.push(BrickAssertion::max_latency_ms(16));
        } else {
            failed.push((
                BrickAssertion::max_latency_ms(16),
                format!("Value {} outside range [0, {}]", self.value, self.max),
            ));
        }

        BrickVerification {
            passed,
            failed,
            verification_time: Duration::from_micros(5),
        }
    }

    fn to_html(&self) -> String {
        String::new()
    }

    fn to_css(&self) -> String {
        String::new()
    }
}

impl Widget for Gauge {
    fn type_id(&self) -> TypeId {
        TypeId::of::<Self>()
    }

    fn measure(&self, constraints: Constraints) -> Size {
        match self.mode {
            GaugeMode::Arc | GaugeMode::ThreeQuarter => {
                let width = 10.0_f32.min(constraints.max_width);
                let height = 4.0_f32.min(constraints.max_height);
                constraints.constrain(Size::new(width, height))
            }
            GaugeMode::Quarter => {
                let width = 8.0_f32.min(constraints.max_width);
                let height = 3.0_f32.min(constraints.max_height);
                constraints.constrain(Size::new(width, height))
            }
            GaugeMode::Half => {
                let width = 10.0_f32.min(constraints.max_width);
                let height = 3.0_f32.min(constraints.max_height);
                constraints.constrain(Size::new(width, height))
            }
            GaugeMode::Vertical => {
                let height = 8.0_f32.min(constraints.max_height);
                constraints.constrain(Size::new(6.0, height))
            }
            GaugeMode::Compact => constraints.constrain(Size::new(12.0, 1.0)),
        }
    }

    fn layout(&mut self, bounds: Rect) -> LayoutResult {
        self.bounds = bounds;
        LayoutResult {
            size: Size::new(bounds.width, bounds.height),
        }
    }

    fn paint(&self, canvas: &mut dyn Canvas) {
        match self.mode {
            GaugeMode::Arc => self.render_arc(canvas),
            GaugeMode::Quarter => self.render_quarter(canvas),
            GaugeMode::Half => self.render_half(canvas),
            GaugeMode::ThreeQuarter => self.render_three_quarter(canvas),
            GaugeMode::Vertical => self.render_vertical(canvas),
            GaugeMode::Compact => self.render_compact(canvas),
        }
    }

    fn event(&mut self, _event: &Event) -> Option<Box<dyn Any + Send>> {
        None
    }

    fn children(&self) -> &[Box<dyn Widget>] {
        &[]
    }

    fn children_mut(&mut self) -> &mut [Box<dyn Widget>] {
        &mut []
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    struct MockCanvas {
        texts: Vec<(String, Point)>,
    }

    impl MockCanvas {
        fn new() -> Self {
            Self { texts: vec![] }
        }
    }

    impl Canvas for MockCanvas {
        fn fill_rect(&mut self, _rect: Rect, _color: Color) {}
        fn stroke_rect(&mut self, _rect: Rect, _color: Color, _width: f32) {}
        fn draw_text(&mut self, text: &str, position: Point, _style: &TextStyle) {
            self.texts.push((text.to_string(), position));
        }
        fn draw_line(&mut self, _from: Point, _to: Point, _color: Color, _width: f32) {}
        fn fill_circle(&mut self, _center: Point, _radius: f32, _color: Color) {}
        fn stroke_circle(&mut self, _center: Point, _radius: f32, _color: Color, _width: f32) {}
        fn fill_arc(&mut self, _c: Point, _r: f32, _s: f32, _e: f32, _color: Color) {}
        fn draw_path(&mut self, _points: &[Point], _color: Color, _width: f32) {}
        fn fill_polygon(&mut self, _points: &[Point], _color: Color) {}
        fn push_clip(&mut self, _rect: Rect) {}
        fn pop_clip(&mut self) {}
        fn push_transform(&mut self, _transform: presentar_core::Transform2D) {}
        fn pop_transform(&mut self) {}
    }

    #[test]
    fn test_gauge_creation() {
        let gauge = Gauge::new(50.0, 100.0);
        assert_eq!(gauge.value(), 50.0);
        assert_eq!(gauge.max, 100.0);
    }

    #[test]
    fn test_gauge_percentage_constructor() {
        let gauge = Gauge::percentage(75.0);
        assert_eq!(gauge.percent(), 75.0);
        assert_eq!(gauge.unit, Some("%".to_string()));
    }

    #[test]
    fn test_gauge_temperature() {
        let gauge = Gauge::temperature(65.0, 100.0);
        assert_eq!(gauge.value(), 65.0);
        assert_eq!(gauge.unit, Some("°C".to_string()));
    }

    #[test]
    fn test_gauge_assertions() {
        let gauge = Gauge::default();
        assert!(!gauge.assertions().is_empty());
    }

    #[test]
    fn test_gauge_verify() {
        let gauge = Gauge::new(50.0, 100.0);
        assert!(gauge.verify().is_valid());
    }

    #[test]
    fn test_gauge_with_label() {
        let gauge = Gauge::new(50.0, 100.0).with_label("CPU");
        assert_eq!(gauge.label, Some("CPU".to_string()));
    }

    #[test]
    fn test_gauge_with_mode() {
        let gauge = Gauge::default().with_mode(GaugeMode::Vertical);
        assert_eq!(gauge.mode, GaugeMode::Vertical);
    }

    #[test]
    fn test_gauge_with_color() {
        let gauge = Gauge::default().with_color(Color::RED);
        assert_eq!(gauge.color, Color::RED);
    }

    #[test]
    fn test_gauge_with_thresholds() {
        let gauge = Gauge::default().with_thresholds(50.0, 80.0);
        assert_eq!(gauge.warn_threshold, 50.0);
        assert_eq!(gauge.critical_threshold, 80.0);
    }

    #[test]
    fn test_gauge_with_value_display() {
        let gauge = Gauge::default().with_value_display(false);
        assert!(!gauge.show_value);
    }

    #[test]
    fn test_gauge_with_unit() {
        let gauge = Gauge::default().with_unit("MB");
        assert_eq!(gauge.unit, Some("MB".to_string()));
    }

    #[test]
    fn test_gauge_set_value() {
        let mut gauge = Gauge::new(50.0, 100.0);
        gauge.set_value(75.0);
        assert_eq!(gauge.value(), 75.0);
    }

    #[test]
    fn test_gauge_set_value_clamped() {
        let mut gauge = Gauge::new(50.0, 100.0);
        gauge.set_value(150.0);
        assert_eq!(gauge.value(), 100.0);

        gauge.set_value(-10.0);
        assert_eq!(gauge.value(), 0.0);
    }

    #[test]
    fn test_gauge_current_color_normal() {
        let gauge = Gauge::new(50.0, 100.0);
        let color = gauge.current_color();
        assert_eq!(color, gauge.color);
    }

    #[test]
    fn test_gauge_current_color_warning() {
        let gauge = Gauge::new(75.0, 100.0);
        let color = gauge.current_color();
        assert!(color.r > 0.9);
    }

    #[test]
    fn test_gauge_current_color_critical() {
        let gauge = Gauge::new(95.0, 100.0);
        let color = gauge.current_color();
        assert!(color.r > 0.9);
        assert!(color.g < 0.5);
    }

    #[test]
    fn test_gauge_paint_arc() {
        let mut gauge = Gauge::default().with_mode(GaugeMode::Arc);
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 4.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_paint_vertical() {
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Vertical);
        gauge.bounds = Rect::new(0.0, 0.0, 6.0, 8.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_paint_compact() {
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Compact);
        gauge.bounds = Rect::new(0.0, 0.0, 20.0, 1.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_paint_compact_with_label() {
        let mut gauge = Gauge::percentage(50.0)
            .with_mode(GaugeMode::Compact)
            .with_label("CPU");
        gauge.bounds = Rect::new(0.0, 0.0, 20.0, 1.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(canvas.texts.iter().any(|(t, _)| t.contains("CPU")));
    }

    #[test]
    fn test_gauge_measure_arc() {
        let gauge = Gauge::default().with_mode(GaugeMode::Arc);
        let size = gauge.measure(Constraints::loose(Size::new(100.0, 100.0)));
        assert!(size.width > 0.0);
        assert!(size.height > 0.0);
    }

    #[test]
    fn test_gauge_measure_vertical() {
        let gauge = Gauge::default().with_mode(GaugeMode::Vertical);
        let size = gauge.measure(Constraints::loose(Size::new(100.0, 100.0)));
        assert!(size.height > size.width);
    }

    #[test]
    fn test_gauge_measure_compact() {
        let gauge = Gauge::default().with_mode(GaugeMode::Compact);
        let size = gauge.measure(Constraints::loose(Size::new(100.0, 100.0)));
        assert_eq!(size.height, 1.0);
    }

    #[test]
    fn test_gauge_layout() {
        let mut gauge = Gauge::default();
        let bounds = Rect::new(5.0, 10.0, 20.0, 10.0);
        let result = gauge.layout(bounds);
        assert_eq!(result.size.width, 20.0);
        assert_eq!(gauge.bounds, bounds);
    }

    #[test]
    fn test_gauge_brick_name() {
        let gauge = Gauge::default();
        assert_eq!(gauge.brick_name(), "gauge");
    }

    #[test]
    fn test_gauge_type_id() {
        let gauge = Gauge::default();
        assert_eq!(Widget::type_id(&gauge), TypeId::of::<Gauge>());
    }

    #[test]
    fn test_gauge_children() {
        let gauge = Gauge::default();
        assert!(gauge.children().is_empty());
    }

    #[test]
    fn test_gauge_event() {
        let mut gauge = Gauge::default();
        let event = Event::KeyDown {
            key: presentar_core::Key::Enter,
        };
        assert!(gauge.event(&event).is_none());
    }

    #[test]
    fn test_gauge_default() {
        let gauge = Gauge::default();
        assert_eq!(gauge.value(), 0.0);
        assert_eq!(gauge.max, 100.0);
    }

    #[test]
    fn test_gauge_percentage_zero_max() {
        let gauge = Gauge::new(50.0, 0.0);
        assert_eq!(gauge.percent(), 0.0);
    }

    #[test]
    fn test_gauge_arc_fallback_to_compact() {
        // Arc mode with small bounds should fall back to compact
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Arc);
        gauge.bounds = Rect::new(0.0, 0.0, 3.0, 2.0); // Too small for arc
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Should have rendered compact mode instead
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_arc_no_value_display() {
        let mut gauge = Gauge::percentage(50.0)
            .with_mode(GaugeMode::Arc)
            .with_value_display(false);
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 4.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Should render without value text
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_arc_with_label() {
        let mut gauge = Gauge::percentage(50.0)
            .with_mode(GaugeMode::Arc)
            .with_label("CPU");
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 5.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Should render with label below arc
        assert!(canvas.texts.iter().any(|(t, _)| t.contains("CPU")));
    }

    #[test]
    fn test_gauge_arc_height_two() {
        // Arc with only 2 lines height - falls back to compact (height < 3)
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Arc);
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 2.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Falls back to compact mode
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_arc_height_three_no_middle() {
        // Arc with exactly 3 lines height - draws top and bottom
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Arc);
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 3.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Should draw top and bottom (height > 2 is false, so no middle)
        assert!(canvas.texts.len() >= 2);
    }

    #[test]
    fn test_gauge_arc_height_four() {
        // Arc with 4 lines - draws all sections
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Arc);
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 4.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Should draw top, middle, and bottom (height > 2)
        assert!(canvas.texts.len() >= 3);
    }

    #[test]
    fn test_gauge_vertical_zero_height() {
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Vertical);
        gauge.bounds = Rect::new(0.0, 0.0, 6.0, 1.0); // height - 1 = 0
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Early return when height is 0
        assert!(canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_vertical_no_value_display() {
        let mut gauge = Gauge::percentage(50.0)
            .with_mode(GaugeMode::Vertical)
            .with_value_display(false);
        gauge.bounds = Rect::new(0.0, 0.0, 6.0, 8.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Should not have value text
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_verify_invalid() {
        // Create a gauge and manually set invalid value
        let mut gauge = Gauge::new(50.0, 100.0);
        gauge.value = -10.0; // Invalid: outside range
        let result = gauge.verify();
        assert!(!result.is_valid());
        assert!(!result.failed.is_empty());
    }

    #[test]
    fn test_gauge_verify_above_max() {
        let mut gauge = Gauge::new(50.0, 100.0);
        gauge.value = 150.0; // Invalid: above max
        let result = gauge.verify();
        assert!(!result.is_valid());
    }

    #[test]
    fn test_gauge_children_mut() {
        let mut gauge = Gauge::default();
        assert!(gauge.children_mut().is_empty());
    }

    #[test]
    fn test_gauge_budget() {
        let gauge = Gauge::default();
        let budget = gauge.budget();
        assert_eq!(budget.total_ms, 16);
    }

    #[test]
    fn test_gauge_to_html() {
        let gauge = Gauge::default();
        assert!(gauge.to_html().is_empty());
    }

    #[test]
    fn test_gauge_to_css() {
        let gauge = Gauge::default();
        assert!(gauge.to_css().is_empty());
    }

    #[test]
    fn test_gauge_compact_no_label() {
        // Compact mode without label
        let mut gauge = Gauge::percentage(75.0).with_mode(GaugeMode::Compact);
        gauge.bounds = Rect::new(0.0, 0.0, 20.0, 1.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        // Should show value without label prefix
        assert!(canvas.texts.iter().any(|(t, _)| t.contains("75")));
    }

    #[test]
    fn test_gauge_quarter_mode() {
        let gauge = Gauge::default().with_mode(GaugeMode::Quarter);
        assert_eq!(gauge.mode, GaugeMode::Quarter);
    }

    #[test]
    fn test_gauge_half_mode() {
        let gauge = Gauge::default().with_mode(GaugeMode::Half);
        assert_eq!(gauge.mode, GaugeMode::Half);
    }

    #[test]
    fn test_gauge_three_quarter_mode() {
        let gauge = Gauge::default().with_mode(GaugeMode::ThreeQuarter);
        assert_eq!(gauge.mode, GaugeMode::ThreeQuarter);
    }

    #[test]
    fn test_gauge_quarter_paint() {
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Quarter);
        gauge.bounds = Rect::new(0.0, 0.0, 8.0, 3.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
        // Quarter arc should have ╮ character
        assert!(canvas.texts.iter().any(|(t, _)| t.contains('')));
    }

    #[test]
    fn test_gauge_half_paint() {
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Half);
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 3.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
        // Half arc should have ╰ and ╯ characters
        assert!(canvas.texts.iter().any(|(t, _)| t.contains('')));
    }

    #[test]
    fn test_gauge_three_quarter_paint() {
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::ThreeQuarter);
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 4.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
        // Three-quarter arc should have ╮ and ╯ characters
        assert!(canvas.texts.iter().any(|(t, _)| t.contains('')));
        assert!(canvas.texts.iter().any(|(t, _)| t.contains('')));
    }

    #[test]
    fn test_gauge_quarter_fallback() {
        // Quarter mode with too small bounds falls back to compact
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Quarter);
        gauge.bounds = Rect::new(0.0, 0.0, 2.0, 1.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_half_fallback() {
        // Half mode with too small bounds falls back to compact
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::Half);
        gauge.bounds = Rect::new(0.0, 0.0, 2.0, 1.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_three_quarter_fallback() {
        // Three-quarter mode with too small bounds falls back to compact
        let mut gauge = Gauge::percentage(50.0).with_mode(GaugeMode::ThreeQuarter);
        gauge.bounds = Rect::new(0.0, 0.0, 2.0, 2.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(!canvas.texts.is_empty());
    }

    #[test]
    fn test_gauge_measure_quarter() {
        let gauge = Gauge::default().with_mode(GaugeMode::Quarter);
        let size = gauge.measure(Constraints::loose(Size::new(100.0, 100.0)));
        assert_eq!(size.width, 8.0);
        assert_eq!(size.height, 3.0);
    }

    #[test]
    fn test_gauge_measure_half() {
        let gauge = Gauge::default().with_mode(GaugeMode::Half);
        let size = gauge.measure(Constraints::loose(Size::new(100.0, 100.0)));
        assert_eq!(size.width, 10.0);
        assert_eq!(size.height, 3.0);
    }

    #[test]
    fn test_gauge_measure_three_quarter() {
        let gauge = Gauge::default().with_mode(GaugeMode::ThreeQuarter);
        let size = gauge.measure(Constraints::loose(Size::new(100.0, 100.0)));
        assert_eq!(size.width, 10.0);
        assert_eq!(size.height, 4.0);
    }

    #[test]
    fn test_gauge_quarter_with_label() {
        let mut gauge = Gauge::percentage(50.0)
            .with_mode(GaugeMode::Quarter)
            .with_label("Temp");
        gauge.bounds = Rect::new(0.0, 0.0, 8.0, 4.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(canvas.texts.iter().any(|(t, _)| t.contains("Temp")));
    }

    #[test]
    fn test_gauge_half_with_label() {
        let mut gauge = Gauge::percentage(50.0)
            .with_mode(GaugeMode::Half)
            .with_label("Load");
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 4.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(canvas.texts.iter().any(|(t, _)| t.contains("Load")));
    }

    #[test]
    fn test_gauge_three_quarter_with_label() {
        let mut gauge = Gauge::percentage(50.0)
            .with_mode(GaugeMode::ThreeQuarter)
            .with_label("CPU");
        gauge.bounds = Rect::new(0.0, 0.0, 10.0, 5.0);
        let mut canvas = MockCanvas::new();
        gauge.paint(&mut canvas);
        assert!(canvas.texts.iter().any(|(t, _)| t.contains("CPU")));
    }
}