irox_egui_extras/
visuals.rs

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
// SPDX-License-Identifier: MIT
// Copyright 2024 IROX Contributors
//

use crate::WithAlpha;
use egui::color_picker::show_color;
use egui::{vec2, RichText};

macro_rules! add_row {
    ($ui:ident, $name:expr, $col:expr) => {
        $ui.label($name);
        $ui.label(RichText::new("fg text").color($col));
        $ui.label(RichText::new("bg text").background_color($col));
        show_color($ui, $col, vec2(40., 15.));
        show_color($ui, WithAlpha::with_alpha($col, 128), vec2(40., 15.));
        $ui.label($col.to_hex());
        $ui.end_row();
    };
}

macro_rules! add_widget {
    ($ui:ident, $name:expr, $widget:expr) => {
        add_row!($ui, format!("{}.bg_fill", $name), $widget.bg_fill);
        add_row!($ui, format!("{}.weak_bg_fill", $name), $widget.weak_bg_fill);
        add_row!($ui, format!("{}.bg_stroke", $name), $widget.bg_stroke.color);
        add_row!($ui, format!("{}.fg_stroke", $name), $widget.fg_stroke.color);
    };
}

pub struct VisualsWindow;
impl VisualsWindow {
    pub fn show_visuals_window(ctx: &egui::Context) -> bool {
        let mut open = true;
        egui::Window::new("Visuals_Debug_Window")
            .constrain(true)
            .open(&mut open)
            .vscroll(true)
            .show(ctx, |ui| {
                let visuals = ui.visuals().clone();
                egui::Grid::new("Visuals_Debug_Grid")
                    .striped(true)
                    .num_columns(6)
                    .show(ui, |ui| {
                        add_row!(ui, "hyperlink_color", visuals.hyperlink_color);
                        add_row!(ui, "faint_bg_color", visuals.faint_bg_color);
                        add_row!(ui, "extreme_bg_color", visuals.extreme_bg_color);
                        add_row!(ui, "code_bg_color", visuals.code_bg_color);
                        add_row!(ui, "warn_fg_color", visuals.warn_fg_color);
                        add_row!(ui, "error_fg_color", visuals.error_fg_color);
                        add_row!(ui, "window_fill", visuals.window_fill);
                        add_row!(ui, "panel_fill", visuals.panel_fill);
                        add_row!(ui, "window_stroke", visuals.window_stroke.color);
                        add_row!(ui, "text_cursor", visuals.text_cursor.stroke.color);
                        add_widget!(ui, "noninteractive", visuals.widgets.noninteractive);
                        add_widget!(ui, "inactive", visuals.widgets.inactive);
                        add_widget!(ui, "hovered", visuals.widgets.hovered);
                        add_widget!(ui, "active", visuals.widgets.active);
                        add_widget!(ui, "open", visuals.widgets.open);
                    });
            });
        open
    }
}