use super::validation::{
assert_color_single_choice_mask, color_button_supported_mask, color_data_type_mask,
color_display_mask, color_edit_supported_mask, color_input_mask, color_picker_mask,
color_picker_supported_mask, validate_color_button_flags, validate_color_edit_flags,
validate_color_picker_flags, validate_color_supported_bits,
};
use crate::sys;
bitflags::bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)]
pub struct ColorEditFlags: u32 {
const NONE = 0;
const NO_ALPHA = sys::ImGuiColorEditFlags_NoAlpha as u32;
const NO_PICKER = sys::ImGuiColorEditFlags_NoPicker as u32;
const NO_OPTIONS = sys::ImGuiColorEditFlags_NoOptions as u32;
const NO_SMALL_PREVIEW = sys::ImGuiColorEditFlags_NoSmallPreview as u32;
const NO_INPUTS = sys::ImGuiColorEditFlags_NoInputs as u32;
const NO_TOOLTIP = sys::ImGuiColorEditFlags_NoTooltip as u32;
const NO_LABEL = sys::ImGuiColorEditFlags_NoLabel as u32;
const NO_DRAG_DROP = sys::ImGuiColorEditFlags_NoDragDrop as u32;
const NO_COLOR_MARKERS = sys::ImGuiColorEditFlags_NoColorMarkers as u32;
const ALPHA_BAR = sys::ImGuiColorEditFlags_AlphaBar as u32;
const ALPHA_OPAQUE = sys::ImGuiColorEditFlags_AlphaOpaque as u32;
const ALPHA_NO_BG = sys::ImGuiColorEditFlags_AlphaNoBg as u32;
const ALPHA_PREVIEW = Self::ALPHA_NO_BG.bits();
const ALPHA_PREVIEW_HALF = sys::ImGuiColorEditFlags_AlphaPreviewHalf as u32;
const HDR = sys::ImGuiColorEditFlags_HDR as u32;
}
}
bitflags::bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)]
pub struct ColorPickerFlags: u32 {
const NONE = 0;
const NO_ALPHA = sys::ImGuiColorEditFlags_NoAlpha as u32;
const NO_OPTIONS = sys::ImGuiColorEditFlags_NoOptions as u32;
const NO_SMALL_PREVIEW = sys::ImGuiColorEditFlags_NoSmallPreview as u32;
const NO_INPUTS = sys::ImGuiColorEditFlags_NoInputs as u32;
const NO_TOOLTIP = sys::ImGuiColorEditFlags_NoTooltip as u32;
const NO_LABEL = sys::ImGuiColorEditFlags_NoLabel as u32;
const NO_SIDE_PREVIEW = sys::ImGuiColorEditFlags_NoSidePreview as u32;
const ALPHA_BAR = sys::ImGuiColorEditFlags_AlphaBar as u32;
const ALPHA_OPAQUE = sys::ImGuiColorEditFlags_AlphaOpaque as u32;
const ALPHA_NO_BG = sys::ImGuiColorEditFlags_AlphaNoBg as u32;
const ALPHA_PREVIEW = Self::ALPHA_NO_BG.bits();
const ALPHA_PREVIEW_HALF = sys::ImGuiColorEditFlags_AlphaPreviewHalf as u32;
const HDR = sys::ImGuiColorEditFlags_HDR as u32;
}
}
bitflags::bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)]
pub struct ColorButtonFlags: u32 {
const NONE = 0;
const NO_ALPHA = sys::ImGuiColorEditFlags_NoAlpha as u32;
const NO_TOOLTIP = sys::ImGuiColorEditFlags_NoTooltip as u32;
const NO_DRAG_DROP = sys::ImGuiColorEditFlags_NoDragDrop as u32;
const NO_BORDER = sys::ImGuiColorEditFlags_NoBorder as u32;
const ALPHA_OPAQUE = sys::ImGuiColorEditFlags_AlphaOpaque as u32;
const ALPHA_NO_BG = sys::ImGuiColorEditFlags_AlphaNoBg as u32;
const ALPHA_PREVIEW = Self::ALPHA_NO_BG.bits();
const ALPHA_PREVIEW_HALF = sys::ImGuiColorEditFlags_AlphaPreviewHalf as u32;
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ColorDisplayMode {
Rgb,
Hsv,
Hex,
}
impl ColorDisplayMode {
const fn raw(self) -> u32 {
match self {
Self::Rgb => sys::ImGuiColorEditFlags_DisplayRGB as u32,
Self::Hsv => sys::ImGuiColorEditFlags_DisplayHSV as u32,
Self::Hex => sys::ImGuiColorEditFlags_DisplayHex as u32,
}
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ColorDataType {
Uint8,
Float,
}
impl ColorDataType {
const fn raw(self) -> u32 {
match self {
Self::Uint8 => sys::ImGuiColorEditFlags_Uint8 as u32,
Self::Float => sys::ImGuiColorEditFlags_Float as u32,
}
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ColorPickerMode {
HueBar,
HueWheel,
}
impl ColorPickerMode {
const fn raw(self) -> u32 {
match self {
Self::HueBar => sys::ImGuiColorEditFlags_PickerHueBar as u32,
Self::HueWheel => sys::ImGuiColorEditFlags_PickerHueWheel as u32,
}
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ColorInputMode {
Rgb,
Hsv,
}
impl ColorInputMode {
const fn raw(self) -> u32 {
match self {
Self::Rgb => sys::ImGuiColorEditFlags_InputRGB as u32,
Self::Hsv => sys::ImGuiColorEditFlags_InputHSV as u32,
}
}
}
bitflags::bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct ColorPickerDisplayFlags: u32 {
const RGB = sys::ImGuiColorEditFlags_DisplayRGB as u32;
const HSV = sys::ImGuiColorEditFlags_DisplayHSV as u32;
const HEX = sys::ImGuiColorEditFlags_DisplayHex as u32;
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct ColorEditOptions {
pub flags: ColorEditFlags,
pub display_mode: Option<ColorDisplayMode>,
pub data_type: Option<ColorDataType>,
pub picker_mode: Option<ColorPickerMode>,
pub input_mode: Option<ColorInputMode>,
}
impl ColorEditOptions {
pub const fn new() -> Self {
Self {
flags: ColorEditFlags::NONE,
display_mode: None,
data_type: None,
picker_mode: None,
input_mode: None,
}
}
pub fn flags(mut self, flags: ColorEditFlags) -> Self {
self.flags = flags;
self
}
pub fn display_mode(mut self, mode: ColorDisplayMode) -> Self {
self.display_mode = Some(mode);
self
}
pub fn data_type(mut self, data_type: ColorDataType) -> Self {
self.data_type = Some(data_type);
self
}
pub fn picker_mode(mut self, mode: ColorPickerMode) -> Self {
self.picker_mode = Some(mode);
self
}
pub fn input_mode(mut self, mode: ColorInputMode) -> Self {
self.input_mode = Some(mode);
self
}
pub fn bits(self) -> u32 {
self.flags.bits()
| self.display_mode.map_or(0, ColorDisplayMode::raw)
| self.data_type.map_or(0, ColorDataType::raw)
| self.picker_mode.map_or(0, ColorPickerMode::raw)
| self.input_mode.map_or(0, ColorInputMode::raw)
}
pub(crate) fn validate(self, caller: &str) {
validate_color_edit_flags(caller, self.flags);
validate_color_supported_bits(caller, self.bits(), color_edit_supported_mask());
assert_color_single_choice_mask(caller, self.bits(), color_display_mask(), "display mode");
assert_color_single_choice_mask(caller, self.bits(), color_data_type_mask(), "data type");
assert_color_single_choice_mask(caller, self.bits(), color_picker_mask(), "picker mode");
assert_color_single_choice_mask(caller, self.bits(), color_input_mask(), "input mode");
}
}
impl Default for ColorEditOptions {
fn default() -> Self {
Self::new()
}
}
impl From<ColorEditFlags> for ColorEditOptions {
fn from(flags: ColorEditFlags) -> Self {
Self::new().flags(flags)
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct ColorPickerOptions {
pub flags: ColorPickerFlags,
pub display_flags: ColorPickerDisplayFlags,
pub data_type: Option<ColorDataType>,
pub picker_mode: Option<ColorPickerMode>,
pub input_mode: Option<ColorInputMode>,
}
impl ColorPickerOptions {
pub const fn new() -> Self {
Self {
flags: ColorPickerFlags::NONE,
display_flags: ColorPickerDisplayFlags::empty(),
data_type: None,
picker_mode: None,
input_mode: None,
}
}
pub fn flags(mut self, flags: ColorPickerFlags) -> Self {
self.flags = flags;
self
}
pub fn display_flags(mut self, flags: ColorPickerDisplayFlags) -> Self {
self.display_flags = flags;
self
}
pub fn data_type(mut self, data_type: ColorDataType) -> Self {
self.data_type = Some(data_type);
self
}
pub fn picker_mode(mut self, mode: ColorPickerMode) -> Self {
self.picker_mode = Some(mode);
self
}
pub fn input_mode(mut self, mode: ColorInputMode) -> Self {
self.input_mode = Some(mode);
self
}
pub fn bits(self) -> u32 {
self.flags.bits()
| self.display_flags.bits()
| self.data_type.map_or(0, ColorDataType::raw)
| self.picker_mode.map_or(0, ColorPickerMode::raw)
| self.input_mode.map_or(0, ColorInputMode::raw)
}
pub(crate) fn validate(self, caller: &str) {
validate_color_picker_flags(caller, self.flags);
let unsupported_display =
self.display_flags.bits() & !ColorPickerDisplayFlags::all().bits();
assert!(
unsupported_display == 0,
"{caller} received unsupported ColorPickerDisplayFlags bits: 0x{unsupported_display:X}"
);
validate_color_supported_bits(caller, self.bits(), color_picker_supported_mask());
assert_color_single_choice_mask(caller, self.bits(), color_data_type_mask(), "data type");
assert_color_single_choice_mask(caller, self.bits(), color_picker_mask(), "picker mode");
assert_color_single_choice_mask(caller, self.bits(), color_input_mask(), "input mode");
}
}
impl Default for ColorPickerOptions {
fn default() -> Self {
Self::new()
}
}
impl From<ColorPickerFlags> for ColorPickerOptions {
fn from(flags: ColorPickerFlags) -> Self {
Self::new().flags(flags)
}
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct ColorButtonOptions {
pub flags: ColorButtonFlags,
pub input_mode: Option<ColorInputMode>,
}
impl ColorButtonOptions {
pub const fn new() -> Self {
Self {
flags: ColorButtonFlags::NONE,
input_mode: None,
}
}
pub fn flags(mut self, flags: ColorButtonFlags) -> Self {
self.flags = flags;
self
}
pub fn input_mode(mut self, mode: ColorInputMode) -> Self {
self.input_mode = Some(mode);
self
}
pub fn bits(self) -> u32 {
self.flags.bits() | self.input_mode.map_or(0, ColorInputMode::raw)
}
pub(crate) fn validate(self, caller: &str) {
validate_color_button_flags(caller, self.flags);
validate_color_supported_bits(caller, self.bits(), color_button_supported_mask());
assert_color_single_choice_mask(caller, self.bits(), color_input_mask(), "input mode");
}
}
impl Default for ColorButtonOptions {
fn default() -> Self {
Self::new()
}
}
impl From<ColorButtonFlags> for ColorButtonOptions {
fn from(flags: ColorButtonFlags) -> Self {
Self::new().flags(flags)
}
}