| 1098 | //----------------------------------------------------------------------------- |
| 1099 | |
| 1100 | static void DemoWindowWidgetsColorAndPickers() |
| 1101 | { |
| 1102 | if (ImGui::TreeNode("Color/Picker Widgets")) |
| 1103 | { |
| 1104 | IMGUI_DEMO_MARKER("Widgets/Color"); |
| 1105 | static ImVec4 color = ImVec4(114.0f / 255.0f, 144.0f / 255.0f, 154.0f / 255.0f, 200.0f / 255.0f); |
| 1106 | static ImGuiColorEditFlags base_flags = ImGuiColorEditFlags_None; |
| 1107 | |
| 1108 | ImGui::SeparatorText("Options"); |
| 1109 | ImGui::CheckboxFlags("ImGuiColorEditFlags_NoAlpha", &base_flags, ImGuiColorEditFlags_NoAlpha); |
| 1110 | ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaOpaque", &base_flags, ImGuiColorEditFlags_AlphaOpaque); |
| 1111 | ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaNoBg", &base_flags, ImGuiColorEditFlags_AlphaNoBg); |
| 1112 | ImGui::CheckboxFlags("ImGuiColorEditFlags_AlphaPreviewHalf", &base_flags, ImGuiColorEditFlags_AlphaPreviewHalf); |
| 1113 | ImGui::CheckboxFlags("ImGuiColorEditFlags_NoOptions", &base_flags, ImGuiColorEditFlags_NoOptions); ImGui::SameLine(); HelpMarker("Right-click on the individual color widget to show options."); |
| 1114 | ImGui::CheckboxFlags("ImGuiColorEditFlags_NoDragDrop", &base_flags, ImGuiColorEditFlags_NoDragDrop); |
| 1115 | ImGui::CheckboxFlags("ImGuiColorEditFlags_NoColorMarkers", &base_flags, ImGuiColorEditFlags_NoColorMarkers); |
| 1116 | 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."); |
| 1117 | |
| 1118 | IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit"); |
| 1119 | ImGui::SeparatorText("Inline color editor"); |
| 1120 | ImGui::Text("Color widget:"); |
| 1121 | ImGui::SameLine(); HelpMarker( |
| 1122 | "Click on the color square to open a color picker.\n" |
| 1123 | "Ctrl+Click on individual component to input value.\n"); |
| 1124 | ImGui::ColorEdit3("MyColor##1", (float*)&color, base_flags); |
| 1125 | |
| 1126 | IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit (HSV, with Alpha)"); |
| 1127 | ImGui::Text("Color widget HSV with Alpha:"); |
| 1128 | ImGui::ColorEdit4("MyColor##2", (float*)&color, ImGuiColorEditFlags_DisplayHSV | base_flags); |
| 1129 | |
| 1130 | IMGUI_DEMO_MARKER("Widgets/Color/ColorEdit (float display)"); |
| 1131 | ImGui::Text("Color widget with Float Display:"); |
| 1132 | ImGui::ColorEdit4("MyColor##2f", (float*)&color, ImGuiColorEditFlags_Float | base_flags); |
| 1133 | |
| 1134 | IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (with Picker)"); |
| 1135 | ImGui::Text("Color button with Picker:"); |
| 1136 | ImGui::SameLine(); HelpMarker( |
| 1137 | "With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs.\n" |
| 1138 | "With the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only " |
| 1139 | "be used for the tooltip and picker popup."); |
| 1140 | ImGui::ColorEdit4("MyColor##3", (float*)&color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | base_flags); |
| 1141 | |
| 1142 | IMGUI_DEMO_MARKER("Widgets/Color/ColorButton (with custom Picker popup)"); |
| 1143 | ImGui::Text("Color button with Custom Picker Popup:"); |
| 1144 | |
| 1145 | // Generate a default palette. The palette will persist and can be edited. |
| 1146 | static bool saved_palette_init = true; |
| 1147 | static ImVec4 saved_palette[32] = {}; |
| 1148 | if (saved_palette_init) |
| 1149 | { |
| 1150 | for (int n = 0; n < IM_COUNTOF(saved_palette); n++) |
| 1151 | { |
| 1152 | ImGui::ColorConvertHSVtoRGB(n / 31.0f, 0.8f, 0.8f, |
| 1153 | saved_palette[n].x, saved_palette[n].y, saved_palette[n].z); |
| 1154 | saved_palette[n].w = 1.0f; // Alpha |
| 1155 | } |
| 1156 | saved_palette_init = false; |
| 1157 | } |
no test coverage detected