MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ColorEdit4

Method ColorEdit4

KBotExt/imgui/imgui_widgets.cpp:5100–5343  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

5098// See enum ImGuiColorEditFlags_ for available options. e.g. Only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
5099// 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.
5100bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags)
5101{
5102 ImGuiWindow* window = GetCurrentWindow();
5103 if (window->SkipItems)
5104 return false;
5105
5106 ImGuiContext& g = *GImGui;
5107 const ImGuiStyle& style = g.Style;
5108 const float square_sz = GetFrameHeight();
5109 const float w_full = CalcItemWidth();
5110 const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
5111 const float w_inputs = w_full - w_button;
5112 const char* label_display_end = FindRenderedTextEnd(label);
5113 g.NextItemData.ClearFlags();
5114
5115 BeginGroup();
5116 PushID(label);
5117 const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0);
5118 if (set_current_color_edit_id)
5119 g.ColorEditCurrentID = window->IDStack.back();
5120
5121 // If we're not showing any slider there's no point in doing any HSV conversions
5122 const ImGuiColorEditFlags flags_untouched = flags;
5123 if (flags & ImGuiColorEditFlags_NoInputs)
5124 flags = (flags & (~ImGuiColorEditFlags_DisplayMask_)) | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoOptions;
5125
5126 // Context menu: display and modify options (before defaults are applied)
5127 if (!(flags & ImGuiColorEditFlags_NoOptions))
5128 ColorEditOptionsPopup(col, flags);
5129
5130 // Read stored options
5131 if (!(flags & ImGuiColorEditFlags_DisplayMask_))
5132 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_DisplayMask_);
5133 if (!(flags & ImGuiColorEditFlags_DataTypeMask_))
5134 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_DataTypeMask_);
5135 if (!(flags & ImGuiColorEditFlags_PickerMask_))
5136 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_PickerMask_);
5137 if (!(flags & ImGuiColorEditFlags_InputMask_))
5138 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_InputMask_);
5139 flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags_DisplayMask_ | ImGuiColorEditFlags_DataTypeMask_ | ImGuiColorEditFlags_PickerMask_ | ImGuiColorEditFlags_InputMask_));
5140 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_DisplayMask_)); // Check that only 1 is selected
5141 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_InputMask_)); // Check that only 1 is selected
5142
5143 const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
5144 const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0;
5145 const int components = alpha ? 4 : 3;
5146
5147 // Convert to the formats we need
5148 float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
5149 if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB))
5150 ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
5151 else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV))
5152 {
5153 // Hue is lost when converting from grayscale rgb (saturation=0). Restore it.
5154 ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
5155 ColorEditRestoreHS(col, &f[0], &f[1], &f[2]);
5156 }
5157 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]) };

Callers

nothing calls this directly

Calls 10

GetCurrentWindowFunction · 0.85
ImIsPowerOfTwoFunction · 0.85
ColorEditRestoreHSFunction · 0.85
ImMaxFunction · 0.85
ImFormatStringFunction · 0.85
ImClampFunction · 0.85
ImCharIsBlankAFunction · 0.85
ImVec2Function · 0.85
ImVec4Class · 0.85
ClearFlagsMethod · 0.45

Tested by

no test coverage detected