mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-23 04:17:00 +00:00
ColorEdit4: support ImGuiColorEditFlags_NoSliders to display only a button (wip #346)
This commit is contained in:
parent
f8fede1d8b
commit
a43a9e602a
16
imgui.cpp
16
imgui.cpp
@ -8525,15 +8525,20 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
||||
const float w_full = CalcItemWidth();
|
||||
const float square_sz_with_spacing = (flags & ImGuiColorEditFlags_NoColorSquare) ? 0.0f : (g.FontSize + style.FramePadding.y * 2.0f + style.ItemInnerSpacing.x);
|
||||
|
||||
// If no mode is specified default to RGB
|
||||
// If no mode is specified, defaults to RGB
|
||||
if (!(flags & ImGuiColorEditFlags_ModeMask_))
|
||||
flags |= ImGuiColorEditFlags_RGB;
|
||||
|
||||
// If we're not showing any slider there's no point in querying color mode, nor showing the options menu, nor doing any HSV conversions
|
||||
if (flags & ImGuiColorEditFlags_NoSliders)
|
||||
flags = (flags & (~ImGuiColorEditFlags_ModeMask_)) | ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_NoOptions;
|
||||
|
||||
// Read back edit mode from persistent storage
|
||||
if (!(flags & ImGuiColorEditFlags_NoOptions))
|
||||
flags = (flags & (~ImGuiColorEditFlags_ModeMask_)) | (g.ColorEditModeStorage.GetInt(id, (flags & ImGuiColorEditFlags_ModeMask_)) & ImGuiColorEditFlags_ModeMask_);
|
||||
|
||||
IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags_ModeMask_))); // Check that exactly one of RGB/HSV/HEX is set
|
||||
// Check that exactly one of RGB/HSV/HEX is set
|
||||
IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags_ModeMask_))); //
|
||||
|
||||
float f[4] = { col[0], col[1], col[2], col[3] };
|
||||
if (flags & ImGuiColorEditFlags_HSV)
|
||||
@ -8548,7 +8553,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
||||
ImGui::BeginGroup();
|
||||
ImGui::PushID(label);
|
||||
|
||||
if (flags & (ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_HSV))
|
||||
if ((flags & (ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_HSV)) != 0 && (flags & ImGuiColorEditFlags_NoSliders) == 0)
|
||||
{
|
||||
// RGB/HSV 0..255 Sliders
|
||||
const float w_items_all = w_full - square_sz_with_spacing;
|
||||
@ -8577,7 +8582,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
else if (flags & ImGuiColorEditFlags_HEX)
|
||||
else if ((flags & ImGuiColorEditFlags_HEX) != 0 && (flags & ImGuiColorEditFlags_NoSliders) == 0)
|
||||
{
|
||||
// RGB Hexadecimal Input
|
||||
const float w_slider_all = w_full - square_sz_with_spacing;
|
||||
@ -8607,7 +8612,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
||||
bool picker_active = false;
|
||||
if (!(flags & ImGuiColorEditFlags_NoColorSquare))
|
||||
{
|
||||
ImGui::SameLine(0, style.ItemInnerSpacing.x);
|
||||
if (!(flags & ImGuiColorEditFlags_NoSliders))
|
||||
ImGui::SameLine(0, style.ItemInnerSpacing.x);
|
||||
|
||||
const ImVec4 col_display(col[0], col[1], col[2], 1.0f);
|
||||
if (ImGui::ColorButton(col_display))
|
||||
|
2
imgui.h
2
imgui.h
@ -620,7 +620,7 @@ enum ImGuiColorEditFlags_
|
||||
ImGuiColorEditFlags_NoPicker = 1 << 4, // ColorEdit: Disable picker when clicking on colored square
|
||||
ImGuiColorEditFlags_NoOptions = 1 << 5, // ColorEdit: Disable toggling options menu when right-clicking colored square
|
||||
ImGuiColorEditFlags_NoColorSquare = 1 << 6, // ColorEdit: Disable colored square
|
||||
ImGuiColorEditFlags_NoSliders = 1 << 7, // ColorPicker: Disable RGB/HSV/HEX sliders
|
||||
ImGuiColorEditFlags_NoSliders = 1 << 7, // ColorEdit: Disable sliders, show only a button. ColorPicker: Disable all RGB/HSV/HEX sliders.
|
||||
ImGuiColorEditFlags_ModeMask_ = ImGuiColorEditFlags_RGB|ImGuiColorEditFlags_HSV|ImGuiColorEditFlags_HEX
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user