Add a delete button to themes in the preferences and fix a bug with imported themes.

This commit is contained in:
Zachary Hall 2023-07-17 13:23:02 -07:00
parent 18bc56e510
commit 2200119f1f
2 changed files with 19 additions and 4 deletions

View file

@ -234,6 +234,8 @@ int main(int, char**)
Theme dark(true); Theme dark(true);
dark.Save(darkPath); dark.Save(darkPath);
} }
delete theme;
theme = new Theme(darkPath);
} }
} }
SDL_GL_SetSwapInterval(vsync ? 1 : 0); SDL_GL_SetSwapInterval(vsync ? 1 : 0);
@ -378,11 +380,16 @@ int main(int, char**)
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
ImGui::InputText("##FilterInput", filter, 1024); ImGui::InputText("##FilterInput", filter, 1024);
ImGui::Text("Select a theme..."); ImGui::Text("Select a theme...");
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) { ImVec2 ListBoxSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y);
if (ImGui::BeginTable("##Themes", 2, 0, ListBoxSize)) {
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Remove", ImGuiTableColumnFlags_WidthFixed);
for (auto themePath : Theme::availableThemes) { for (auto themePath : Theme::availableThemes) {
if (themePath.stem().string().starts_with(filter)) { if (themePath.stem().string().starts_with(filter)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
const bool is_selected = themePath == theme->file_path; const bool is_selected = themePath == theme->file_path;
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected)) { if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected, 0)) {
delete theme; delete theme;
theme = new Theme(themePath); theme = new Theme(themePath);
theme->Apply(accent_color); theme->Apply(accent_color);
@ -390,10 +397,18 @@ int main(int, char**)
} }
if (is_selected) { if (is_selected) {
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
} else {
ImGui::TableSetColumnIndex(1);
if (ImGui::SmallButton((string(ICON_FK_WINDOW_CLOSE "##") + themePath.stem().generic_string()).c_str())) {
printf("%s\n", themePath.c_str());
std::filesystem::remove(themePath);
Theme::updateAvailableThemes();
break;
}
} }
} }
} }
ImGui::EndListBox(); ImGui::EndTable();
} }
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().FramePadding.x * 4)); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().FramePadding.x * 4));
if (ImGui::SliderFloat("##AccentColor", &accent_color, 0.0, 360.0, "UI hue: %.0f°", ImGuiSliderFlags_NoRoundToFormat)) { if (ImGui::SliderFloat("##AccentColor", &accent_color, 0.0, 360.0, "UI hue: %.0f°", ImGuiSliderFlags_NoRoundToFormat)) {

View file

@ -186,7 +186,7 @@ bool Theme::ShowEditor(bool* open, Theme* &theme) {
path selected_path = importDialog.GetSelected(); path selected_path = importDialog.GetSelected();
path filename = selected_path.filename(); path filename = selected_path.filename();
copy_file(selected_path, theme->themeDir / filename); copy_file(selected_path, theme->themeDir / filename);
theme->availableThemes.insert(filename); Theme::updateAvailableThemes();
importDialog.ClearSelected(); importDialog.ClearSelected();
} }
if (exportDialog.HasSelected()) { if (exportDialog.HasSelected()) {