mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 20:07:01 +00:00
Style Editor: Using local storage so Save/Revert button made some more sense without code passing its storage. Tweaked layout, added horizontal scroll bar, Fixed Save/Revert button to be always accessible. (fix #1211)
This commit is contained in:
parent
c1b5eab868
commit
1c41603b31
@ -1851,30 +1851,41 @@ void ImGui::ShowTestWindow(bool* p_open)
|
|||||||
|
|
||||||
void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||||
{
|
{
|
||||||
|
// You can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it compares to an internally stored reference)
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.55f);
|
static ImGuiStyle ref_saved_style;
|
||||||
|
|
||||||
// Style selector
|
// Default to using internal storage as reference
|
||||||
|
static bool init = true;
|
||||||
|
if (init && ref == NULL)
|
||||||
|
ref_saved_style = style;
|
||||||
|
init = false;
|
||||||
|
if (ref == NULL)
|
||||||
|
ref = &ref_saved_style;
|
||||||
|
|
||||||
|
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f);
|
||||||
|
|
||||||
|
// Default Styles Selector
|
||||||
static int style_idx = 0;
|
static int style_idx = 0;
|
||||||
if (ImGui::Combo("Colors##Selector", &style_idx, "Classic\0Dark\0"))
|
if (ImGui::Combo("Colors##Selector", &style_idx, "Classic\0Dark\0"))
|
||||||
|
{
|
||||||
switch (style_idx)
|
switch (style_idx)
|
||||||
{
|
{
|
||||||
case 0: ImGui::StyleColorsClassic(); break;
|
case 0: ImGui::StyleColorsClassic(); break;
|
||||||
case 1: ImGui::StyleColorsDark(); break;
|
case 1: ImGui::StyleColorsDark(); break;
|
||||||
}
|
}
|
||||||
|
ref_saved_style = style;
|
||||||
// You can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it compares to the default style)
|
|
||||||
const ImGuiStyle default_style; // Default style
|
|
||||||
if (ImGui::Button("Revert Style"))
|
|
||||||
style = ref ? *ref : default_style;
|
|
||||||
|
|
||||||
if (ref)
|
|
||||||
{
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("Save Style"))
|
|
||||||
*ref = style;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save/Revert button
|
||||||
|
if (ImGui::Button("Save Ref"))
|
||||||
|
*ref = ref_saved_style = style;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Revert Ref"))
|
||||||
|
style = *ref;
|
||||||
|
ImGui::SameLine();
|
||||||
|
ShowHelpMarker("Save/Revert in local non-persistent storage. Default Colors definition are not affected. Use \"Export Colors\" below to save them somewhere.");
|
||||||
|
|
||||||
if (ImGui::TreeNode("Rendering"))
|
if (ImGui::TreeNode("Rendering"))
|
||||||
{
|
{
|
||||||
ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); ImGui::SameLine(); ShowHelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well.");
|
ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); ImGui::SameLine(); ShowHelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well.");
|
||||||
@ -1911,8 +1922,8 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
if (ImGui::TreeNode("Colors"))
|
if (ImGui::TreeNode("Colors"))
|
||||||
{
|
{
|
||||||
static int output_dest = 0;
|
static int output_dest = 0;
|
||||||
static bool output_only_modified = false;
|
static bool output_only_modified = true;
|
||||||
if (ImGui::Button("Copy Colors"))
|
if (ImGui::Button("Export Unsaved"))
|
||||||
{
|
{
|
||||||
if (output_dest == 0)
|
if (output_dest == 0)
|
||||||
ImGui::LogToClipboard();
|
ImGui::LogToClipboard();
|
||||||
@ -1923,13 +1934,13 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
{
|
{
|
||||||
const ImVec4& col = style.Colors[i];
|
const ImVec4& col = style.Colors[i];
|
||||||
const char* name = ImGui::GetStyleColorName(i);
|
const char* name = ImGui::GetStyleColorName(i);
|
||||||
if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &default_style.Colors[i]), sizeof(ImVec4)) != 0)
|
if (!output_only_modified || memcmp(&col, &ref->Colors[i], sizeof(ImVec4)) != 0)
|
||||||
ImGui::LogText("colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" IM_NEWLINE, name, 23-(int)strlen(name), "", col.x, col.y, col.z, col.w);
|
ImGui::LogText("colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" IM_NEWLINE, name, 23-(int)strlen(name), "", col.x, col.y, col.z, col.w);
|
||||||
}
|
}
|
||||||
ImGui::LogFinish();
|
ImGui::LogFinish();
|
||||||
}
|
}
|
||||||
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 Colors", &output_only_modified);
|
||||||
|
|
||||||
ImGui::Text("Tip: Left-click on colored square to open color picker,\nRight-click to open edit options menu.");
|
ImGui::Text("Tip: Left-click on colored square to open color picker,\nRight-click to open edit options menu.");
|
||||||
|
|
||||||
@ -1941,7 +1952,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
ImGui::RadioButton("Alpha", &alpha_flags, ImGuiColorEditFlags_AlphaPreview); ImGui::SameLine();
|
ImGui::RadioButton("Alpha", &alpha_flags, ImGuiColorEditFlags_AlphaPreview); ImGui::SameLine();
|
||||||
ImGui::RadioButton("Both", &alpha_flags, ImGuiColorEditFlags_AlphaPreviewHalf);
|
ImGui::RadioButton("Both", &alpha_flags, ImGuiColorEditFlags_AlphaPreviewHalf);
|
||||||
|
|
||||||
ImGui::BeginChild("#colors", ImVec2(0, 300), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
ImGui::BeginChild("#colors", ImVec2(0, 300), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar);
|
||||||
ImGui::PushItemWidth(-160);
|
ImGui::PushItemWidth(-160);
|
||||||
for (int i = 0; i < ImGuiCol_COUNT; i++)
|
for (int i = 0; i < ImGuiCol_COUNT; i++)
|
||||||
{
|
{
|
||||||
@ -1949,12 +1960,16 @@ 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], ImGuiColorEditFlags_AlphaBar | alpha_flags);
|
ImGui::ColorEdit4("##color", (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->Colors[i], sizeof(ImVec4)) != 0)
|
||||||
{
|
{
|
||||||
ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : default_style.Colors[i];
|
// Tips: in a real user application, you may want to merge and use an icon font into the main font, so instead of "Save"/"Revert" you'd use icons.
|
||||||
if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; }
|
// Read the FAQ and extra_fonts/README.txt about using icon fonts. It's really easy and super convenient!
|
||||||
|
ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i];
|
||||||
|
ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); if (ImGui::Button("Revert")) style.Colors[i] = ref->Colors[i];
|
||||||
}
|
}
|
||||||
|
ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
|
||||||
|
ImGui::TextUnformatted(name);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
|
Loading…
Reference in New Issue
Block a user