revue 2.71.1

A Vue-style TUI framework for Rust with CSS styling
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
//! Developer tools for Revue applications
//!
//! Provides debugging and inspection tools for development:
//!
//! | Tool | Description |
//! |------|-------------|
//! | [`Inspector`] | Widget tree inspector |
//! | [`StateDebugger`] | Reactive state viewer |
//! | [`StyleInspector`] | CSS style inspector |
//! | [`EventLogger`] | Event stream logger |
//!
//! # Quick Start
//!
//! ```rust,ignore
//! use revue::devtools::{DevTools, Inspector};
//!
//! // Enable dev tools with F12
//! let app = App::builder()
//!     .with_devtools(true)
//!     .build();
//! ```
//!
//! # Widget Inspector
//!
//! ```rust,ignore
//! use revue::devtools::Inspector;
//!
//! let inspector = Inspector::new()
//!     .show_bounds(true)
//!     .show_classes(true);
//! ```

mod events;
mod helpers;
mod inspector;
mod profiler;
mod state;
mod style;
mod time_travel;

pub use events::{EventFilter, EventLogger, EventType, LoggedEvent};
pub use inspector::{ComponentPicker, Inspector, InspectorConfig, PickerMode, WidgetNode};
pub use profiler::{ComponentStats, Frame, Profiler, ProfilerView, RenderEvent, RenderReason};
pub use state::{StateDebugger, StateEntry, StateValue};
pub use style::{ComputedProperty, PropertySource, StyleCategory, StyleInspector};
pub use time_travel::{
    Action, SnapshotValue, StateDiff, StateSnapshot, TimeTravelConfig, TimeTravelDebugger,
    TimeTravelView,
};

use crate::layout::Rect;
use crate::render::Buffer;
use crate::style::Color;
use std::sync::atomic::{AtomicBool, Ordering};

// =============================================================================
// DevTools Panel
// =============================================================================

/// DevTools panel position
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum DevToolsPosition {
    /// Right side panel
    #[default]
    Right,
    /// Bottom panel
    Bottom,
    /// Left side panel
    Left,
    /// Floating overlay
    Overlay,
}

/// DevTools configuration
#[derive(Debug, Clone)]
pub struct DevToolsConfig {
    /// Panel position
    pub position: DevToolsPosition,
    /// Panel size (width or height depending on position)
    pub size: u16,
    /// Is visible
    pub visible: bool,
    /// Active tab
    pub active_tab: DevToolsTab,
    /// Background color
    pub bg_color: Color,
    /// Text color
    pub fg_color: Color,
    /// Accent color
    pub accent_color: Color,
}

impl Default for DevToolsConfig {
    fn default() -> Self {
        Self {
            position: DevToolsPosition::Right,
            size: 50,
            visible: false,
            active_tab: DevToolsTab::Inspector,
            bg_color: Color::rgb(25, 25, 35),
            fg_color: Color::rgb(200, 200, 210),
            accent_color: Color::rgb(130, 180, 255),
        }
    }
}

/// DevTools tab
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum DevToolsTab {
    /// Widget inspector
    #[default]
    Inspector,
    /// State debugger
    State,
    /// Style inspector
    Styles,
    /// Event logger
    Events,
    /// Performance profiler
    Profiler,
    /// Time-travel debugger
    TimeTravel,
}

impl DevToolsTab {
    /// Get tab label
    pub fn label(&self) -> &'static str {
        match self {
            Self::Inspector => "Inspector",
            Self::State => "State",
            Self::Styles => "Styles",
            Self::Events => "Events",
            Self::Profiler => "Profiler",
            Self::TimeTravel => "Travel",
        }
    }

    /// Get all tabs
    pub fn all() -> &'static [DevToolsTab] {
        &[
            DevToolsTab::Inspector,
            DevToolsTab::State,
            DevToolsTab::Styles,
            DevToolsTab::Events,
            DevToolsTab::Profiler,
            DevToolsTab::TimeTravel,
        ]
    }

    /// Next tab
    pub fn next(&self) -> Self {
        match self {
            Self::Inspector => Self::State,
            Self::State => Self::Styles,
            Self::Styles => Self::Events,
            Self::Events => Self::Profiler,
            Self::Profiler => Self::TimeTravel,
            Self::TimeTravel => Self::Inspector,
        }
    }

    /// Previous tab
    pub fn prev(&self) -> Self {
        match self {
            Self::Inspector => Self::TimeTravel,
            Self::State => Self::Inspector,
            Self::Styles => Self::State,
            Self::Events => Self::Styles,
            Self::Profiler => Self::Events,
            Self::TimeTravel => Self::Profiler,
        }
    }
}

// =============================================================================
// DevTools
// =============================================================================

/// Main DevTools panel
pub struct DevTools {
    /// Configuration
    config: DevToolsConfig,
    /// Widget inspector
    inspector: Inspector,
    /// State debugger
    state: StateDebugger,
    /// Style inspector
    styles: StyleInspector,
    /// Event logger
    events: EventLogger,
    /// Performance profiler
    profiler: Profiler,
    /// Time-travel debugger
    time_travel: TimeTravelDebugger,
}

impl DevTools {
    /// Create new DevTools
    pub fn new() -> Self {
        Self {
            config: DevToolsConfig::default(),
            inspector: Inspector::new(),
            state: StateDebugger::new(),
            styles: StyleInspector::new(),
            events: EventLogger::new(),
            profiler: Profiler::new(),
            time_travel: TimeTravelDebugger::new(),
        }
    }

    /// Set configuration
    pub fn config(mut self, config: DevToolsConfig) -> Self {
        self.config = config;
        self
    }

    /// Set position
    pub fn position(mut self, position: DevToolsPosition) -> Self {
        self.config.position = position;
        self
    }

    /// Set size
    pub fn size(mut self, size: u16) -> Self {
        self.config.size = size;
        self
    }

    /// Toggle visibility
    pub fn toggle(&mut self) {
        self.config.visible = !self.config.visible;
    }

    /// Set visibility
    pub fn set_visible(&mut self, visible: bool) {
        self.config.visible = visible;
    }

    /// Is visible
    pub fn is_visible(&self) -> bool {
        self.config.visible
    }

    /// Set active tab
    pub fn set_tab(&mut self, tab: DevToolsTab) {
        self.config.active_tab = tab;
    }

    /// Next tab
    pub fn next_tab(&mut self) {
        self.config.active_tab = self.config.active_tab.next();
    }

    /// Previous tab
    pub fn prev_tab(&mut self) {
        self.config.active_tab = self.config.active_tab.prev();
    }

    /// Get inspector
    pub fn inspector(&self) -> &Inspector {
        &self.inspector
    }

    /// Get mutable inspector
    pub fn inspector_mut(&mut self) -> &mut Inspector {
        &mut self.inspector
    }

    /// Get state debugger
    pub fn state(&self) -> &StateDebugger {
        &self.state
    }

    /// Get mutable state debugger
    pub fn state_mut(&mut self) -> &mut StateDebugger {
        &mut self.state
    }

    /// Get style inspector
    pub fn styles(&self) -> &StyleInspector {
        &self.styles
    }

    /// Get mutable style inspector
    pub fn styles_mut(&mut self) -> &mut StyleInspector {
        &mut self.styles
    }

    /// Get event logger
    pub fn events(&self) -> &EventLogger {
        &self.events
    }

    /// Get mutable event logger
    pub fn events_mut(&mut self) -> &mut EventLogger {
        &mut self.events
    }

    /// Get profiler
    pub fn profiler(&self) -> &Profiler {
        &self.profiler
    }

    /// Get mutable profiler
    pub fn profiler_mut(&mut self) -> &mut Profiler {
        &mut self.profiler
    }

    /// Get time-travel debugger
    pub fn time_travel(&self) -> &TimeTravelDebugger {
        &self.time_travel
    }

    /// Get mutable time-travel debugger
    pub fn time_travel_mut(&mut self) -> &mut TimeTravelDebugger {
        &mut self.time_travel
    }

    /// Calculate panel rect based on position
    pub fn panel_rect(&self, area: Rect) -> Option<Rect> {
        if !self.config.visible {
            return None;
        }

        let size = self.config.size;

        Some(match self.config.position {
            DevToolsPosition::Right => Rect::new(
                area.x + area.width.saturating_sub(size),
                area.y,
                size.min(area.width),
                area.height,
            ),
            DevToolsPosition::Left => Rect::new(area.x, area.y, size.min(area.width), area.height),
            DevToolsPosition::Bottom => Rect::new(
                area.x,
                area.y + area.height.saturating_sub(size),
                area.width,
                size.min(area.height),
            ),
            DevToolsPosition::Overlay => {
                let width = (area.width * 2 / 3).min(80);
                let height = (area.height * 2 / 3).min(30);
                Rect::new(
                    area.x + (area.width - width) / 2,
                    area.y + (area.height - height) / 2,
                    width,
                    height,
                )
            }
        })
    }

    /// Calculate content area (excluding devtools)
    pub fn content_rect(&self, area: Rect) -> Rect {
        if !self.config.visible {
            return area;
        }

        let size = self.config.size;

        match self.config.position {
            DevToolsPosition::Right => {
                Rect::new(area.x, area.y, area.width.saturating_sub(size), area.height)
            }
            DevToolsPosition::Left => Rect::new(
                area.x + size.min(area.width),
                area.y,
                area.width.saturating_sub(size),
                area.height,
            ),
            DevToolsPosition::Bottom => {
                Rect::new(area.x, area.y, area.width, area.height.saturating_sub(size))
            }
            DevToolsPosition::Overlay => area,
        }
    }

    /// Render devtools panel
    pub fn render(&self, buffer: &mut Buffer, area: Rect) {
        if let Some(panel) = self.panel_rect(area) {
            self.render_panel(buffer, panel);
        }
    }

    fn render_panel(&self, buffer: &mut Buffer, area: Rect) {
        // Fill background
        for y in area.y..area.y + area.height {
            for x in area.x..area.x + area.width {
                if let Some(cell) = buffer.get_mut(x, y) {
                    cell.symbol = ' ';
                    cell.bg = Some(self.config.bg_color);
                    cell.fg = Some(self.config.fg_color);
                }
            }
        }

        // Draw border
        self.draw_border(buffer, area);

        // Tab bar
        let tab_area = Rect::new(area.x + 1, area.y + 1, area.width - 2, 1);
        self.render_tabs(buffer, tab_area);

        // Content area
        let content_area = Rect::new(
            area.x + 1,
            area.y + 3,
            area.width - 2,
            area.height.saturating_sub(4),
        );

        match self.config.active_tab {
            DevToolsTab::Inspector => {
                self.inspector
                    .render_content(buffer, content_area, &self.config)
            }
            DevToolsTab::State => self
                .state
                .render_content(buffer, content_area, &self.config),
            DevToolsTab::Styles => self
                .styles
                .render_content(buffer, content_area, &self.config),
            DevToolsTab::Events => self
                .events
                .render_content(buffer, content_area, &self.config),
            DevToolsTab::Profiler => {
                self.profiler
                    .render_content(buffer, content_area, &self.config)
            }
            DevToolsTab::TimeTravel => {
                self.time_travel
                    .render_content(buffer, content_area, &self.config)
            }
        }
    }

    fn render_tabs(&self, buffer: &mut Buffer, area: Rect) {
        let mut x = area.x;

        for tab in DevToolsTab::all() {
            let label = format!(" {} ", tab.label());
            let is_active = *tab == self.config.active_tab;

            let (fg, bg) = if is_active {
                (self.config.bg_color, self.config.accent_color)
            } else {
                (self.config.fg_color, self.config.bg_color)
            };

            for ch in label.chars() {
                if x < area.x + area.width {
                    if let Some(cell) = buffer.get_mut(x, area.y) {
                        cell.symbol = ch;
                        cell.fg = Some(fg);
                        cell.bg = Some(bg);
                    }
                    x += 1;
                }
            }

            x += 1; // Gap between tabs
        }
    }

    fn draw_border(&self, buffer: &mut Buffer, area: Rect) {
        let color = self.config.accent_color;

        // Corners and edges
        for x in area.x..area.x + area.width {
            if let Some(cell) = buffer.get_mut(x, area.y) {
                cell.symbol = if x == area.x {
                    ''
                } else if x == area.x + area.width - 1 {
                    ''
                } else {
                    ''
                };
                cell.fg = Some(color);
            }
            if let Some(cell) = buffer.get_mut(x, area.y + area.height - 1) {
                cell.symbol = if x == area.x {
                    ''
                } else if x == area.x + area.width - 1 {
                    ''
                } else {
                    ''
                };
                cell.fg = Some(color);
            }
        }

        for y in area.y + 1..area.y + area.height - 1 {
            if let Some(cell) = buffer.get_mut(area.x, y) {
                cell.symbol = '';
                cell.fg = Some(color);
            }
            if let Some(cell) = buffer.get_mut(area.x + area.width - 1, y) {
                cell.symbol = '';
                cell.fg = Some(color);
            }
        }

        // Separator after tabs
        for x in area.x..area.x + area.width {
            if let Some(cell) = buffer.get_mut(x, area.y + 2) {
                cell.symbol = if x == area.x {
                    ''
                } else if x == area.x + area.width - 1 {
                    ''
                } else {
                    ''
                };
                cell.fg = Some(color);
            }
        }
    }
}

impl Default for DevTools {
    fn default() -> Self {
        Self::new()
    }
}

// =============================================================================
// Global DevTools State (Deprecated)
// =============================================================================
//
// These global functions are deprecated. Use `App::is_devtools_enabled()`,
// `App::enable_devtools()`, `App::disable_devtools()`, and `App::toggle_devtools()`
// instead for proper test isolation and cleaner architecture.

static DEVTOOLS_ENABLED: AtomicBool = AtomicBool::new(false);

/// Enable global devtools
///
/// # Deprecated
/// Use `App::enable_devtools()` instead for proper test isolation.
#[deprecated(since = "2.1.0", note = "Use App::enable_devtools() instead")]
pub fn enable_devtools() {
    DEVTOOLS_ENABLED.store(true, Ordering::Relaxed);
}

/// Disable global devtools
///
/// # Deprecated
/// Use `App::disable_devtools()` instead for proper test isolation.
#[deprecated(since = "2.1.0", note = "Use App::disable_devtools() instead")]
pub fn disable_devtools() {
    DEVTOOLS_ENABLED.store(false, Ordering::Relaxed);
}

/// Check if devtools are enabled
///
/// # Deprecated
/// Use `App::is_devtools_enabled()` instead for proper test isolation.
#[deprecated(since = "2.1.0", note = "Use App::is_devtools_enabled() instead")]
pub fn is_devtools_enabled() -> bool {
    DEVTOOLS_ENABLED.load(Ordering::Relaxed)
}

/// Toggle devtools
///
/// # Deprecated
/// Use `App::toggle_devtools()` instead for proper test isolation.
#[deprecated(since = "2.1.0", note = "Use App::toggle_devtools() instead")]
pub fn toggle_devtools() -> bool {
    let was = DEVTOOLS_ENABLED.fetch_xor(true, Ordering::Relaxed);
    !was
}

// =============================================================================
// Tests
// =============================================================================

#[cfg(test)]
mod tests {
    use super::*;
    use crate::core::app::App;

    #[test]
    fn test_devtools_config_default() {
        let config = DevToolsConfig::default();
        assert!(!config.visible);
        assert_eq!(config.position, DevToolsPosition::Right);
        assert_eq!(config.active_tab, DevToolsTab::Inspector);
        assert_eq!(config.size, 50);
    }

    #[test]
    fn test_devtools_tab_cycle() {
        let tab = DevToolsTab::Inspector;
        assert_eq!(tab.next(), DevToolsTab::State);
        assert_eq!(tab.prev(), DevToolsTab::TimeTravel);
    }

    #[test]
    fn test_devtools_toggle() {
        let mut devtools = DevTools::new();
        assert!(!devtools.is_visible());

        devtools.toggle();
        assert!(devtools.is_visible());

        devtools.toggle();
        assert!(!devtools.is_visible());
    }

    #[test]
    fn test_panel_rect_right() {
        let devtools = DevTools::new().size(30);
        let mut dt = devtools;
        dt.set_visible(true);

        let area = Rect::new(0, 0, 100, 50);
        let panel = dt.panel_rect(area).unwrap();

        assert_eq!(panel.x, 70);
        assert_eq!(panel.width, 30);
        assert_eq!(panel.height, 50);
    }

    #[test]
    fn test_panel_rect_left() {
        let mut devtools = DevTools::new().size(25);
        devtools.set_visible(true);
        devtools.config.position = DevToolsPosition::Left;

        let area = Rect::new(10, 5, 100, 50);
        let panel = devtools.panel_rect(area).unwrap();

        assert_eq!(panel.x, 10);
        assert_eq!(panel.y, 5);
        assert_eq!(panel.width, 25);
        assert_eq!(panel.height, 50);
    }

    #[test]
    fn test_panel_rect_bottom() {
        let mut devtools = DevTools::new().size(15);
        devtools.set_visible(true);
        devtools.config.position = DevToolsPosition::Bottom;

        let area = Rect::new(0, 0, 100, 50);
        let panel = devtools.panel_rect(area).unwrap();

        assert_eq!(panel.x, 0);
        assert_eq!(panel.y, 35);
        assert_eq!(panel.width, 100);
        assert_eq!(panel.height, 15);
    }

    #[test]
    fn test_panel_rect_overlay() {
        let mut devtools = DevTools::new();
        devtools.set_visible(true);
        devtools.config.position = DevToolsPosition::Overlay;

        let area = Rect::new(0, 0, 100, 50);
        let panel = devtools.panel_rect(area).unwrap();

        // Overlay should be centered: 2/3 of width/height, capped at 80/30
        assert_eq!(panel.width, 66); // 100 * 2 / 3 = 66
        assert_eq!(panel.height, 30); // 50 * 2 / 3 = 33, capped at 30
    }

    #[test]
    fn test_panel_rect_invisible() {
        let mut devtools = DevTools::new();
        devtools.set_visible(false);

        let area = Rect::new(0, 0, 100, 50);
        assert!(devtools.panel_rect(area).is_none());
    }

    #[test]
    fn test_content_rect_right() {
        let mut devtools = DevTools::new().size(30);
        devtools.set_visible(true);

        let area = Rect::new(0, 0, 100, 50);
        let content = devtools.content_rect(area);

        assert_eq!(content.x, 0);
        assert_eq!(content.y, 0);
        assert_eq!(content.width, 70);
        assert_eq!(content.height, 50);
    }

    #[test]
    fn test_content_rect_left() {
        let mut devtools = DevTools::new().size(30);
        devtools.set_visible(true);
        devtools.config.position = DevToolsPosition::Left;

        let area = Rect::new(0, 0, 100, 50);
        let content = devtools.content_rect(area);

        assert_eq!(content.x, 30);
        assert_eq!(content.width, 70);
    }

    #[test]
    fn test_content_rect_bottom() {
        let mut devtools = DevTools::new().size(20);
        devtools.set_visible(true);
        devtools.config.position = DevToolsPosition::Bottom;

        let area = Rect::new(0, 0, 100, 50);
        let content = devtools.content_rect(area);

        assert_eq!(content.y, 0);
        assert_eq!(content.height, 30);
    }

    #[test]
    fn test_content_rect_overlay() {
        let mut devtools = DevTools::new();
        devtools.set_visible(true);
        devtools.config.position = DevToolsPosition::Overlay;

        let area = Rect::new(0, 0, 100, 50);
        let content = devtools.content_rect(area);

        // Overlay doesn't reduce content area
        assert_eq!(content, area);
    }

    #[test]
    fn test_content_rect_invisible() {
        let mut devtools = DevTools::new();
        devtools.set_visible(false);

        let area = Rect::new(0, 0, 100, 50);
        let content = devtools.content_rect(area);

        assert_eq!(content, area);
    }

    #[test]
    fn test_devtools_new() {
        let devtools = DevTools::new();
        assert!(!devtools.is_visible());
        assert_eq!(devtools.config.active_tab, DevToolsTab::Inspector);
    }

    #[test]
    fn test_devtools_default() {
        let devtools = DevTools::default();
        assert!(!devtools.is_visible());
        assert_eq!(devtools.config.active_tab, DevToolsTab::Inspector);
    }

    #[test]
    fn test_devtools_config_builder() {
        let config = DevToolsConfig {
            position: DevToolsPosition::Left,
            size: 40,
            visible: true,
            active_tab: DevToolsTab::Profiler,
            bg_color: Color::rgb(10, 10, 10),
            fg_color: Color::rgb(255, 255, 255),
            accent_color: Color::rgb(100, 100, 255),
        };

        let devtools = DevTools::new().config(config);
        assert!(devtools.is_visible());
        assert_eq!(devtools.config.position, DevToolsPosition::Left);
        assert_eq!(devtools.config.size, 40);
        assert_eq!(devtools.config.active_tab, DevToolsTab::Profiler);
    }

    #[test]
    fn test_devtools_position() {
        let devtools = DevTools::new().position(DevToolsPosition::Bottom);
        assert_eq!(devtools.config.position, DevToolsPosition::Bottom);
    }

    #[test]
    fn test_devtools_size() {
        let devtools = DevTools::new().size(60);
        assert_eq!(devtools.config.size, 60);
    }

    #[test]
    fn test_devtools_set_visible() {
        let mut devtools = DevTools::new();
        assert!(!devtools.is_visible());

        devtools.set_visible(true);
        assert!(devtools.is_visible());

        devtools.set_visible(false);
        assert!(!devtools.is_visible());
    }

    #[test]
    fn test_devtools_set_tab() {
        let mut devtools = DevTools::new();
        assert_eq!(devtools.config.active_tab, DevToolsTab::Inspector);

        devtools.set_tab(DevToolsTab::Profiler);
        assert_eq!(devtools.config.active_tab, DevToolsTab::Profiler);
    }

    #[test]
    fn test_devtools_next_tab() {
        let mut devtools = DevTools::new();
        assert_eq!(devtools.config.active_tab, DevToolsTab::Inspector);

        devtools.next_tab();
        assert_eq!(devtools.config.active_tab, DevToolsTab::State);

        devtools.next_tab();
        assert_eq!(devtools.config.active_tab, DevToolsTab::Styles);
    }

    #[test]
    fn test_devtools_prev_tab() {
        let mut devtools = DevTools::new();
        assert_eq!(devtools.config.active_tab, DevToolsTab::Inspector);

        devtools.prev_tab();
        assert_eq!(devtools.config.active_tab, DevToolsTab::TimeTravel);

        devtools.prev_tab();
        assert_eq!(devtools.config.active_tab, DevToolsTab::Profiler);
    }

    #[test]
    fn test_devtools_getters() {
        let devtools = DevTools::new();

        // Test inspector getter - just check it returns a reference
        let _inspector = devtools.inspector();
        let _state = devtools.state();
        let _styles = devtools.styles();
        let _events = devtools.events();
        let _profiler = devtools.profiler();
        let _time_travel = devtools.time_travel();
    }

    #[test]
    fn test_devtools_getters_mut() {
        let mut devtools = DevTools::new();

        // Test mutable getters
        devtools.inspector_mut();
        devtools.state_mut();
        devtools.styles_mut();
        devtools.events_mut();
        devtools.profiler_mut();
        devtools.time_travel_mut();
    }

    #[test]
    fn test_devtools_tab_label() {
        assert_eq!(DevToolsTab::Inspector.label(), "Inspector");
        assert_eq!(DevToolsTab::State.label(), "State");
        assert_eq!(DevToolsTab::Styles.label(), "Styles");
        assert_eq!(DevToolsTab::Events.label(), "Events");
        assert_eq!(DevToolsTab::Profiler.label(), "Profiler");
        assert_eq!(DevToolsTab::TimeTravel.label(), "Travel");
    }

    #[test]
    fn test_devtools_tab_all() {
        let all = DevToolsTab::all();
        assert_eq!(all.len(), 6);
        assert_eq!(all[0], DevToolsTab::Inspector);
        assert_eq!(all[5], DevToolsTab::TimeTravel);
    }

    #[test]
    fn test_devtools_tab_next_cycle() {
        assert_eq!(DevToolsTab::Inspector.next(), DevToolsTab::State);
        assert_eq!(DevToolsTab::State.next(), DevToolsTab::Styles);
        assert_eq!(DevToolsTab::Styles.next(), DevToolsTab::Events);
        assert_eq!(DevToolsTab::Events.next(), DevToolsTab::Profiler);
        assert_eq!(DevToolsTab::Profiler.next(), DevToolsTab::TimeTravel);
        assert_eq!(DevToolsTab::TimeTravel.next(), DevToolsTab::Inspector);
    }

    #[test]
    fn test_devtools_tab_prev_cycle() {
        assert_eq!(DevToolsTab::Inspector.prev(), DevToolsTab::TimeTravel);
        assert_eq!(DevToolsTab::TimeTravel.prev(), DevToolsTab::Profiler);
        assert_eq!(DevToolsTab::Profiler.prev(), DevToolsTab::Events);
        assert_eq!(DevToolsTab::Events.prev(), DevToolsTab::Styles);
        assert_eq!(DevToolsTab::Styles.prev(), DevToolsTab::State);
        assert_eq!(DevToolsTab::State.prev(), DevToolsTab::Inspector);
    }

    #[test]
    fn test_devtools_position_default() {
        assert_eq!(DevToolsPosition::default(), DevToolsPosition::Right);
    }

    #[test]
    fn test_devtools_tab_default() {
        assert_eq!(DevToolsTab::default(), DevToolsTab::Inspector);
    }

    #[test]
    fn test_panel_rect_saturation() {
        let mut devtools = DevTools::new().size(200);
        devtools.set_visible(true);

        let area = Rect::new(0, 0, 100, 50);
        let panel = devtools.panel_rect(area).unwrap();

        // Size should be capped at area size
        assert_eq!(panel.width, 100);
        assert_eq!(panel.height, 50);
    }

    #[test]
    fn test_content_rect_saturation() {
        let mut devtools = DevTools::new().size(200);
        devtools.set_visible(true);

        let area = Rect::new(0, 0, 100, 50);
        let content = devtools.content_rect(area);

        // Content should handle large size gracefully
        assert_eq!(content.width, 0); // 100 - 100 = 0
        assert_eq!(content.height, 50);
    }

    #[test]
    fn test_global_enable_disable_devtools() {
        // Use App methods instead of deprecated global functions
        // Start with devtools explicitly disabled
        let mut app = App::builder().devtools(false).build();
        assert!(!app.is_devtools_enabled());

        app.enable_devtools();
        assert!(app.is_devtools_enabled());

        app.disable_devtools();
        assert!(!app.is_devtools_enabled());
    }

    #[test]
    fn test_global_toggle_devtools() {
        // Use App methods instead of deprecated global functions
        // Start with devtools explicitly disabled
        let mut app = App::builder().devtools(false).build();
        assert!(!app.is_devtools_enabled());

        // Toggle should enable
        let result = app.toggle_devtools();
        assert!(result); // Returns new state (enabled)
        assert!(app.is_devtools_enabled());

        // Toggle should disable
        let result = app.toggle_devtools();
        assert!(!result); // Returns new state (disabled)
        assert!(!app.is_devtools_enabled());
    }
}