mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
ColorPicker: Forward AlphaPreview flag to its individual inputs/sliders. Split code into extra lines to make logic more readable. (#346)
This commit is contained in:
@ -666,36 +666,36 @@ void ImGui::ShowTestWindow(bool* p_open)
|
||||
static bool alpha_half_preview = false;
|
||||
ImGui::Checkbox("With Alpha Preview", &alpha_preview);
|
||||
ImGui::Checkbox("With Half Alpha Preview", &alpha_half_preview);
|
||||
int alpha_flags = alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0);
|
||||
int alpha_previw_flags = alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0);
|
||||
|
||||
ImGui::Text("Color widget:");
|
||||
ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n");
|
||||
ImGui::ColorEdit3("MyColor##1", (float*)&color, ImGuiColorEditFlags_HSV);
|
||||
|
||||
ImGui::Text("Color widget with Alpha:");
|
||||
ImGui::ColorEdit4("MyColor##2", (float*)&color, alpha_flags);
|
||||
ImGui::ColorEdit4("MyColor##2", (float*)&color, alpha_previw_flags);
|
||||
|
||||
ImGui::Text("Color widget with Float Display:");
|
||||
ImGui::ColorEdit4("MyColor##2f", (float*)&color, ImGuiColorEditFlags_Float | alpha_flags);
|
||||
ImGui::ColorEdit4("MyColor##2f", (float*)&color, ImGuiColorEditFlags_Float | alpha_previw_flags);
|
||||
|
||||
ImGui::Text("Color button with Picker:");
|
||||
ImGui::SameLine(); ShowHelpMarker("With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs.\nWith the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only be used for the tooltip and picker popup.");
|
||||
ImGui::ColorEdit4("MyColor##3", (float*)&color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | alpha_flags);
|
||||
ImGui::ColorEdit4("MyColor##3", (float*)&color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | alpha_previw_flags);
|
||||
|
||||
ImGui::Text("Color button only:");
|
||||
ImGui::ColorButton("MyColor##3b", *(ImVec4*)&color, alpha_flags, ImVec2(80,80));
|
||||
ImGui::ColorButton("MyColor##3b", *(ImVec4*)&color, alpha_previw_flags, ImVec2(80,80));
|
||||
|
||||
ImGui::Text("Color picker:");
|
||||
static bool alpha = false;
|
||||
static bool alpha_bar = false;
|
||||
static int inputs_mode = 0;
|
||||
static int inputs_mode = 2;
|
||||
static float width = 200.0f;
|
||||
ImGui::Checkbox("With Alpha", &alpha);
|
||||
ImGui::Checkbox("With Alpha Bar", &alpha_bar);
|
||||
ImGui::Combo("Mode", &inputs_mode, "All Inputs\0No Inputs\0RGB Input\0HSV Input\0HEX Input\0");
|
||||
ImGui::DragFloat("Width", &width, 1.0f, 1.0f, 999.0f);
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGuiColorEditFlags flags = 0;
|
||||
ImGuiColorEditFlags flags = alpha_previw_flags;
|
||||
if (!alpha) flags |= ImGuiColorEditFlags_NoAlpha; // This is by default if you call ColorPicker3() instead of ColorPicker4()
|
||||
if (alpha_bar) flags |= ImGuiColorEditFlags_AlphaBar;
|
||||
if (inputs_mode == 1) flags |= ImGuiColorEditFlags_NoInputs;
|
||||
|
Reference in New Issue
Block a user