Skip to main content

imgui_inspect/default/
default_u32.rs

1use super::*;
2
3impl InspectRenderDefault<u32> for u32 {
4    fn render(
5        data: &[&u32],
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 u32],
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 value = same_or_none_value.unwrap_or(0);
43
44        // CAST
45        let mut value = value as i32;
46
47        let style_token = if same_or_none_value.is_none() {
48            // If values are inconsistent, push a style
49            Some(ui.push_style_color(imgui::StyleColor::Text, [1.0, 1.0, 0.0, 1.0]))
50        } else {
51            None
52        };
53
54        let mut changed = false;
55        if ui
56            .input_int(&imgui::im_str!("{}", label), &mut value)
57            .build()
58        {
59            for d in data {
60                // CAST
61                let value = value as u32;
62
63                **d = value;
64                changed = true;
65            }
66        }
67
68        if let Some(style_token) = style_token {
69            style_token.pop(ui);
70        }
71
72        changed
73    }
74}