Make theme load/save as windows fill the window too
This commit is contained in:
parent
3894aa8537
commit
35077a3e58
1 changed files with 71 additions and 67 deletions
138
theme.cpp
138
theme.cpp
|
@ -205,90 +205,94 @@ bool Theme::ShowEditor(bool* open, Theme* &theme, ImGuiID dockid, int window_wid
|
||||||
}
|
}
|
||||||
if (loadOpen) {
|
if (loadOpen) {
|
||||||
ImGui::OpenPopup("Load...");
|
ImGui::OpenPopup("Load...");
|
||||||
}
|
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||||
if (ImGui::BeginPopupModal("Load...", &loadOpen)) {
|
ImGui::SetNextWindowSize(ImVec2(window_width, window_height));
|
||||||
static path selectedThemePath;
|
if (ImGui::BeginPopupModal("Load...", nullptr, ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize)) {
|
||||||
static char filter[1024] = {0};
|
static path selectedThemePath;
|
||||||
ImGui::Text("Filter:"); ImGui::SameLine();
|
static char filter[1024] = {0};
|
||||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
ImGui::Text("Filter:"); ImGui::SameLine();
|
||||||
ImGui::InputText("##FilterInput", filter, 1024);
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
||||||
ImGui::Text("Available themes...");
|
ImGui::InputText("##FilterInput", filter, 1024);
|
||||||
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
ImGui::Text("Available themes...");
|
||||||
for (auto themePath : Theme::availableThemes) {
|
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
||||||
if (themePath.stem().string().starts_with(filter)) {
|
for (auto themePath : Theme::availableThemes) {
|
||||||
const bool is_selected = themePath == selectedThemePath;
|
if (themePath.stem().string().starts_with(filter)) {
|
||||||
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected)) {
|
const bool is_selected = themePath == selectedThemePath;
|
||||||
selectedThemePath = themePath;
|
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected)) {
|
||||||
}
|
selectedThemePath = themePath;
|
||||||
if (is_selected) {
|
}
|
||||||
ImGui::SetItemDefaultFocus();
|
if (is_selected) {
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ImGui::EndListBox();
|
||||||
}
|
}
|
||||||
ImGui::EndListBox();
|
if (ImGui::Button("Load")) {
|
||||||
}
|
if (!selectedThemePath.empty()) {
|
||||||
if (ImGui::Button("Load")) {
|
filter[0] = '\0';
|
||||||
if (!selectedThemePath.empty()) {
|
loadOpen = false;
|
||||||
|
delete theme;
|
||||||
|
theme = new Theme(selectedThemePath);
|
||||||
|
selectedThemePath = path();
|
||||||
|
ImGui::EndPopup();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Cancel")) {
|
||||||
|
selectedThemePath = path();
|
||||||
filter[0] = '\0';
|
filter[0] = '\0';
|
||||||
loadOpen = false;
|
loadOpen = false;
|
||||||
delete theme;
|
|
||||||
theme = new Theme(selectedThemePath);
|
|
||||||
selectedThemePath = path();
|
|
||||||
ImGui::EndPopup();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("Cancel")) {
|
|
||||||
selectedThemePath = path();
|
|
||||||
filter[0] = '\0';
|
|
||||||
loadOpen = false;
|
|
||||||
}
|
|
||||||
ImGui::EndPopup();
|
|
||||||
}
|
}
|
||||||
if (saveAsOpen) {
|
if (saveAsOpen) {
|
||||||
ImGui::OpenPopup("Save as...");
|
ImGui::OpenPopup("Save as...");
|
||||||
}
|
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||||
if (ImGui::BeginPopupModal("Save as...", &saveAsOpen)) {
|
ImGui::SetNextWindowSize(ImVec2(window_width, window_height));
|
||||||
static char selectedThemeName[1024] = {0};
|
if (ImGui::BeginPopupModal("Save as...", nullptr, ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize)) {
|
||||||
static char filter[1024] = {0};
|
static char selectedThemeName[1024] = {0};
|
||||||
ImGui::Text("Filter:"); ImGui::SameLine();
|
static char filter[1024] = {0};
|
||||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
ImGui::Text("Filter:"); ImGui::SameLine();
|
||||||
ImGui::InputText("##FilterInput", filter, 1024);
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
||||||
ImGui::Text("Available themes...");
|
ImGui::InputText("##FilterInput", filter, 1024);
|
||||||
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetFrameHeightWithSpacing() - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
ImGui::Text("Available themes...");
|
||||||
for (auto themePath : Theme::availableThemes) {
|
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetFrameHeightWithSpacing() - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
||||||
if (themePath.stem().string().starts_with(filter)) {
|
for (auto themePath : Theme::availableThemes) {
|
||||||
const bool is_selected = strcmp(themePath.stem().generic_string().c_str(), selectedThemeName) == 0;
|
if (themePath.stem().string().starts_with(filter)) {
|
||||||
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected)) {
|
const bool is_selected = strcmp(themePath.stem().generic_string().c_str(), selectedThemeName) == 0;
|
||||||
strncpy(selectedThemeName, themePath.stem().generic_string().c_str(), 1024);
|
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected)) {
|
||||||
}
|
strncpy(selectedThemeName, themePath.stem().generic_string().c_str(), 1024);
|
||||||
if (is_selected) {
|
}
|
||||||
ImGui::SetItemDefaultFocus();
|
if (is_selected) {
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ImGui::EndListBox();
|
||||||
}
|
}
|
||||||
ImGui::EndListBox();
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f));
|
||||||
}
|
ImGui::InputText("Theme name: ", selectedThemeName, 1024);
|
||||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f));
|
if (ImGui::Button("Save")) {
|
||||||
ImGui::InputText("Theme name: ", selectedThemeName, 1024);
|
path selectedThemePath(selectedThemeName);
|
||||||
if (ImGui::Button("Save")) {
|
if (!selectedThemePath.empty() && !selectedThemePath.is_absolute()) {
|
||||||
path selectedThemePath(selectedThemeName);
|
selectedThemeName[0] = '\0'; // This empties the string by taking advantage of C strings.
|
||||||
if (!selectedThemePath.empty() && !selectedThemePath.is_absolute()) {
|
filter[0] = '\0';
|
||||||
selectedThemeName[0] = '\0'; // This empties the string by taking advantage of C strings.
|
saveAsOpen = false;
|
||||||
|
theme->Save(Theme::themeDir / selectedThemePath.replace_extension(".json"));
|
||||||
|
theme->file_path = selectedThemePath.generic_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Cancel")) {
|
||||||
|
selectedThemeName[0] = '\0'; // Same as above
|
||||||
filter[0] = '\0';
|
filter[0] = '\0';
|
||||||
saveAsOpen = false;
|
saveAsOpen = false;
|
||||||
theme->Save(Theme::themeDir / selectedThemePath.replace_extension(".json"));
|
|
||||||
theme->file_path = selectedThemePath.generic_string();
|
|
||||||
}
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("Cancel")) {
|
|
||||||
selectedThemeName[0] = '\0'; // Same as above
|
|
||||||
filter[0] = '\0';
|
|
||||||
saveAsOpen = false;
|
|
||||||
}
|
|
||||||
ImGui::EndPopup();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue