Improve accent color checkbox and defaults

This commit is contained in:
Zachary Hall 2023-07-11 10:18:51 -07:00
parent 9c6f69203d
commit b7beb49a50

View file

@ -14,6 +14,18 @@ using namespace std::numbers;
const char* Theme::prefPath = NULL; const char* Theme::prefPath = NULL;
path Theme::themeDir = path(); path Theme::themeDir = path();
std::set<path> Theme::availableThemes = std::set<path>(); std::set<path> Theme::availableThemes = std::set<path>();
ImVec4 change_accent_color(ImVec4 in, float hue) {
if (in.x == in.y && in.y == in.z) {
return in;
}
ImVec4 hsv = in;
ImVec4 out = in;
ImGui::ColorConvertRGBtoHSV(in.x, in.y, in.z, hsv.x, hsv.y, hsv.z);
hsv.x = hue / 360.0f;
ImGui::ColorConvertHSVtoRGB(hsv.x, hsv.y, hsv.z, out.x, out.y, out.z);
return out;
}
bool Theme::ShowEditor(bool* open, Theme* &theme) { bool Theme::ShowEditor(bool* open, Theme* &theme) {
static ImGui::FileBrowser importDialog; static ImGui::FileBrowser importDialog;
static ImGui::FileBrowser exportDialog; static ImGui::FileBrowser exportDialog;
@ -146,17 +158,18 @@ bool Theme::ShowEditor(bool* open, Theme* &theme) {
if (!filter.PassFilter(name)) if (!filter.PassFilter(name))
continue; continue;
ImGui::PushID(i); ImGui::PushID(i);
ImGui::ColorEdit4("##color", (float*)&style.Colors[i], ImGuiColorEditFlags_AlphaBar | alpha_flags | ImGuiColorEditFlags_DisplayHSV);
ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
ImGui::TextUnformatted(name);
bool hueEnabled = theme->HueEnabledColors.contains(i); bool hueEnabled = theme->HueEnabledColors.contains(i);
if (ImGui::Checkbox("Match accent color hue", &hueEnabled)) { if (ImGui::Checkbox("Accent", &hueEnabled)) {
if (hueEnabled) { if (hueEnabled) {
theme->HueEnabledColors.insert(i); theme->HueEnabledColors.insert(i);
} else { } else {
theme->HueEnabledColors.erase(i); theme->HueEnabledColors.erase(i);
} }
} }
ImGui::SameLine();
ImGui::ColorEdit4("##color", (float*)&style.Colors[i], ImGuiColorEditFlags_AlphaBar | alpha_flags | ImGuiColorEditFlags_DisplayHSV);
ImGui::SameLine(0.0f, style.ItemInnerSpacing.x);
ImGui::TextUnformatted(name);
ImGui::PopID(); ImGui::PopID();
} }
ImGui::PopItemWidth(); ImGui::PopItemWidth();
@ -269,17 +282,6 @@ bool Theme::ShowEditor(bool* open, Theme* &theme) {
} }
return false; return false;
} }
ImVec4 change_accent_color(ImVec4 in, float hue) {
if (in.x == in.y && in.y == in.z) {
return in;
}
ImVec4 hsv = in;
ImVec4 out = in;
ImGui::ColorConvertRGBtoHSV(in.x, in.y, in.z, hsv.x, hsv.y, hsv.z);
hsv.x = hue / 360.0f;
ImGui::ColorConvertHSVtoRGB(hsv.x, hsv.y, hsv.z, out.x, out.y, out.z);
return out;
}
void Theme::Apply(float hue) { void Theme::Apply(float hue) {
ImGuiStyle& actual_style = ImGui::GetStyle(); ImGuiStyle& actual_style = ImGui::GetStyle();
actual_style = style; actual_style = style;
@ -370,8 +372,11 @@ Theme::Theme(bool dark) : Theme() {
} }
for (int i = 0; i < ImGuiCol_COUNT; i++) for (int i = 0; i < ImGuiCol_COUNT; i++)
{ {
ImVec4 color = style.Colors[i];
if (color.x != color.y || color.y != color.z) {
HueEnabledColors.insert(i); HueEnabledColors.insert(i);
} }
}
style.FrameRounding = 12; style.FrameRounding = 12;
style.GrabRounding = 12; style.GrabRounding = 12;
style.WindowRounding = 12; style.WindowRounding = 12;