Skip to main content

dear_imgui_rs/style/
color.rs

1#![allow(
2    clippy::cast_possible_truncation,
3    clippy::cast_sign_loss,
4    clippy::as_conversions
5)]
6
7use super::{Style, validate_style_color};
8use crate::sys;
9#[cfg(feature = "serde")]
10use serde::{Deserialize, Serialize};
11
12/// Style color identifier
13#[repr(i32)]
14#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16pub enum StyleColor {
17    Text = sys::ImGuiCol_Text as i32,
18    TextDisabled = sys::ImGuiCol_TextDisabled as i32,
19    WindowBg = sys::ImGuiCol_WindowBg as i32,
20    ChildBg = sys::ImGuiCol_ChildBg as i32,
21    PopupBg = sys::ImGuiCol_PopupBg as i32,
22    Border = sys::ImGuiCol_Border as i32,
23    BorderShadow = sys::ImGuiCol_BorderShadow as i32,
24    FrameBg = sys::ImGuiCol_FrameBg as i32,
25    FrameBgHovered = sys::ImGuiCol_FrameBgHovered as i32,
26    FrameBgActive = sys::ImGuiCol_FrameBgActive as i32,
27    TitleBg = sys::ImGuiCol_TitleBg as i32,
28    TitleBgActive = sys::ImGuiCol_TitleBgActive as i32,
29    TitleBgCollapsed = sys::ImGuiCol_TitleBgCollapsed as i32,
30    MenuBarBg = sys::ImGuiCol_MenuBarBg as i32,
31    ScrollbarBg = sys::ImGuiCol_ScrollbarBg as i32,
32    ScrollbarGrab = sys::ImGuiCol_ScrollbarGrab as i32,
33    ScrollbarGrabHovered = sys::ImGuiCol_ScrollbarGrabHovered as i32,
34    ScrollbarGrabActive = sys::ImGuiCol_ScrollbarGrabActive as i32,
35    CheckMark = sys::ImGuiCol_CheckMark as i32,
36    CheckboxSelectedBg = sys::ImGuiCol_CheckboxSelectedBg as i32,
37    SliderGrab = sys::ImGuiCol_SliderGrab as i32,
38    SliderGrabActive = sys::ImGuiCol_SliderGrabActive as i32,
39    Button = sys::ImGuiCol_Button as i32,
40    ButtonHovered = sys::ImGuiCol_ButtonHovered as i32,
41    ButtonActive = sys::ImGuiCol_ButtonActive as i32,
42    Header = sys::ImGuiCol_Header as i32,
43    HeaderHovered = sys::ImGuiCol_HeaderHovered as i32,
44    HeaderActive = sys::ImGuiCol_HeaderActive as i32,
45    Separator = sys::ImGuiCol_Separator as i32,
46    SeparatorHovered = sys::ImGuiCol_SeparatorHovered as i32,
47    SeparatorActive = sys::ImGuiCol_SeparatorActive as i32,
48    ResizeGrip = sys::ImGuiCol_ResizeGrip as i32,
49    ResizeGripHovered = sys::ImGuiCol_ResizeGripHovered as i32,
50    ResizeGripActive = sys::ImGuiCol_ResizeGripActive as i32,
51    Tab = sys::ImGuiCol_Tab as i32,
52    TabHovered = sys::ImGuiCol_TabHovered as i32,
53    // Newly added tab colors in docking branch
54    TabSelected = sys::ImGuiCol_TabSelected as i32,
55    TabSelectedOverline = sys::ImGuiCol_TabSelectedOverline as i32,
56    TabDimmed = sys::ImGuiCol_TabDimmed as i32,
57    TabDimmedSelected = sys::ImGuiCol_TabDimmedSelected as i32,
58    TabDimmedSelectedOverline = sys::ImGuiCol_TabDimmedSelectedOverline as i32,
59    DockingPreview = sys::ImGuiCol_DockingPreview as i32,
60    DockingEmptyBg = sys::ImGuiCol_DockingEmptyBg as i32,
61    PlotLines = sys::ImGuiCol_PlotLines as i32,
62    PlotLinesHovered = sys::ImGuiCol_PlotLinesHovered as i32,
63    PlotHistogram = sys::ImGuiCol_PlotHistogram as i32,
64    PlotHistogramHovered = sys::ImGuiCol_PlotHistogramHovered as i32,
65    TableHeaderBg = sys::ImGuiCol_TableHeaderBg as i32,
66    TableBorderStrong = sys::ImGuiCol_TableBorderStrong as i32,
67    TableBorderLight = sys::ImGuiCol_TableBorderLight as i32,
68    TableRowBg = sys::ImGuiCol_TableRowBg as i32,
69    TableRowBgAlt = sys::ImGuiCol_TableRowBgAlt as i32,
70    TextSelectedBg = sys::ImGuiCol_TextSelectedBg as i32,
71    TextLink = sys::ImGuiCol_TextLink as i32,
72    TreeLines = sys::ImGuiCol_TreeLines as i32,
73    InputTextCursor = sys::ImGuiCol_InputTextCursor as i32,
74    DragDropTarget = sys::ImGuiCol_DragDropTarget as i32,
75    DragDropTargetBg = sys::ImGuiCol_DragDropTargetBg as i32,
76    UnsavedMarker = sys::ImGuiCol_UnsavedMarker as i32,
77    NavCursor = sys::ImGuiCol_NavCursor as i32,
78    NavWindowingHighlight = sys::ImGuiCol_NavWindowingHighlight as i32,
79    NavWindowingDimBg = sys::ImGuiCol_NavWindowingDimBg as i32,
80    ModalWindowDimBg = sys::ImGuiCol_ModalWindowDimBg as i32,
81}
82
83impl StyleColor {
84    pub const COUNT: usize = sys::ImGuiCol_COUNT as usize;
85}
86
87impl Style {
88    /// Get a color by style color identifier
89    pub fn color(&self, color: StyleColor) -> [f32; 4] {
90        let c = self.inner().Colors[color as usize];
91        [c.x, c.y, c.z, c.w]
92    }
93
94    /// Set a color by style color identifier
95    pub fn set_color(&mut self, color: StyleColor, value: [f32; 4]) {
96        validate_style_color("Style::set_color()", "value", value);
97        self.inner_mut().Colors[color as usize] = sys::ImVec4 {
98            x: value[0],
99            y: value[1],
100            z: value[2],
101            w: value[3],
102        };
103    }
104}