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) {
|
||||
ImGui::OpenPopup("Load...");
|
||||
}
|
||||
if (ImGui::BeginPopupModal("Load...", &loadOpen)) {
|
||||
static path selectedThemePath;
|
||||
static char filter[1024] = {0};
|
||||
ImGui::Text("Filter:"); ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
||||
ImGui::InputText("##FilterInput", filter, 1024);
|
||||
ImGui::Text("Available themes...");
|
||||
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
||||
for (auto themePath : Theme::availableThemes) {
|
||||
if (themePath.stem().string().starts_with(filter)) {
|
||||
const bool is_selected = themePath == selectedThemePath;
|
||||
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected)) {
|
||||
selectedThemePath = themePath;
|
||||
}
|
||||
if (is_selected) {
|
||||
ImGui::SetItemDefaultFocus();
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width, window_height));
|
||||
if (ImGui::BeginPopupModal("Load...", nullptr, ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize)) {
|
||||
static path selectedThemePath;
|
||||
static char filter[1024] = {0};
|
||||
ImGui::Text("Filter:"); ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
||||
ImGui::InputText("##FilterInput", filter, 1024);
|
||||
ImGui::Text("Available themes...");
|
||||
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
||||
for (auto themePath : Theme::availableThemes) {
|
||||
if (themePath.stem().string().starts_with(filter)) {
|
||||
const bool is_selected = themePath == selectedThemePath;
|
||||
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected)) {
|
||||
selectedThemePath = themePath;
|
||||
}
|
||||
if (is_selected) {
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
if (ImGui::Button("Load")) {
|
||||
if (!selectedThemePath.empty()) {
|
||||
if (ImGui::Button("Load")) {
|
||||
if (!selectedThemePath.empty()) {
|
||||
filter[0] = '\0';
|
||||
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';
|
||||
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) {
|
||||
ImGui::OpenPopup("Save as...");
|
||||
}
|
||||
if (ImGui::BeginPopupModal("Save as...", &saveAsOpen)) {
|
||||
static char selectedThemeName[1024] = {0};
|
||||
static char filter[1024] = {0};
|
||||
ImGui::Text("Filter:"); ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
||||
ImGui::InputText("##FilterInput", filter, 1024);
|
||||
ImGui::Text("Available themes...");
|
||||
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetFrameHeightWithSpacing() - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
||||
for (auto themePath : Theme::availableThemes) {
|
||||
if (themePath.stem().string().starts_with(filter)) {
|
||||
const bool is_selected = strcmp(themePath.stem().generic_string().c_str(), selectedThemeName) == 0;
|
||||
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();
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width, window_height));
|
||||
if (ImGui::BeginPopupModal("Save as...", nullptr, ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize)) {
|
||||
static char selectedThemeName[1024] = {0};
|
||||
static char filter[1024] = {0};
|
||||
ImGui::Text("Filter:"); ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
||||
ImGui::InputText("##FilterInput", filter, 1024);
|
||||
ImGui::Text("Available themes...");
|
||||
if (ImGui::BeginListBox("##Themes", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetFrameHeightWithSpacing() - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y))) {
|
||||
for (auto themePath : Theme::availableThemes) {
|
||||
if (themePath.stem().string().starts_with(filter)) {
|
||||
const bool is_selected = strcmp(themePath.stem().generic_string().c_str(), selectedThemeName) == 0;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f));
|
||||
ImGui::InputText("Theme name: ", selectedThemeName, 1024);
|
||||
if (ImGui::Button("Save")) {
|
||||
path selectedThemePath(selectedThemeName);
|
||||
if (!selectedThemePath.empty() && !selectedThemePath.is_absolute()) {
|
||||
selectedThemeName[0] = '\0'; // This empties the string by taking advantage of C strings.
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f));
|
||||
ImGui::InputText("Theme name: ", selectedThemeName, 1024);
|
||||
if (ImGui::Button("Save")) {
|
||||
path selectedThemePath(selectedThemeName);
|
||||
if (!selectedThemePath.empty() && !selectedThemePath.is_absolute()) {
|
||||
selectedThemeName[0] = '\0'; // This empties the string by taking advantage of C strings.
|
||||
filter[0] = '\0';
|
||||
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';
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue