mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-26 13:37:00 +00:00
ColorEdit4: Store edit options per window. Demo: Letting user change edit mode. (#346)
This commit is contained in:
parent
c36d59a42a
commit
cdcda9ff68
14
imgui.cpp
14
imgui.cpp
@ -9141,7 +9141,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
|||||||
|
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
const ImGuiStyle& style = g.Style;
|
const ImGuiStyle& style = g.Style;
|
||||||
const ImGuiID id = window->GetID(label);
|
const ImGuiID storage_id = window->ID; // Store options on a per window basis
|
||||||
const float w_extra = (flags & ImGuiColorEditFlags_NoColorSquare) ? 0.0f : (ColorSquareSize() + style.ItemInnerSpacing.x);
|
const float w_extra = (flags & ImGuiColorEditFlags_NoColorSquare) ? 0.0f : (ColorSquareSize() + style.ItemInnerSpacing.x);
|
||||||
const float w_items_all = CalcItemWidth() - w_extra;
|
const float w_items_all = CalcItemWidth() - w_extra;
|
||||||
const char* label_display_end = FindRenderedTextEnd(label);
|
const char* label_display_end = FindRenderedTextEnd(label);
|
||||||
@ -9149,17 +9149,17 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
|||||||
const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
|
const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0;
|
||||||
const int components = alpha ? 4 : 3;
|
const int components = alpha ? 4 : 3;
|
||||||
|
|
||||||
// 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 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_NoInputs)
|
if (flags & ImGuiColorEditFlags_NoInputs)
|
||||||
flags = (flags & (~ImGuiColorEditFlags_ModeMask_)) | ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_NoOptions;
|
flags = (flags & (~ImGuiColorEditFlags_ModeMask_)) | ImGuiColorEditFlags_RGB | ImGuiColorEditFlags_NoOptions;
|
||||||
|
|
||||||
|
// If no mode is specified, defaults to RGB
|
||||||
|
if (!(flags & ImGuiColorEditFlags_ModeMask_))
|
||||||
|
flags |= ImGuiColorEditFlags_RGB;
|
||||||
|
|
||||||
// Read back edit mode from persistent storage, check that exactly one of RGB/HSV/HEX is set
|
// Read back edit mode from persistent storage, check that exactly one of RGB/HSV/HEX is set
|
||||||
if (!(flags & ImGuiColorEditFlags_NoOptions))
|
if (!(flags & ImGuiColorEditFlags_NoOptions))
|
||||||
flags = (flags & (~ImGuiColorEditFlags_StoredMask_)) | (g.ColorEditModeStorage.GetInt(id, (flags & ImGuiColorEditFlags_StoredMask_)) & ImGuiColorEditFlags_StoredMask_);
|
flags = (flags & (~ImGuiColorEditFlags_StoredMask_)) | (g.ColorEditModeStorage.GetInt(storage_id, (flags & ImGuiColorEditFlags_StoredMask_)) & ImGuiColorEditFlags_StoredMask_);
|
||||||
IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags_ModeMask_)));
|
IM_ASSERT(ImIsPowerOfTwo((int)(flags & ImGuiColorEditFlags_ModeMask_)));
|
||||||
|
|
||||||
float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
|
float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f };
|
||||||
@ -9281,7 +9281,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
|||||||
if (RadioButton("0..255", (flags & ImGuiColorEditFlags_Float)?0:1)) new_flags = (flags & ~ImGuiColorEditFlags_Float);
|
if (RadioButton("0..255", (flags & ImGuiColorEditFlags_Float)?0:1)) new_flags = (flags & ~ImGuiColorEditFlags_Float);
|
||||||
if (RadioButton("0.00..1.00", (flags & ImGuiColorEditFlags_Float)?1:0)) new_flags = (flags | ImGuiColorEditFlags_Float);
|
if (RadioButton("0.00..1.00", (flags & ImGuiColorEditFlags_Float)?1:0)) new_flags = (flags | ImGuiColorEditFlags_Float);
|
||||||
if (new_flags != -1)
|
if (new_flags != -1)
|
||||||
g.ColorEditModeStorage.SetInt(id, (int)(new_flags & ImGuiColorEditFlags_StoredMask_));
|
g.ColorEditModeStorage.SetInt(storage_id, (int)(new_flags & ImGuiColorEditFlags_StoredMask_));
|
||||||
EndPopup();
|
EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1752,19 +1752,15 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0"); ImGui::PopItemWidth();
|
ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0"); ImGui::PopItemWidth();
|
||||||
ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified);
|
ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified);
|
||||||
|
|
||||||
static ImGuiColorEditFlags color_flags = ImGuiColorEditFlags_RGB;
|
ImGui::Text("Tip: Left-click on colored square to open color picker,\nRight-click to open edit options menu.");
|
||||||
ImGui::RadioButton("RGB", &color_flags, ImGuiColorEditFlags_RGB); ImGui::SameLine();
|
|
||||||
ImGui::RadioButton("HSV", &color_flags, ImGuiColorEditFlags_HSV); ImGui::SameLine();
|
static ImGuiTextFilter filter;
|
||||||
ImGui::RadioButton("HEX", &color_flags, ImGuiColorEditFlags_HEX);
|
filter.Draw("Filter colors", 200);
|
||||||
//ImGui::Text("Tip: Click on colored square to change edit mode.");
|
|
||||||
|
|
||||||
static ImGuiColorEditFlags alpha_flags = 0;
|
static ImGuiColorEditFlags alpha_flags = 0;
|
||||||
ImGui::RadioButton("Opaque", &alpha_flags, 0); ImGui::SameLine();
|
ImGui::RadioButton("Opaque", &alpha_flags, 0); ImGui::SameLine();
|
||||||
ImGui::RadioButton("Alpha", &alpha_flags, ImGuiColorEditFlags_AlphaPreview); ImGui::SameLine();
|
ImGui::RadioButton("Alpha", &alpha_flags, ImGuiColorEditFlags_AlphaPreview); ImGui::SameLine();
|
||||||
ImGui::RadioButton("Half", &alpha_flags, ImGuiColorEditFlags_AlphaPreviewHalf);
|
ImGui::RadioButton("Both", &alpha_flags, ImGuiColorEditFlags_AlphaPreviewHalf);
|
||||||
|
|
||||||
static ImGuiTextFilter filter;
|
|
||||||
filter.Draw("Filter colors", 200);
|
|
||||||
|
|
||||||
ImGui::BeginChild("#colors", ImVec2(0, 300), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
ImGui::BeginChild("#colors", ImVec2(0, 300), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||||
ImGui::PushItemWidth(-160);
|
ImGui::PushItemWidth(-160);
|
||||||
@ -1774,7 +1770,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
if (!filter.PassFilter(name))
|
if (!filter.PassFilter(name))
|
||||||
continue;
|
continue;
|
||||||
ImGui::PushID(i);
|
ImGui::PushID(i);
|
||||||
ImGui::ColorEdit4(name, (float*)&style.Colors[i], color_flags | ImGuiColorEditFlags_NoOptions | ImGuiColorEditFlags_AlphaBar | alpha_flags);
|
ImGui::ColorEdit4(name, (float*)&style.Colors[i], ImGuiColorEditFlags_AlphaBar | alpha_flags);
|
||||||
if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &default_style.Colors[i]), sizeof(ImVec4)) != 0)
|
if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &default_style.Colors[i]), sizeof(ImVec4)) != 0)
|
||||||
{
|
{
|
||||||
ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : default_style.Colors[i];
|
ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : default_style.Colors[i];
|
||||||
|
Loading…
Reference in New Issue
Block a user