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
use super::*;

impl CurrentContext<'_> {
    pub fn style(&mut self) -> &mut Style {
        unsafe {
            let ptr = ImGui_GetStyle();
            &mut *(ptr as *mut Style)
        }
    }
}

impl<A> Ui<A> {
    pub fn style(&self) -> &Style {
        unsafe {
            let ptr = ImGui_GetStyle();
            &*(ptr as *const Style)
        }
    }
}

/// A wrapper for the `ImGuiStyle` type.
///
/// It can be deref-ed directly into a `ImGuiStyle` reference.
#[derive(Debug)]
#[repr(transparent)]
pub struct Style(ImGuiStyle);

impl std::ops::Deref for Style {
    type Target = ImGuiStyle;
    fn deref(&self) -> &ImGuiStyle {
        self.get()
    }
}

impl std::ops::DerefMut for Style {
    fn deref_mut(&mut self) -> &mut ImGuiStyle {
        self.get_mut()
    }
}

impl Style {
    pub fn get(&self) -> &ImGuiStyle {
        &self.0
    }
    pub fn get_mut(&mut self) -> &mut ImGuiStyle {
        &mut self.0
    }
    pub fn set_colors_light(&mut self) {
        unsafe {
            ImGui_StyleColorsLight(&mut self.0);
        }
    }
    pub fn set_colors_dark(&mut self) {
        unsafe {
            ImGui_StyleColorsDark(&mut self.0);
        }
    }
    pub fn set_colors_classic(&mut self) {
        unsafe {
            ImGui_StyleColorsClassic(&mut self.0);
        }
    }
    pub fn color(&self, id: ColorId) -> Color {
        self.0.Colors[id.bits() as usize].into()
    }
    pub fn set_color(&mut self, id: ColorId, color: Color) {
        self.0.Colors[id.bits() as usize] = color.into();
    }
    pub fn color_alpha(&self, id: ColorId, alpha_mul: f32) -> Color {
        let mut c = self.color(id);
        let a = self.Alpha;
        c.a *= a * alpha_mul;
        c
    }
}