From 86833b6b6f2a599c5310f64e0f5a84aee4ede3a8 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Tue, 18 Jul 2023 18:44:19 -0700 Subject: [PATCH] Fix sizing bugs and add sizing to themes --- main.cpp | 16 +++++++++------- theme.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 75f44a4..30cc6e5 100644 --- a/main.cpp +++ b/main.cpp @@ -339,7 +339,7 @@ int main(int, char**) } ImGui::SameLine(); const int NEXT_SLIDER_COUNT = 1; - ImGui::SetNextItemWidth(-(ImGui::GetFontSize() * (1 + (8 * NEXT_SLIDER_COUNT))) - (ImGui::GetStyle().ItemSpacing.x * (NEXT_SLIDER_COUNT + 1)) - (ImGui::GetStyle().WindowPadding.x)); + ImGui::SetNextItemWidth(-(ImGui::GetFontSize() * (1 + (8 * NEXT_SLIDER_COUNT))) - ((ImGui::GetStyle().ItemSpacing.x + ImGui::GetStyle().FramePadding.x) * (NEXT_SLIDER_COUNT + 1))); uint8_t components = TimeToComponentCount(playback->GetLength()); string time_str = TimeToString(position, components); if (ImGui::SliderFloat("##Seek", &position, 0.0f, playback->GetLength(), time_str.c_str(), ImGuiSliderFlags_NoRoundToFormat)) @@ -353,7 +353,9 @@ int main(int, char**) if (ImGui::SliderFloat("##Volume", &playback->volume, 0.0, 100.0, ICON_FK_VOLUME_UP ": %.0f%%")) { playback->Update(); } - ImGui::PushItemWidth((ImGui::GetWindowWidth() / 3) - (ImGui::GetStyle().ItemSpacing.x) - (ImGui::GetStyle().WindowPadding.x / 3)); + const float items = 3.0f; + const float between_items = items - 1.0f; + ImGui::PushItemWidth((ImGui::GetWindowWidth() / items) - (ImGui::GetStyle().ItemSpacing.x / (items / between_items)) - ((ImGui::GetStyle().WindowPadding.x / items) * 2.0f)); if (ImGui::SliderFloat("##Speed", &playback->speed, 0.25, 4.0, "Speed: %.2fx", ImGuiSliderFlags_Logarithmic)) { playback->Update(); } @@ -394,12 +396,12 @@ int main(int, char**) ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x); ImGui::InputText("##FilterInput", filter, 1024); ImGui::Text("Select a theme..."); - ImVec2 ChildSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y); + ImVec2 ChildSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetFrameHeightWithSpacing()); if (ImGui::BeginChildFrame(ImGui::GetID("##ThemesContainer"), ChildSize)) { - ImVec2 TableSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y); - if (ImGui::BeginTable("##Themes", 2, 0, TableSize)) { + ImVec2 TableSize = ImVec2(0, 0); + if (ImGui::BeginTable("##Themes", 2, ImGuiTableFlags_SizingFixedFit|ImGuiTableFlags_NoSavedSettings|ImGuiTableFlags_ScrollY, TableSize)) { ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch); - ImGui::TableSetupColumn("Remove", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Remove", 0); for (auto themePath : Theme::availableThemes) { if (themePath.stem().string().starts_with(filter)) { ImGui::TableNextRow(); @@ -427,7 +429,7 @@ int main(int, char**) } } ImGui::EndChildFrame(); - ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().FramePadding.x * 4)); + ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2)); if (ImGui::SliderFloat("##AccentColor", &accent_color, 0.0, 360.0, "UI hue: %.0f°", ImGuiSliderFlags_NoRoundToFormat)) { theme->Apply(accent_color); } diff --git a/theme.cpp b/theme.cpp index 8efa545..1bcd427 100644 --- a/theme.cpp +++ b/theme.cpp @@ -127,6 +127,17 @@ bool Theme::ShowEditor(bool* open, Theme* &theme, ImGuiID dockid, int window_wid { if (ImGui::BeginTabItem("Sizes")) { + ImGui::SeparatorText("Sizing"); + ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("CellPadding", (float*)&style.CellPadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); + //ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); + //ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f, "%.0f"); + ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("SeparatorTextPadding", (float*)&style.SeparatorTextPadding, 0.0f, 40.0f, "%.0f"); ImGui::SeparatorText("Borders"); ImGui::SliderFloat("WindowBorderSize", &style.WindowBorderSize, 0.0f, 1.0f, "%.0f"); @@ -134,6 +145,7 @@ bool Theme::ShowEditor(bool* open, Theme* &theme, ImGuiID dockid, int window_wid ImGui::SliderFloat("PopupBorderSize", &style.PopupBorderSize, 0.0f, 1.0f, "%.0f"); ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f, "%.0f"); ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui::SliderFloat("SeparatorTextBorderSize", &style.SeparatorTextBorderSize, 0.0f, 10.0f, "%.0f"); ImGui::SeparatorText("Rounding"); ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f, "%.0f"); @@ -329,6 +341,22 @@ void Theme::Save(string path) { rounding["Tab"] = style.TabRounding; config["rounding"] = rounding; } + { + Json::Value sizing; + sizing["FrameX"] = style.FramePadding.x; + sizing["FrameY"] = style.FramePadding.y; + sizing["WindowX"] = style.WindowPadding.x; + sizing["WindowY"] = style.WindowPadding.y; + sizing["CellX"] = style.CellPadding.x; + sizing["CellY"] = style.CellPadding.y; + sizing["SeparatorTextX"] = style.SeparatorTextPadding.x; + sizing["SeparatorTextY"] = style.SeparatorTextPadding.y; + sizing["ItemSpacingX"] = style.ItemSpacing.x; + sizing["ItemSpacingY"] = style.ItemSpacing.y; + sizing["Scrollbar"] = style.ScrollbarSize; + sizing["Grab"] = style.GrabMinSize; + config["sizing"] = sizing; + } { Json::Value borders; borders["Frame"] = style.FrameBorderSize; @@ -336,6 +364,8 @@ void Theme::Save(string path) { borders["Child"] = style.ChildBorderSize; borders["Popup"] = style.PopupBorderSize; borders["Tab"] = style.TabBorderSize; + borders["Tab"] = style.TabBorderSize; + borders["SeparatorText"] = style.SeparatorTextBorderSize; config["borders"] = borders; } { @@ -415,6 +445,21 @@ Theme::Theme(string path) : Theme() { style.GrabRounding = rounding["Grab"].asFloat(); style.TabRounding = rounding["Tab"].asFloat(); } + if (config.isMember("sizing")) { + Json::Value sizing = config["sizing"]; + style.FramePadding.x = sizing["FrameX"].asFloat(); + style.FramePadding.y = sizing["FrameY"].asFloat(); + style.WindowPadding.x = sizing["WindowX"].asFloat(); + style.WindowPadding.y = sizing["WindowY"].asFloat(); + style.CellPadding.x = sizing["CellX"].asFloat(); + style.CellPadding.y = sizing["CellY"].asFloat(); + style.SeparatorTextPadding.x = sizing["SeparatorTextX"].asFloat(); + style.SeparatorTextPadding.y = sizing["SeparatorTextY"].asFloat(); + style.ItemSpacing.x = sizing["ItemSpacingX"].asFloat(); + style.ItemSpacing.y = sizing["ItemSpacingY"].asFloat(); + style.ScrollbarSize = sizing["Scrollbar"].asFloat(); + style.GrabMinSize = sizing["Grab"].asFloat(); + } if (config.isMember("borders")) { Json::Value borders = config["borders"]; style.FrameBorderSize = borders["Frame"].asFloat(); @@ -422,6 +467,9 @@ Theme::Theme(string path) : Theme() { style.ChildBorderSize = borders["Child"].asFloat(); style.PopupBorderSize = borders["Popup"].asFloat(); style.TabBorderSize = borders["Tab"].asFloat(); + if (borders.isMember("SeparatorText")) { + style.SeparatorTextBorderSize = borders["SeparatorText"].asFloat(); + } } if (config.isMember("colors")) { Json::Value colors = config["colors"];