MCPcopy Create free account
hub / github.com/cinder/Cinder / ColorEdit4

Method ColorEdit4

src/imgui/imgui_widgets.cpp:5688–5934  ·  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

5686// See enum ImGuiColorEditFlags_ for available options. e.g. Only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
5687// 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.
5688bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags)
5689{
5690 ImGuiWindow* window = GetCurrentWindow();
5691 if (window->SkipItems)
5692 return false;
5693
5694 ImGuiContext& g = *GImGui;
5695 const ImGuiStyle& style = g.Style;
5696 const float square_sz = GetFrameHeight();
5697 const char* label_display_end = FindRenderedTextEnd(label);
5698 float w_full = CalcItemWidth();
5699 g.NextItemData.ClearFlags();
5700
5701 BeginGroup();
5702 PushID(label);
5703 const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0);
5704 if (set_current_color_edit_id)
5705 g.ColorEditCurrentID = window->IDStack.back();
5706
5707 // If we're not showing any slider there's no point in doing any HSV conversions
5708 const ImGuiColorEditFlags flags_untouched = flags;
5709 if (flags & ImGuiColorEditFlags_NoInputs)
5710 flags = (flags & (~ImGuiColorEditFlags_DisplayMask_)) | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoOptions;
5711
5712 // Context menu: display and modify options (before defaults are applied)
5713 if (!(flags & ImGuiColorEditFlags_NoOptions))
5714 ColorEditOptionsPopup(col, flags);
5715
5716 // Read stored options
5717 if (!(flags & ImGuiColorEditFlags_DisplayMask_))
5718 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_DisplayMask_);
5719 if (!(flags & ImGuiColorEditFlags_DataTypeMask_))
5720 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_DataTypeMask_);
5721 if (!(flags & ImGuiColorEditFlags_PickerMask_))
5722 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_PickerMask_);
5723 if (!(flags & ImGuiColorEditFlags_InputMask_))
5724 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_InputMask_);
5725 flags |= (g.ColorEditOptions & ~(ImGuiColorEditFlags_DisplayMask_ | ImGuiColorEditFlags_DataTypeMask_ | ImGuiColorEditFlags_PickerMask_ | ImGuiColorEditFlags_InputMask_));
5726 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_DisplayMask_)); // Check that only 1 is selected
5727 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_InputMask_)); // Check that only 1 is selected
5728
5729 const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
5730 const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0;
5731 const int components = alpha ? 4 : 3;
5732 const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
5733 const float w_inputs = ImMax(w_full - w_button, 1.0f);
5734 w_full = w_inputs + w_button;
5735
5736 // Convert to the formats we need
5737 float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
5738 if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB))
5739 ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]);
5740 else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV))
5741 {
5742 // Hue is lost when converting from grayscale rgb (saturation=0). Restore it.
5743 ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]);
5744 ColorEditRestoreHS(col, &f[0], &f[1], &f[2]);
5745 }

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected