mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-23 04:17:00 +00: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:
parent
cdcda9ff68
commit
973d4a361b
@ -9264,15 +9264,17 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
|||||||
Separator();
|
Separator();
|
||||||
}
|
}
|
||||||
float square_sz = ColorSquareSize();
|
float square_sz = ColorSquareSize();
|
||||||
ImGuiColorEditFlags picker_flags = (flags & (ImGuiColorEditFlags_NoAlpha|ImGuiColorEditFlags_AlphaBar|ImGuiColorEditFlags_Float)) | (ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_HSV | ImGuiColorEditFlags_HEX) | ImGuiColorEditFlags_NoLabel;
|
ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags_Float | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf;
|
||||||
|
ImGuiColorEditFlags picker_flags = (flags & picker_flags_to_forward) | (ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_HSV | ImGuiColorEditFlags_HEX) | ImGuiColorEditFlags_NoLabel;
|
||||||
PushItemWidth(square_sz * 12.0f);
|
PushItemWidth(square_sz * 12.0f);
|
||||||
value_changed |= ColorPicker4("##picker", col, picker_flags);
|
value_changed |= ColorPicker4("##picker", col, picker_flags);
|
||||||
PopItemWidth();
|
PopItemWidth();
|
||||||
EndPopup();
|
EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Context menu: display and store options. Don't apply to 'flags' this frame.
|
||||||
if (!(flags & ImGuiColorEditFlags_NoOptions) && BeginPopup("context"))
|
if (!(flags & ImGuiColorEditFlags_NoOptions) && BeginPopup("context"))
|
||||||
{
|
{
|
||||||
// Display and store options. Don't apply to 'flags' this frame.
|
|
||||||
ImGuiColorEditFlags new_flags = -1;
|
ImGuiColorEditFlags new_flags = -1;
|
||||||
if (RadioButton("RGB", (flags & ImGuiColorEditFlags_RGB)?1:0)) new_flags = (flags & ~ImGuiColorEditFlags_ModeMask_) | ImGuiColorEditFlags_RGB;
|
if (RadioButton("RGB", (flags & ImGuiColorEditFlags_RGB)?1:0)) new_flags = (flags & ~ImGuiColorEditFlags_ModeMask_) | ImGuiColorEditFlags_RGB;
|
||||||
if (RadioButton("HSV", (flags & ImGuiColorEditFlags_HSV)?1:0)) new_flags = (flags & ~ImGuiColorEditFlags_ModeMask_) | ImGuiColorEditFlags_HSV;
|
if (RadioButton("HSV", (flags & ImGuiColorEditFlags_HSV)?1:0)) new_flags = (flags & ~ImGuiColorEditFlags_ModeMask_) | ImGuiColorEditFlags_HSV;
|
||||||
@ -9407,7 +9409,8 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
|
|||||||
if ((flags & ImGuiColorEditFlags_ModeMask_) == 0)
|
if ((flags & ImGuiColorEditFlags_ModeMask_) == 0)
|
||||||
flags |= ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_HSV | ImGuiColorEditFlags_HEX;
|
flags |= ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_HSV | ImGuiColorEditFlags_HEX;
|
||||||
PushItemWidth((alpha_bar ? bar1_pos_x : bar0_pos_x) + bars_width - picker_pos.x);
|
PushItemWidth((alpha_bar ? bar1_pos_x : bar0_pos_x) + bars_width - picker_pos.x);
|
||||||
ImGuiColorEditFlags sub_flags = (flags & (ImGuiColorEditFlags_Float | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoColorSquare)) | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoOptions | ImGuiColorEditFlags_NoTooltip;
|
ImGuiColorEditFlags sub_flags_to_forward = ImGuiColorEditFlags_Float | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoColorSquare | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf;
|
||||||
|
ImGuiColorEditFlags sub_flags = (flags & sub_flags_to_forward) | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoOptions;
|
||||||
if (flags & ImGuiColorEditFlags_RGB)
|
if (flags & ImGuiColorEditFlags_RGB)
|
||||||
value_changed |= ColorEdit4("##rgb", col, sub_flags | ImGuiColorEditFlags_RGB);
|
value_changed |= ColorEdit4("##rgb", col, sub_flags | ImGuiColorEditFlags_RGB);
|
||||||
if (flags & ImGuiColorEditFlags_HSV)
|
if (flags & ImGuiColorEditFlags_HSV)
|
||||||
|
@ -666,36 +666,36 @@ void ImGui::ShowTestWindow(bool* p_open)
|
|||||||
static bool alpha_half_preview = false;
|
static bool alpha_half_preview = false;
|
||||||
ImGui::Checkbox("With Alpha Preview", &alpha_preview);
|
ImGui::Checkbox("With Alpha Preview", &alpha_preview);
|
||||||
ImGui::Checkbox("With Half Alpha Preview", &alpha_half_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::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::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::ColorEdit3("MyColor##1", (float*)&color, ImGuiColorEditFlags_HSV);
|
||||||
|
|
||||||
ImGui::Text("Color widget with Alpha:");
|
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::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::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::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::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:");
|
ImGui::Text("Color picker:");
|
||||||
static bool alpha = false;
|
static bool alpha = false;
|
||||||
static bool alpha_bar = false;
|
static bool alpha_bar = false;
|
||||||
static int inputs_mode = 0;
|
static int inputs_mode = 2;
|
||||||
static float width = 200.0f;
|
static float width = 200.0f;
|
||||||
ImGui::Checkbox("With Alpha", &alpha);
|
ImGui::Checkbox("With Alpha", &alpha);
|
||||||
ImGui::Checkbox("With Alpha Bar", &alpha_bar);
|
ImGui::Checkbox("With Alpha Bar", &alpha_bar);
|
||||||
ImGui::Combo("Mode", &inputs_mode, "All Inputs\0No Inputs\0RGB Input\0HSV Input\0HEX Input\0");
|
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::DragFloat("Width", &width, 1.0f, 1.0f, 999.0f);
|
||||||
ImGui::PushItemWidth(width);
|
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) flags |= ImGuiColorEditFlags_NoAlpha; // This is by default if you call ColorPicker3() instead of ColorPicker4()
|
||||||
if (alpha_bar) flags |= ImGuiColorEditFlags_AlphaBar;
|
if (alpha_bar) flags |= ImGuiColorEditFlags_AlphaBar;
|
||||||
if (inputs_mode == 1) flags |= ImGuiColorEditFlags_NoInputs;
|
if (inputs_mode == 1) flags |= ImGuiColorEditFlags_NoInputs;
|
||||||
|
Loading…
Reference in New Issue
Block a user