Skip to main content

retroglyph_ui/perf/
mode.rs

1//! [`PerfOverlayMode`]: how much detail [`super::PerfOverlayApp`] currently shows.
2
3/// How much detail [`super::PerfOverlayApp`] currently shows, advanced by the toggle key.
4///
5/// Cycles `Off -> Compact -> Full -> Off`. [`Full`](Self::Full) is only reachable once
6/// [`PerfOverlayApp::cycle_with`](super::PerfOverlayApp::cycle_with) has registered a second
7/// renderer; without one, the cycle skips straight from [`Compact`](Self::Compact) back to `Off`,
8/// i.e. the plain two-state toggle from before this enum existed.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10#[non_exhaustive]
11pub enum PerfOverlayMode {
12    /// Nothing renders.
13    Off,
14    /// [`PerfOverlayApp`](super::PerfOverlayApp)'s primary [`PerfRenderer`](super::PerfRenderer)
15    /// (e.g. [`DefaultPerfRenderer`](super::DefaultPerfRenderer)) renders.
16    Compact,
17    /// The renderer registered via
18    /// [`PerfOverlayApp::cycle_with`](super::PerfOverlayApp::cycle_with) renders, if any;
19    /// otherwise equivalent to `Off` (this mode is unreachable through the toggle key alone in
20    /// that case, but [`PerfOverlayApp::set_mode`](super::PerfOverlayApp::set_mode) can still be
21    /// called with it directly).
22    Full,
23}
24
25impl PerfOverlayMode {
26    /// The next mode in the cycle, `Off -> Compact -> Full -> Off`, skipping `Full` when
27    /// `has_full` is `false`.
28    #[must_use]
29    pub(super) const fn next(self, has_full: bool) -> Self {
30        match self {
31            Self::Off => Self::Compact,
32            Self::Compact if has_full => Self::Full,
33            Self::Compact | Self::Full => Self::Off,
34        }
35    }
36}