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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
use bitflags::bitflags;
use std::ptr;

use crate::sys;
use crate::Ui;

/// Mutable reference to an editable color value.
#[derive(Debug)]
pub enum EditableColor<'a> {
    /// Color value with three float components (e.g. RGB).
    Float3(&'a mut [f32; 3]),
    /// Color value with four float components (e.g. RGBA).
    Float4(&'a mut [f32; 4]),
}

impl<'a> EditableColor<'a> {
    /// Returns an unsafe mutable pointer to the color slice's buffer.
    fn as_mut_ptr(&mut self) -> *mut f32 {
        match *self {
            EditableColor::Float3(ref mut value) => value.as_mut_ptr(),
            EditableColor::Float4(ref mut value) => value.as_mut_ptr(),
        }
    }
}

impl<'a> From<&'a mut [f32; 3]> for EditableColor<'a> {
    #[inline]
    fn from(value: &'a mut [f32; 3]) -> EditableColor<'a> {
        EditableColor::Float3(value)
    }
}

impl<'a> From<&'a mut [f32; 4]> for EditableColor<'a> {
    #[inline]
    fn from(value: &'a mut [f32; 4]) -> EditableColor<'a> {
        EditableColor::Float4(value)
    }
}

/// Color editor input mode.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ColorEditInputMode {
    /// Edit as RGB(A).
    Rgb,
    /// Edit as HSV(A).
    Hsv,
}

impl ColorEditInputMode {
    // Note: Probably no point in deprecating these since they're ~0 maintance burden.
    /// Edit as RGB(A). Alias for [`Self::Rgb`] for backwards-compatibility.
    pub const RGB: Self = Self::Rgb;
    /// Edit as HSV(A). Alias for [`Self::Hsv`] for backwards-compatibility.
    pub const HSV: Self = Self::Hsv;
}

/// Color editor display mode.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ColorEditDisplayMode {
    /// Display as RGB(A).
    Rgb,
    /// Display as HSV(A).
    Hsv,
    /// Display as hex (e.g. `#AABBCC(DD)`)
    Hex,
}

impl ColorEditDisplayMode {
    // Note: Probably no point in deprecating these since they're ~0 maintance burden.
    /// Display as RGB(A). Alias for [`Self::Rgb`] for backwards-compatibility.
    pub const RGB: Self = Self::Rgb;
    /// Display as HSV(A). Alias for [`Self::Hsv`] for backwards-compatibility.
    pub const HSV: Self = Self::Hsv;
    /// Display as hex. Alias for [`Self::Hex`] for backwards-compatibility.
    pub const HEX: Self = Self::Hex;
}

/// Color picker hue/saturation/value editor mode
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ColorPickerMode {
    /// Use a bar for hue, rectangle for saturation/value.
    HueBar,
    /// Use a wheel for hue, triangle for saturation/value.
    HueWheel,
}

/// Color component formatting
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ColorFormat {
    /// Display values formatted as 0..255.
    U8,
    /// Display values formatted as 0.0..1.0.
    Float,
}

/// Color editor preview style
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ColorPreview {
    /// Don't show the alpha component.
    Opaque,
    /// Half of the preview area shows the alpha component using a checkerboard pattern.
    HalfAlpha,
    /// Show the alpha component using a checkerboard pattern.
    Alpha,
}

bitflags! {
    /// Color edit flags
    #[repr(transparent)]
    pub struct ColorEditFlags: u32 {
        /// ColorEdit, ColorPicker, ColorButton: ignore Alpha component (read only 3 components of
        /// the value).
        const NO_ALPHA = sys::ImGuiColorEditFlags_NoAlpha;
        /// ColorEdit: disable picker when clicking on colored square.
        const NO_PICKER = sys::ImGuiColorEditFlags_NoPicker;
        /// ColorEdit: disable toggling options menu when right-clicking on inputs/small preview.
        const NO_OPTIONS = sys::ImGuiColorEditFlags_NoOptions;
        /// ColorEdit, ColorPicker: disable colored square preview next to the inputs. (e.g. to
        /// show only the inputs)
        const NO_SMALL_PREVIEW = sys::ImGuiColorEditFlags_NoSmallPreview;
        /// ColorEdit, ColorPicker: disable inputs sliders/text widgets (e.g. to show only the
        /// small preview colored square).
        const NO_INPUTS = sys::ImGuiColorEditFlags_NoInputs;
        /// ColorEdit, ColorPicker, ColorButton: disable tooltip when hovering the preview.
        const NO_TOOLTIP = sys::ImGuiColorEditFlags_NoTooltip;
        /// ColorEdit, ColorPicker: disable display of inline text label (the label is still
        /// forwarded to the tooltip and picker).
        const NO_LABEL = sys::ImGuiColorEditFlags_NoLabel;
        /// ColorPicker: disable bigger color preview on right side of the picker, use small
        /// colored square preview instead.
        const NO_SIDE_PREVIEW = sys::ImGuiColorEditFlags_NoSidePreview;
        /// ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source.
        const NO_DRAG_DROP = sys::ImGuiColorEditFlags_NoDragDrop;
        /// ColorButton: disable border (which is enforced by default).
        const NO_BORDER = sys::ImGuiColorEditFlags_NoBorder;

        /// ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker.
        const ALPHA_BAR = sys::ImGuiColorEditFlags_AlphaBar;
        /// ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a
        /// checkerboard, instead of opaque.
        const ALPHA_PREVIEW = sys::ImGuiColorEditFlags_AlphaPreview;
        /// ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead
        /// of opaque.
        const ALPHA_PREVIEW_HALF = sys::ImGuiColorEditFlags_AlphaPreviewHalf;
        /// (WIP) ColorEdit: Currently onlys disable 0.0f..1.0f limits in RGBA editing (note: you
        /// probably want to use `ColorEditFlags::FLOAT` as well).
        const HDR = sys::ImGuiColorEditFlags_HDR;
        /// ColorEdit: display only as RGB. ColorPicker: Enable RGB display.
        const DISPLAY_RGB = sys::ImGuiColorEditFlags_DisplayRGB;
        /// ColorEdit: display only as HSV. ColorPicker: Enable HSV display.
        const DISPLAY_HSV = sys::ImGuiColorEditFlags_DisplayHSV;
        /// ColorEdit: display only as HEX. ColorPicker: Enable Hex display.
        const DISPLAY_HEX = sys::ImGuiColorEditFlags_DisplayHex;
        /// ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255.
        const UINT8 = sys::ImGuiColorEditFlags_Uint8;
        /// ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats
        /// instead of 0..255 integers. No round-trip of value via integers.
        const FLOAT = sys::ImGuiColorEditFlags_Float;
        /// ColorPicker: bar for Hue, rectangle for Sat/Value.
        const PICKER_HUE_BAR = sys::ImGuiColorEditFlags_PickerHueBar;
        /// ColorPicker: wheel for Hue, triangle for Sat/Value.
        const PICKER_HUE_WHEEL = sys::ImGuiColorEditFlags_PickerHueWheel;
        /// ColorEdit, ColorPicker: input and output data in RGB format.
        const INPUT_RGB = sys::ImGuiColorEditFlags_InputRGB;
        /// ColorEdit, ColorPicker: input and output data in HSV format.
        const INPUT_HSV = sys::ImGuiColorEditFlags_InputHSV;
    }
}

/// Builder for a color editor widget.
///
/// # Examples
///
/// ```no_run
/// # use arcdps_imgui::*;
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// # let mut color = [0.0, 0.0, 0.0, 1.0];
/// let ce = ColorEdit::new(im_str!("color_edit"), &mut color);
/// if ce.build(&ui) {
///   println!("The color was changed");
/// }
/// ```
#[derive(Debug)]
#[must_use]
pub struct ColorEdit<'a, T: AsRef<str> + 'a> {
    label: T,
    value: EditableColor<'a>,
    flags: ColorEditFlags,
}

impl<'a, T: AsRef<str> + 'a> ColorEdit<'a, T> {
    /// Constructs a new color editor builder.
    #[doc(alias = "ColorEdit3", alias = "ColorEdit4")]
    pub fn new(label: T, value: impl Into<EditableColor<'a>>) -> ColorEdit<'a, T> {
        ColorEdit {
            label,
            value: value.into(),
            flags: ColorEditFlags::empty(),
        }
    }
    /// Replaces all current settings with the given flags.
    #[inline]
    pub fn flags(mut self, flags: ColorEditFlags) -> Self {
        self.flags = flags;
        self
    }
    /// Enables/disables the use of the alpha component.
    #[inline]
    pub fn alpha(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_ALPHA, !value);
        self
    }
    /// Enables/disables the picker that appears when clicking on colored square.
    #[inline]
    pub fn picker(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_PICKER, !value);
        self
    }
    /// Enables/disables toggling of the options menu when right-clicking on inputs or the small
    /// preview.
    #[inline]
    pub fn options(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_OPTIONS, !value);
        self
    }
    /// Enables/disables the colored square preview next to the inputs.
    #[inline]
    pub fn small_preview(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_SMALL_PREVIEW, !value);
        self
    }
    /// Enables/disables the input sliders/text widgets.
    #[inline]
    pub fn inputs(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_INPUTS, !value);
        self
    }
    /// Enables/disables the tooltip that appears when hovering the preview.
    #[inline]
    pub fn tooltip(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_TOOLTIP, !value);
        self
    }
    /// Enables/disables display of the inline text label (the label is in any case forwarded to
    /// the tooltip and picker).
    #[inline]
    pub fn label(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_LABEL, !value);
        self
    }
    /// Enables/disables the vertical alpha bar/gradient in the color picker.
    #[inline]
    pub fn alpha_bar(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::ALPHA_BAR, value);
        self
    }
    /// Sets the preview style.
    #[inline]
    pub fn preview(mut self, preview: ColorPreview) -> Self {
        self.flags.set(
            ColorEditFlags::ALPHA_PREVIEW_HALF,
            preview == ColorPreview::HalfAlpha,
        );
        self.flags.set(
            ColorEditFlags::ALPHA_PREVIEW,
            preview == ColorPreview::Alpha,
        );
        self
    }
    /// (WIP) Currently only disables 0.0..1.0 limits in RGBA edition.
    ///
    /// Note: you probably want to use ColorFormat::Float as well.
    #[inline]
    pub fn hdr(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::HDR, value);
        self
    }
    /// Sets the data format for input and output data.
    #[inline]
    pub fn input_mode(mut self, input_mode: ColorEditInputMode) -> Self {
        self.flags.set(
            ColorEditFlags::INPUT_RGB,
            input_mode == ColorEditInputMode::RGB,
        );
        self.flags.set(
            ColorEditFlags::INPUT_HSV,
            input_mode == ColorEditInputMode::HSV,
        );
        self
    }
    /// Sets the color editor display mode.
    #[inline]
    pub fn display_mode(mut self, mode: ColorEditDisplayMode) -> Self {
        self.flags.set(
            ColorEditFlags::DISPLAY_RGB,
            mode == ColorEditDisplayMode::RGB,
        );
        self.flags.set(
            ColorEditFlags::DISPLAY_HSV,
            mode == ColorEditDisplayMode::HSV,
        );
        self.flags.set(
            ColorEditFlags::DISPLAY_HEX,
            mode == ColorEditDisplayMode::HEX,
        );
        self
    }
    /// Sets the formatting style of color components.
    #[inline]
    pub fn format(mut self, format: ColorFormat) -> Self {
        self.flags
            .set(ColorEditFlags::UINT8, format == ColorFormat::U8);
        self.flags
            .set(ColorEditFlags::FLOAT, format == ColorFormat::Float);
        self
    }
    /// Builds the color editor.
    ///
    /// Returns true if the color value was changed.
    pub fn build(mut self, ui: &Ui<'_>) -> bool {
        if let EditableColor::Float3(_) = self.value {
            self.flags.insert(ColorEditFlags::NO_ALPHA);
        }
        match self.value {
            EditableColor::Float3(value) => unsafe {
                sys::igColorEdit3(
                    ui.scratch_txt(self.label),
                    value.as_mut_ptr(),
                    self.flags.bits() as _,
                )
            },
            EditableColor::Float4(value) => unsafe {
                sys::igColorEdit4(
                    ui.scratch_txt(self.label),
                    value.as_mut_ptr(),
                    self.flags.bits() as _,
                )
            },
        }
    }
}

/// Builder for a color picker widget.
///
/// # Examples
///
/// ```no_run
/// # use arcdps_imgui::*;
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// # let mut color = [0.0, 0.0, 0.0, 1.0];
/// let cp = ColorPicker::new(im_str!("color_picker"), &mut color);
/// if cp.build(&ui) {
///   println!("A color was picked");
/// }
/// ```
#[derive(Debug)]
#[must_use]
pub struct ColorPicker<'a, T: AsRef<str> + 'a> {
    label: T,
    value: EditableColor<'a>,
    flags: ColorEditFlags,
    ref_color: Option<&'a [f32; 4]>,
}

impl<'a, T: AsRef<str>> ColorPicker<'a, T> {
    /// Constructs a new color picker builder.
    #[doc(alias = "ColorButton")]
    pub fn new(label: T, value: impl Into<EditableColor<'a>>) -> Self {
        ColorPicker {
            label,
            value: value.into(),
            flags: ColorEditFlags::empty(),
            ref_color: None,
        }
    }
    /// Replaces all current settings with the given flags.
    #[inline]
    pub fn flags(mut self, flags: ColorEditFlags) -> Self {
        self.flags = flags;
        self
    }
    /// Enables/disables the use of the alpha component.
    #[inline]
    pub fn alpha(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_ALPHA, !value);
        self
    }
    /// Enables/disables toggling of the options menu when right-clicking on inputs or the small
    /// preview.
    #[inline]
    pub fn options(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_OPTIONS, !value);
        self
    }
    /// Enables/disables the colored square preview next to the inputs.
    #[inline]
    pub fn small_preview(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_SMALL_PREVIEW, !value);
        self
    }
    /// Enables/disables the input sliders/text widgets.
    #[inline]
    pub fn inputs(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_INPUTS, !value);
        self
    }
    /// Enables/disables the tooltip that appears when hovering the preview.
    #[inline]
    pub fn tooltip(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_TOOLTIP, !value);
        self
    }
    /// Enables/disables display of the inline text label (the label is in any case forwarded to
    /// the tooltip and picker).
    #[inline]
    pub fn label(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_LABEL, !value);
        self
    }
    /// Enables/disables the bigger color preview on the right side of the picker.
    #[inline]
    pub fn side_preview(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_SIDE_PREVIEW, !value);
        self
    }
    /// Enables/disables the vertical alpha bar/gradient in the color picker.
    #[inline]
    pub fn alpha_bar(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::ALPHA_BAR, value);
        self
    }
    /// Sets the preview style.
    #[inline]
    pub fn preview(mut self, preview: ColorPreview) -> Self {
        self.flags.set(
            ColorEditFlags::ALPHA_PREVIEW_HALF,
            preview == ColorPreview::HalfAlpha,
        );
        self.flags.set(
            ColorEditFlags::ALPHA_PREVIEW,
            preview == ColorPreview::Alpha,
        );
        self
    }
    /// Sets the data format for input and output data.
    #[inline]
    pub fn input_mode(mut self, input_mode: ColorEditInputMode) -> Self {
        self.flags.set(
            ColorEditFlags::INPUT_RGB,
            input_mode == ColorEditInputMode::RGB,
        );
        self.flags.set(
            ColorEditFlags::INPUT_HSV,
            input_mode == ColorEditInputMode::HSV,
        );
        self
    }
    /// Enables/disables displaying the value as RGB.
    #[inline]
    pub fn display_rgb(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::DISPLAY_RGB, value);
        self
    }
    /// Enables/disables displaying the value as HSV.
    #[inline]
    pub fn display_hsv(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::DISPLAY_HSV, value);
        self
    }
    /// Enables/disables displaying the value as hex.
    #[inline]
    pub fn display_hex(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::DISPLAY_HEX, value);
        self
    }
    /// Sets the hue/saturation/value editor mode.
    #[inline]
    pub fn mode(mut self, mode: ColorPickerMode) -> Self {
        self.flags.set(
            ColorEditFlags::PICKER_HUE_BAR,
            mode == ColorPickerMode::HueBar,
        );
        self.flags.set(
            ColorEditFlags::PICKER_HUE_WHEEL,
            mode == ColorPickerMode::HueWheel,
        );
        self
    }
    /// Sets the formatting style of color components.
    #[inline]
    pub fn format(mut self, format: ColorFormat) -> Self {
        self.flags
            .set(ColorEditFlags::UINT8, format == ColorFormat::U8);
        self.flags
            .set(ColorEditFlags::FLOAT, format == ColorFormat::Float);
        self
    }
    /// Sets the shown reference color.
    #[inline]
    pub fn reference_color(mut self, ref_color: &'a [f32; 4]) -> Self {
        self.ref_color = Some(ref_color);
        self
    }
    /// Builds the color picker.
    ///
    /// Returns true if the color value was changed.
    pub fn build(mut self, ui: &Ui<'_>) -> bool {
        if let EditableColor::Float3(_) = self.value {
            self.flags.insert(ColorEditFlags::NO_ALPHA);
        }
        let ref_color = self.ref_color.map(|c| c.as_ptr()).unwrap_or(ptr::null());
        unsafe {
            sys::igColorPicker4(
                ui.scratch_txt(self.label),
                self.value.as_mut_ptr(),
                self.flags.bits() as _,
                ref_color,
            )
        }
    }
}

/// Builder for a color button widget.
///
/// # Examples
///
/// ```no_run
/// # use arcdps_imgui::*;
/// # let mut imgui = Context::create();
/// # let ui = imgui.frame();
/// ColorButton::new(im_str!("color_button"), [1.0, 0.0, 0.0, 1.0])
///     .build(&ui);
/// ```
#[derive(Copy, Clone, Debug)]
#[must_use]
pub struct ColorButton<T> {
    desc_id: T,
    color: [f32; 4],
    flags: ColorEditFlags,
    size: [f32; 2],
}

impl<T: AsRef<str>> ColorButton<T> {
    /// Constructs a new color button builder.
    pub fn new(desc_id: T, color: [f32; 4]) -> Self {
        ColorButton {
            desc_id,
            color,
            flags: ColorEditFlags::empty(),
            size: [0.0, 0.0],
        }
    }
    /// Replaces all current settings with the given flags.
    #[inline]
    pub fn flags(mut self, flags: ColorEditFlags) -> Self {
        self.flags = flags;
        self
    }
    /// Enables/disables the use of the alpha component.
    #[inline]
    pub fn alpha(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_ALPHA, !value);
        self
    }
    /// Enables/disables the tooltip that appears when hovering the preview.
    #[inline]
    pub fn tooltip(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_TOOLTIP, !value);
        self
    }
    /// Sets the preview style.
    #[inline]
    pub fn preview(mut self, preview: ColorPreview) -> Self {
        self.flags.set(
            ColorEditFlags::ALPHA_PREVIEW_HALF,
            preview == ColorPreview::HalfAlpha,
        );
        self.flags.set(
            ColorEditFlags::ALPHA_PREVIEW,
            preview == ColorPreview::Alpha,
        );
        self
    }
    /// Sets the data format for input data.
    #[inline]
    pub fn input_mode(mut self, input_mode: ColorEditInputMode) -> Self {
        self.flags.set(
            ColorEditFlags::INPUT_RGB,
            input_mode == ColorEditInputMode::RGB,
        );
        self.flags.set(
            ColorEditFlags::INPUT_HSV,
            input_mode == ColorEditInputMode::HSV,
        );
        self
    }
    /// Enables/disables using the button as drag&drop source.
    ///
    /// Enabled by default.
    pub fn drag_drop(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_DRAG_DROP, !value);
        self
    }
    /// Enables/disables the button border.
    ///
    /// Enabled by default.
    pub fn border(mut self, value: bool) -> Self {
        self.flags.set(ColorEditFlags::NO_BORDER, !value);
        self
    }
    /// Sets the button size.
    ///
    /// Use 0.0 for width and/or height to use the default size.
    #[inline]
    pub fn size(mut self, size: [f32; 2]) -> Self {
        self.size = size;
        self
    }
    /// Builds the color button.
    ///
    /// Returns true if this color button was clicked.
    pub fn build(self, ui: &Ui<'_>) -> bool {
        unsafe {
            sys::igColorButton(
                ui.scratch_txt(self.desc_id),
                self.color.into(),
                self.flags.bits() as _,
                self.size.into(),
            )
        }
    }
}

/// # Widgets: Color Editor/Picker
impl<'ui> Ui<'ui> {
    /// Initializes current color editor/picker options (generally on application startup) if you
    /// want to select a default format, picker type, etc. Users will be able to change many
    /// settings, unless you use .options(false) in your widget builders.
    #[doc(alias = "SetColorEditOptions")]
    pub fn set_color_edit_options(&self, flags: ColorEditFlags) {
        unsafe {
            sys::igSetColorEditOptions(flags.bits() as i32);
        }
    }
}