|
@@ -254,6 +254,7 @@ static void DemoWindowWidgetsBasic();
|
|
|
static void DemoWindowWidgetsBullets();
|
|
|
static void DemoWindowWidgetsCollapsingHeaders();
|
|
|
static void DemoWindowWidgetsComboBoxes();
|
|
|
+static void DemoWindowWidgetsColorAndPickers();
|
|
|
static void DemoWindowWidgetsDataTypes();
|
|
|
static void DemoWindowWidgetsImages();
|
|
|
static void DemoWindowWidgetsListBoxes();
|
|
@@ -827,6 +828,7 @@ static void DemoWindowWidgets(ImGuiDemoWindowData* demo_data)
|
|
|
DemoWindowWidgetsBullets();
|
|
|
DemoWindowWidgetsCollapsingHeaders();
|
|
|
DemoWindowWidgetsComboBoxes();
|
|
|
+ DemoWindowWidgetsColorAndPickers();
|
|
|
DemoWindowWidgetsDataTypes();
|
|
|
DemoWindowWidgetsImages();
|
|
|
DemoWindowWidgetsListBoxes();
|
|
@@ -841,199 +843,6 @@ static void DemoWindowWidgets(ImGuiDemoWindowData* demo_data)
|
|
|
DemoWindowWidgetsTooltips();
|
|
|
DemoWindowWidgetsTreeNodes();
|
|
|
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color");
|
|
|
- if (ImGui::TreeNode("Color/Picker Widgets"))
|
|
|
- {
|
|
|
- static ImVec4 color = ImVec4(114.0f / 255.0f, 144.0f / 255.0f, 154.0f / 255.0f, 200.0f / 255.0f);
|
|
|
- static ImGuiColorEditFlags base_flags = ImGuiColorEditFlags_None;
|
|
|
-
|
|
|
- ImGui::SeparatorText("Options");
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_NoAlpha", &base_flags, ImGuiColorEditFlags_NoAlpha);
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaOpaque", &base_flags, ImGuiColorEditFlags_AlphaOpaque);
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaNoBg", &base_flags, ImGuiColorEditFlags_AlphaNoBg);
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaPreviewHalf", &base_flags, ImGuiColorEditFlags_AlphaPreviewHalf);
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_NoDragDrop", &base_flags, ImGuiColorEditFlags_NoDragDrop);
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_NoOptions", &base_flags, ImGuiColorEditFlags_NoOptions); ImGui::SameLine(); HelpMarker("Right-click on the individual color widget to show options.");
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_HDR", &base_flags, ImGuiColorEditFlags_HDR); ImGui::SameLine(); HelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets.");
|
|
|
-
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit");
|
|
|
- ImGui::SeparatorText("Inline color editor");
|
|
|
- ImGui::Text("Color widget:");
|
|
|
- ImGui::SameLine(); HelpMarker(
|
|
|
- "Click on the color square to open a color picker.\n"
|
|
|
- "CTRL+click on individual component to input value.\n");
|
|
|
- ImGui::ColorEdit3("MyColor##1", (float*)&color, base_flags);
|
|
|
-
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit (HSV, with Alpha)");
|
|
|
- ImGui::Text("Color widget HSV with Alpha:");
|
|
|
- ImGui::ColorEdit4("MyColor##2", (float*)&color, ImGuiColorEditFlags_DisplayHSV | base_flags);
|
|
|
-
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit (float display)");
|
|
|
- ImGui::Text("Color widget with Float Display:");
|
|
|
- ImGui::ColorEdit4("MyColor##2f", (float*)&color, ImGuiColorEditFlags_Float | base_flags);
|
|
|
-
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (with Picker)");
|
|
|
- ImGui::Text("Color button with Picker:");
|
|
|
- ImGui::SameLine(); HelpMarker(
|
|
|
- "With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs.\n"
|
|
|
- "With the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only "
|
|
|
- "be used for the tooltip and picker popup.");
|
|
|
- ImGui::ColorEdit4("MyColor##3", (float*)&color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | base_flags);
|
|
|
-
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (with custom Picker popup)");
|
|
|
- ImGui::Text("Color button with Custom Picker Popup:");
|
|
|
-
|
|
|
- // Generate a default palette. The palette will persist and can be edited.
|
|
|
- static bool saved_palette_init = true;
|
|
|
- static ImVec4 saved_palette[32] = {};
|
|
|
- if (saved_palette_init)
|
|
|
- {
|
|
|
- for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++)
|
|
|
- {
|
|
|
- ImGui::ColorConvertHSVtoRGB(n / 31.0f, 0.8f, 0.8f,
|
|
|
- saved_palette[n].x, saved_palette[n].y, saved_palette[n].z);
|
|
|
- saved_palette[n].w = 1.0f; // Alpha
|
|
|
- }
|
|
|
- saved_palette_init = false;
|
|
|
- }
|
|
|
-
|
|
|
- static ImVec4 backup_color;
|
|
|
- bool open_popup = ImGui::ColorButton("MyColor##3b", color, base_flags);
|
|
|
- ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x);
|
|
|
- open_popup |= ImGui::Button("Palette");
|
|
|
- if (open_popup)
|
|
|
- {
|
|
|
- ImGui::OpenPopup("mypicker");
|
|
|
- backup_color = color;
|
|
|
- }
|
|
|
- if (ImGui::BeginPopup("mypicker"))
|
|
|
- {
|
|
|
- ImGui::Text("MY CUSTOM COLOR PICKER WITH AN AMAZING PALETTE!");
|
|
|
- ImGui::Separator();
|
|
|
- ImGui::ColorPicker4("##picker", (float*)&color, base_flags | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview);
|
|
|
- ImGui::SameLine();
|
|
|
-
|
|
|
- ImGui::BeginGroup(); // Lock X position
|
|
|
- ImGui::Text("Current");
|
|
|
- ImGui::ColorButton("##current", color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60, 40));
|
|
|
- ImGui::Text("Previous");
|
|
|
- if (ImGui::ColorButton("##previous", backup_color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60, 40)))
|
|
|
- color = backup_color;
|
|
|
- ImGui::Separator();
|
|
|
- ImGui::Text("Palette");
|
|
|
- for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++)
|
|
|
- {
|
|
|
- ImGui::PushID(n);
|
|
|
- if ((n % 8) != 0)
|
|
|
- ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
|
|
|
-
|
|
|
- ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip;
|
|
|
- if (ImGui::ColorButton("##palette", saved_palette[n], palette_button_flags, ImVec2(20, 20)))
|
|
|
- color = ImVec4(saved_palette[n].x, saved_palette[n].y, saved_palette[n].z, color.w); // Preserve alpha!
|
|
|
-
|
|
|
- // Allow user to drop colors into each palette entry. Note that ColorButton() is already a
|
|
|
- // drag source by default, unless specifying the ImGuiColorEditFlags_NoDragDrop flag.
|
|
|
- if (ImGui::BeginDragDropTarget())
|
|
|
- {
|
|
|
- if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
|
|
|
- memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 3);
|
|
|
- if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
|
|
|
- memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 4);
|
|
|
- ImGui::EndDragDropTarget();
|
|
|
- }
|
|
|
-
|
|
|
- ImGui::PopID();
|
|
|
- }
|
|
|
- ImGui::EndGroup();
|
|
|
- ImGui::EndPopup();
|
|
|
- }
|
|
|
-
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (simple)");
|
|
|
- ImGui::Text("Color button only:");
|
|
|
- static bool no_border = false;
|
|
|
- ImGui::Checkbox("ImGuiColorEditFlags_NoBorder", &no_border);
|
|
|
- ImGui::ColorButton("MyColor##3c", *(ImVec4*)&color, base_flags | (no_border ? ImGuiColorEditFlags_NoBorder : 0), ImVec2(80, 80));
|
|
|
-
|
|
|
- IMGUI_DEMO_MARKER("Widgets/Color/ColorPicker");
|
|
|
- ImGui::SeparatorText("Color picker");
|
|
|
-
|
|
|
- static bool ref_color = false;
|
|
|
- static ImVec4 ref_color_v(1.0f, 0.0f, 1.0f, 0.5f);
|
|
|
- static int picker_mode = 0;
|
|
|
- static int display_mode = 0;
|
|
|
- static ImGuiColorEditFlags color_picker_flags = ImGuiColorEditFlags_AlphaBar;
|
|
|
-
|
|
|
- ImGui::PushID("Color picker");
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_NoAlpha", &color_picker_flags, ImGuiColorEditFlags_NoAlpha);
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaBar", &color_picker_flags, ImGuiColorEditFlags_AlphaBar);
|
|
|
- ImGui::CheckboxFlags("ImGuiColorEditFlags_NoSidePreview", &color_picker_flags, ImGuiColorEditFlags_NoSidePreview);
|
|
|
- if (color_picker_flags & ImGuiColorEditFlags_NoSidePreview)
|
|
|
- {
|
|
|
- ImGui::SameLine();
|
|
|
- ImGui::Checkbox("With Ref Color", &ref_color);
|
|
|
- if (ref_color)
|
|
|
- {
|
|
|
- ImGui::SameLine();
|
|
|
- ImGui::ColorEdit4("##RefColor", &ref_color_v.x, ImGuiColorEditFlags_NoInputs | base_flags);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ImGui::Combo("Picker Mode", &picker_mode, "Auto/Current\0ImGuiColorEditFlags_PickerHueBar\0ImGuiColorEditFlags_PickerHueWheel\0");
|
|
|
- ImGui::SameLine(); HelpMarker("When not specified explicitly, user can right-click the picker to change mode.");
|
|
|
-
|
|
|
- ImGui::Combo("Display Mode", &display_mode, "Auto/Current\0ImGuiColorEditFlags_NoInputs\0ImGuiColorEditFlags_DisplayRGB\0ImGuiColorEditFlags_DisplayHSV\0ImGuiColorEditFlags_DisplayHex\0");
|
|
|
- ImGui::SameLine(); HelpMarker(
|
|
|
- "ColorEdit defaults to displaying RGB inputs if you don't specify a display mode, "
|
|
|
- "but the user can change it with a right-click on those inputs.\n\nColorPicker defaults to displaying RGB+HSV+Hex "
|
|
|
- "if you don't specify a display mode.\n\nYou can change the defaults using SetColorEditOptions().");
|
|
|
-
|
|
|
- ImGuiColorEditFlags flags = base_flags | color_picker_flags;
|
|
|
- if (picker_mode == 1) flags |= ImGuiColorEditFlags_PickerHueBar;
|
|
|
- if (picker_mode == 2) flags |= ImGuiColorEditFlags_PickerHueWheel;
|
|
|
- if (display_mode == 1) flags |= ImGuiColorEditFlags_NoInputs; // Disable all RGB/HSV/Hex displays
|
|
|
- if (display_mode == 2) flags |= ImGuiColorEditFlags_DisplayRGB; // Override display mode
|
|
|
- if (display_mode == 3) flags |= ImGuiColorEditFlags_DisplayHSV;
|
|
|
- if (display_mode == 4) flags |= ImGuiColorEditFlags_DisplayHex;
|
|
|
- ImGui::ColorPicker4("MyColor##4", (float*)&color, flags, ref_color ? &ref_color_v.x : NULL);
|
|
|
-
|
|
|
- ImGui::Text("Set defaults in code:");
|
|
|
- ImGui::SameLine(); HelpMarker(
|
|
|
- "SetColorEditOptions() is designed to allow you to set boot-time default.\n"
|
|
|
- "We don't have Push/Pop functions because you can force options on a per-widget basis if needed, "
|
|
|
- "and the user can change non-forced ones with the options menu.\nWe don't have a getter to avoid "
|
|
|
- "encouraging you to persistently save values that aren't forward-compatible.");
|
|
|
- if (ImGui::Button("Default: Uint8 + HSV + Hue Bar"))
|
|
|
- ImGui::SetColorEditOptions(ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_PickerHueBar);
|
|
|
- if (ImGui::Button("Default: Float + HDR + Hue Wheel"))
|
|
|
- ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_PickerHueWheel);
|
|
|
-
|
|
|
- // Always display a small version of both types of pickers
|
|
|
- // (that's in order to make it more visible in the demo to people who are skimming quickly through it)
|
|
|
- ImGui::Text("Both types:");
|
|
|
- float w = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.y) * 0.40f;
|
|
|
- ImGui::SetNextItemWidth(w);
|
|
|
- ImGui::ColorPicker3("##MyColor##5", (float*)&color, ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha);
|
|
|
- ImGui::SameLine();
|
|
|
- ImGui::SetNextItemWidth(w);
|
|
|
- ImGui::ColorPicker3("##MyColor##6", (float*)&color, ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha);
|
|
|
- ImGui::PopID();
|
|
|
-
|
|
|
- // HSV encoded support (to avoid RGB<>HSV round trips and singularities when S==0 or V==0)
|
|
|
- static ImVec4 color_hsv(0.23f, 1.0f, 1.0f, 1.0f); // Stored as HSV!
|
|
|
- ImGui::Spacing();
|
|
|
- ImGui::Text("HSV encoded colors");
|
|
|
- ImGui::SameLine(); HelpMarker(
|
|
|
- "By default, colors are given to ColorEdit and ColorPicker in RGB, but ImGuiColorEditFlags_InputHSV "
|
|
|
- "allows you to store colors as HSV and pass them to ColorEdit and ColorPicker as HSV. This comes with the "
|
|
|
- "added benefit that you can manipulate hue values with the picker even when saturation or value are zero.");
|
|
|
- ImGui::Text("Color widget with InputHSV:");
|
|
|
- ImGui::ColorEdit4("HSV shown as RGB##1", (float*)&color_hsv, ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float);
|
|
|
- ImGui::ColorEdit4("HSV shown as HSV##1", (float*)&color_hsv, ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float);
|
|
|
- ImGui::DragFloat4("Raw HSV values", (float*)&color_hsv, 0.01f, 0.0f, 1.0f);
|
|
|
-
|
|
|
- ImGui::TreePop();
|
|
|
- }
|
|
|
-
|
|
|
IMGUI_DEMO_MARKER("Widgets/Drag and Slider Flags");
|
|
|
if (ImGui::TreeNode("Drag/Slider Flags"))
|
|
|
{
|
|
@@ -1814,6 +1623,202 @@ static void DemoWindowWidgetsCollapsingHeaders()
|
|
|
// [SECTION] DemoWindowWidgetsColorAndPickers()
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
+static void DemoWindowWidgetsColorAndPickers()
|
|
|
+{
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color");
|
|
|
+ if (ImGui::TreeNode("Color/Picker Widgets"))
|
|
|
+ {
|
|
|
+ static ImVec4 color = ImVec4(114.0f / 255.0f, 144.0f / 255.0f, 154.0f / 255.0f, 200.0f / 255.0f);
|
|
|
+ static ImGuiColorEditFlags base_flags = ImGuiColorEditFlags_None;
|
|
|
+
|
|
|
+ ImGui::SeparatorText("Options");
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_NoAlpha", &base_flags, ImGuiColorEditFlags_NoAlpha);
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaOpaque", &base_flags, ImGuiColorEditFlags_AlphaOpaque);
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaNoBg", &base_flags, ImGuiColorEditFlags_AlphaNoBg);
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaPreviewHalf", &base_flags, ImGuiColorEditFlags_AlphaPreviewHalf);
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_NoDragDrop", &base_flags, ImGuiColorEditFlags_NoDragDrop);
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_NoOptions", &base_flags, ImGuiColorEditFlags_NoOptions); ImGui::SameLine(); HelpMarker("Right-click on the individual color widget to show options.");
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_HDR", &base_flags, ImGuiColorEditFlags_HDR); ImGui::SameLine(); HelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets.");
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit");
|
|
|
+ ImGui::SeparatorText("Inline color editor");
|
|
|
+ ImGui::Text("Color widget:");
|
|
|
+ ImGui::SameLine(); HelpMarker(
|
|
|
+ "Click on the color square to open a color picker.\n"
|
|
|
+ "CTRL+click on individual component to input value.\n");
|
|
|
+ ImGui::ColorEdit3("MyColor##1", (float*)&color, base_flags);
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit (HSV, with Alpha)");
|
|
|
+ ImGui::Text("Color widget HSV with Alpha:");
|
|
|
+ ImGui::ColorEdit4("MyColor##2", (float*)&color, ImGuiColorEditFlags_DisplayHSV | base_flags);
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit (float display)");
|
|
|
+ ImGui::Text("Color widget with Float Display:");
|
|
|
+ ImGui::ColorEdit4("MyColor##2f", (float*)&color, ImGuiColorEditFlags_Float | base_flags);
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (with Picker)");
|
|
|
+ ImGui::Text("Color button with Picker:");
|
|
|
+ ImGui::SameLine(); HelpMarker(
|
|
|
+ "With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs.\n"
|
|
|
+ "With the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only "
|
|
|
+ "be used for the tooltip and picker popup.");
|
|
|
+ ImGui::ColorEdit4("MyColor##3", (float*)&color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | base_flags);
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (with custom Picker popup)");
|
|
|
+ ImGui::Text("Color button with Custom Picker Popup:");
|
|
|
+
|
|
|
+ // Generate a default palette. The palette will persist and can be edited.
|
|
|
+ static bool saved_palette_init = true;
|
|
|
+ static ImVec4 saved_palette[32] = {};
|
|
|
+ if (saved_palette_init)
|
|
|
+ {
|
|
|
+ for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++)
|
|
|
+ {
|
|
|
+ ImGui::ColorConvertHSVtoRGB(n / 31.0f, 0.8f, 0.8f,
|
|
|
+ saved_palette[n].x, saved_palette[n].y, saved_palette[n].z);
|
|
|
+ saved_palette[n].w = 1.0f; // Alpha
|
|
|
+ }
|
|
|
+ saved_palette_init = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ static ImVec4 backup_color;
|
|
|
+ bool open_popup = ImGui::ColorButton("MyColor##3b", color, base_flags);
|
|
|
+ ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x);
|
|
|
+ open_popup |= ImGui::Button("Palette");
|
|
|
+ if (open_popup)
|
|
|
+ {
|
|
|
+ ImGui::OpenPopup("mypicker");
|
|
|
+ backup_color = color;
|
|
|
+ }
|
|
|
+ if (ImGui::BeginPopup("mypicker"))
|
|
|
+ {
|
|
|
+ ImGui::Text("MY CUSTOM COLOR PICKER WITH AN AMAZING PALETTE!");
|
|
|
+ ImGui::Separator();
|
|
|
+ ImGui::ColorPicker4("##picker", (float*)&color, base_flags | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview);
|
|
|
+ ImGui::SameLine();
|
|
|
+
|
|
|
+ ImGui::BeginGroup(); // Lock X position
|
|
|
+ ImGui::Text("Current");
|
|
|
+ ImGui::ColorButton("##current", color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60, 40));
|
|
|
+ ImGui::Text("Previous");
|
|
|
+ if (ImGui::ColorButton("##previous", backup_color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60, 40)))
|
|
|
+ color = backup_color;
|
|
|
+ ImGui::Separator();
|
|
|
+ ImGui::Text("Palette");
|
|
|
+ for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++)
|
|
|
+ {
|
|
|
+ ImGui::PushID(n);
|
|
|
+ if ((n % 8) != 0)
|
|
|
+ ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
|
|
|
+
|
|
|
+ ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip;
|
|
|
+ if (ImGui::ColorButton("##palette", saved_palette[n], palette_button_flags, ImVec2(20, 20)))
|
|
|
+ color = ImVec4(saved_palette[n].x, saved_palette[n].y, saved_palette[n].z, color.w); // Preserve alpha!
|
|
|
+
|
|
|
+ // Allow user to drop colors into each palette entry. Note that ColorButton() is already a
|
|
|
+ // drag source by default, unless specifying the ImGuiColorEditFlags_NoDragDrop flag.
|
|
|
+ if (ImGui::BeginDragDropTarget())
|
|
|
+ {
|
|
|
+ if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
|
|
|
+ memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 3);
|
|
|
+ if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
|
|
|
+ memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 4);
|
|
|
+ ImGui::EndDragDropTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ ImGui::PopID();
|
|
|
+ }
|
|
|
+ ImGui::EndGroup();
|
|
|
+ ImGui::EndPopup();
|
|
|
+ }
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (simple)");
|
|
|
+ ImGui::Text("Color button only:");
|
|
|
+ static bool no_border = false;
|
|
|
+ ImGui::Checkbox("ImGuiColorEditFlags_NoBorder", &no_border);
|
|
|
+ ImGui::ColorButton("MyColor##3c", *(ImVec4*)&color, base_flags | (no_border ? ImGuiColorEditFlags_NoBorder : 0), ImVec2(80, 80));
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Widgets/Color/ColorPicker");
|
|
|
+ ImGui::SeparatorText("Color picker");
|
|
|
+
|
|
|
+ static bool ref_color = false;
|
|
|
+ static ImVec4 ref_color_v(1.0f, 0.0f, 1.0f, 0.5f);
|
|
|
+ static int picker_mode = 0;
|
|
|
+ static int display_mode = 0;
|
|
|
+ static ImGuiColorEditFlags color_picker_flags = ImGuiColorEditFlags_AlphaBar;
|
|
|
+
|
|
|
+ ImGui::PushID("Color picker");
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_NoAlpha", &color_picker_flags, ImGuiColorEditFlags_NoAlpha);
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaBar", &color_picker_flags, ImGuiColorEditFlags_AlphaBar);
|
|
|
+ ImGui::CheckboxFlags("ImGuiColorEditFlags_NoSidePreview", &color_picker_flags, ImGuiColorEditFlags_NoSidePreview);
|
|
|
+ if (color_picker_flags & ImGuiColorEditFlags_NoSidePreview)
|
|
|
+ {
|
|
|
+ ImGui::SameLine();
|
|
|
+ ImGui::Checkbox("With Ref Color", &ref_color);
|
|
|
+ if (ref_color)
|
|
|
+ {
|
|
|
+ ImGui::SameLine();
|
|
|
+ ImGui::ColorEdit4("##RefColor", &ref_color_v.x, ImGuiColorEditFlags_NoInputs | base_flags);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ImGui::Combo("Picker Mode", &picker_mode, "Auto/Current\0ImGuiColorEditFlags_PickerHueBar\0ImGuiColorEditFlags_PickerHueWheel\0");
|
|
|
+ ImGui::SameLine(); HelpMarker("When not specified explicitly, user can right-click the picker to change mode.");
|
|
|
+
|
|
|
+ ImGui::Combo("Display Mode", &display_mode, "Auto/Current\0ImGuiColorEditFlags_NoInputs\0ImGuiColorEditFlags_DisplayRGB\0ImGuiColorEditFlags_DisplayHSV\0ImGuiColorEditFlags_DisplayHex\0");
|
|
|
+ ImGui::SameLine(); HelpMarker(
|
|
|
+ "ColorEdit defaults to displaying RGB inputs if you don't specify a display mode, "
|
|
|
+ "but the user can change it with a right-click on those inputs.\n\nColorPicker defaults to displaying RGB+HSV+Hex "
|
|
|
+ "if you don't specify a display mode.\n\nYou can change the defaults using SetColorEditOptions().");
|
|
|
+
|
|
|
+ ImGuiColorEditFlags flags = base_flags | color_picker_flags;
|
|
|
+ if (picker_mode == 1) flags |= ImGuiColorEditFlags_PickerHueBar;
|
|
|
+ if (picker_mode == 2) flags |= ImGuiColorEditFlags_PickerHueWheel;
|
|
|
+ if (display_mode == 1) flags |= ImGuiColorEditFlags_NoInputs; // Disable all RGB/HSV/Hex displays
|
|
|
+ if (display_mode == 2) flags |= ImGuiColorEditFlags_DisplayRGB; // Override display mode
|
|
|
+ if (display_mode == 3) flags |= ImGuiColorEditFlags_DisplayHSV;
|
|
|
+ if (display_mode == 4) flags |= ImGuiColorEditFlags_DisplayHex;
|
|
|
+ ImGui::ColorPicker4("MyColor##4", (float*)&color, flags, ref_color ? &ref_color_v.x : NULL);
|
|
|
+
|
|
|
+ ImGui::Text("Set defaults in code:");
|
|
|
+ ImGui::SameLine(); HelpMarker(
|
|
|
+ "SetColorEditOptions() is designed to allow you to set boot-time default.\n"
|
|
|
+ "We don't have Push/Pop functions because you can force options on a per-widget basis if needed, "
|
|
|
+ "and the user can change non-forced ones with the options menu.\nWe don't have a getter to avoid "
|
|
|
+ "encouraging you to persistently save values that aren't forward-compatible.");
|
|
|
+ if (ImGui::Button("Default: Uint8 + HSV + Hue Bar"))
|
|
|
+ ImGui::SetColorEditOptions(ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_PickerHueBar);
|
|
|
+ if (ImGui::Button("Default: Float + HDR + Hue Wheel"))
|
|
|
+ ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_PickerHueWheel);
|
|
|
+
|
|
|
+ // Always display a small version of both types of pickers
|
|
|
+ // (that's in order to make it more visible in the demo to people who are skimming quickly through it)
|
|
|
+ ImGui::Text("Both types:");
|
|
|
+ float w = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.y) * 0.40f;
|
|
|
+ ImGui::SetNextItemWidth(w);
|
|
|
+ ImGui::ColorPicker3("##MyColor##5", (float*)&color, ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha);
|
|
|
+ ImGui::SameLine();
|
|
|
+ ImGui::SetNextItemWidth(w);
|
|
|
+ ImGui::ColorPicker3("##MyColor##6", (float*)&color, ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha);
|
|
|
+ ImGui::PopID();
|
|
|
+
|
|
|
+ // HSV encoded support (to avoid RGB<>HSV round trips and singularities when S==0 or V==0)
|
|
|
+ static ImVec4 color_hsv(0.23f, 1.0f, 1.0f, 1.0f); // Stored as HSV!
|
|
|
+ ImGui::Spacing();
|
|
|
+ ImGui::Text("HSV encoded colors");
|
|
|
+ ImGui::SameLine(); HelpMarker(
|
|
|
+ "By default, colors are given to ColorEdit and ColorPicker in RGB, but ImGuiColorEditFlags_InputHSV "
|
|
|
+ "allows you to store colors as HSV and pass them to ColorEdit and ColorPicker as HSV. This comes with the "
|
|
|
+ "added benefit that you can manipulate hue values with the picker even when saturation or value are zero.");
|
|
|
+ ImGui::Text("Color widget with InputHSV:");
|
|
|
+ ImGui::ColorEdit4("HSV shown as RGB##1", (float*)&color_hsv, ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float);
|
|
|
+ ImGui::ColorEdit4("HSV shown as HSV##1", (float*)&color_hsv, ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float);
|
|
|
+ ImGui::DragFloat4("Raw HSV values", (float*)&color_hsv, 0.01f, 0.0f, 1.0f);
|
|
|
+
|
|
|
+ ImGui::TreePop();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
// [SECTION] DemoWindowWidgetsComboBoxes()
|
|
|
//-----------------------------------------------------------------------------
|