Edit colors components (each component in 0.0f..1.0f range). See enum ImGuiColorEditFlags_ for available options. e.g. Only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. With typical options: Left-click on color square to open color picker. Right-click to open option menu. CTRL-Click over input fields to edit them and TAB to go to next item.
| 4931 | // See enum ImGuiColorEditFlags_ for available options. e.g. Only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. |
| 4932 | // With typical options: Left-click on color square to open color picker. Right-click to open option menu. CTRL-Click over input fields to edit them and TAB to go to next item. |
| 4933 | bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags) |
| 4934 | { |
| 4935 | ImGuiWindow* window = GetCurrentWindow(); |
| 4936 | if (window->SkipItems) |
| 4937 | return false; |
| 4938 | |
| 4939 | ImGuiContext& g = *GImGui; |
| 4940 | const ImGuiStyle& style = g.Style; |
| 4941 | const float square_sz = GetFrameHeight(); |
| 4942 | const float w_full = CalcItemWidth(); |
| 4943 | const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x); |
| 4944 | const float w_inputs = w_full - w_button; |
| 4945 | const char* label_display_end = FindRenderedTextEnd(label); |
| 4946 | g.NextItemData.ClearFlags(); |
| 4947 | |
| 4948 | BeginGroup(); |
| 4949 | PushID(label); |
| 4950 | |
| 4951 | // If we're not showing any slider there's no point in doing any HSV conversions |
| 4952 | const ImGuiColorEditFlags flags_untouched = flags; |
| 4953 | if (flags & ImGuiColorEditFlags_NoInputs) |
| 4954 | flags = (flags & (~ImGuiColorEditFlags_DisplayMask_)) | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoOptions; |
| 4955 | |
| 4956 | // Context menu: display and modify options (before defaults are applied) |
| 4957 | if (!(flags & ImGuiColorEditFlags_NoOptions)) |
| 4958 | ColorEditOptionsPopup(col, flags); |
| 4959 | |
| 4960 | // Read stored options |
| 4961 | if (!(flags & ImGuiColorEditFlags_DisplayMask_)) |
| 4962 | flags |= (g.ColorEditOptions & ImGuiColorEditFlags_DisplayMask_); |
| 4963 | if (!(flags & ImGuiColorEditFlags_DataTypeMask_)) |
| 4964 | flags |= (g.ColorEditOptions & ImGuiColorEditFlags_DataTypeMask_); |
| 4965 | if (!(flags & ImGuiColorEditFlags_PickerMask_)) |
| 4966 | flags |= (g.ColorEditOptions & ImGuiColorEditFlags_PickerMask_); |
| 4967 | if (!(flags & ImGuiColorEditFlags_InputMask_)) |
| 4968 | flags |= (g.ColorEditOptions & ImGuiColorEditFlags_InputMask_); |
| 4969 | flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags_DisplayMask_ | ImGuiColorEditFlags_DataTypeMask_ | ImGuiColorEditFlags_PickerMask_ | ImGuiColorEditFlags_InputMask_)); |
| 4970 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_DisplayMask_)); // Check that only 1 is selected |
| 4971 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_InputMask_)); // Check that only 1 is selected |
| 4972 | |
| 4973 | const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0; |
| 4974 | const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0; |
| 4975 | const int components = alpha ? 4 : 3; |
| 4976 | |
| 4977 | // Convert to the formats we need |
| 4978 | float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f }; |
| 4979 | if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB)) |
| 4980 | ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); |
| 4981 | else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV)) |
| 4982 | { |
| 4983 | // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. |
| 4984 | ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); |
| 4985 | ColorEditRestoreHS(col, &f[0], &f[1], &f[2]); |
| 4986 | } |
| 4987 | int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) }; |
| 4988 | |
| 4989 | bool value_changed = false; |
| 4990 | bool value_changed_as_float = false; |
nothing calls this directly
no test coverage detected