imgui_inspect/default/
default_bool.rs

1use super::*;
2
3impl InspectRenderDefault<bool> for bool {
4    fn render(
5        data: &[&bool],
6        label: &'static str,
7        ui: &imgui::Ui,
8        _args: &InspectArgsDefault,
9    ) {
10        if data.is_empty() {
11            // Values are inconsistent
12            let style_token = ui.push_style_color(imgui::StyleColor::Text, [1.0, 0.0, 0.0, 1.0]);
13            ui.text(&imgui::im_str!("{}: ", label));
14            style_token.pop(ui);
15            return;
16        }
17
18        match get_same_or_none(data) {
19            Some(_v) => {
20                // Values are consistent
21                ui.text(&imgui::im_str!("{}: {}", label, data[0]))
22            }
23            None => {
24                // Values are inconsistent
25                let style_token =
26                    ui.push_style_color(imgui::StyleColor::Text, [1.0, 1.0, 0.0, 1.0]);
27                ui.text(&imgui::im_str!("{}: ", label));
28                style_token.pop(ui);
29            }
30        }
31    }
32
33    fn render_mut(
34        data: &mut [&mut bool],
35        label: &'static str,
36        ui: &imgui::Ui,
37        _args: &InspectArgsDefault,
38    ) -> bool {
39        let same_or_none_value = get_same_or_none_mut(data);
40
41        // Some reasonable default
42        let mut value = same_or_none_value.unwrap_or(false);
43
44        let style_token = if same_or_none_value.is_none() {
45            // If values are inconsistent, push a style
46            Some(ui.push_style_color(imgui::StyleColor::Text, [1.0, 1.0, 0.0, 1.0]))
47        } else {
48            None
49        };
50
51        let mut changed = false;
52        if ui.checkbox(&imgui::im_str!("{}", label), &mut value) {
53            for d in data {
54                **d = value;
55                changed = true;
56            }
57        }
58
59        if let Some(style_token) = style_token {
60            style_token.pop(ui);
61        }
62
63        changed
64    }
65}