[nostalgia/studio] Make About modal and ProjectExplorer hide-able

This commit is contained in:
Gary Talent 2022-03-05 11:39:13 -06:00
parent a092c393a6
commit 4966aaffe4
2 changed files with 40 additions and 19 deletions

View File

@ -18,24 +18,23 @@ struct StudioConfig {
static constexpr auto TypeVersion = 1;
ox::String projectPath;
ox::Vector<ox::String> openFiles;
bool showProjectExplorer = true;
};
template<typename T>
constexpr ox::Error model(T *h, StudioConfig *config) noexcept {
h->template setTypeInfo<StudioConfig>();
oxReturnError(h->field("project_path", &config->projectPath));
oxReturnError(h->field("open_files", &config->openFiles));
return OxError(0);
}
oxModelBegin(StudioConfig)
oxModelFieldRename(project_path, projectPath)
oxModelFieldRename(open_files, openFiles)
oxModelFieldRename(show_project_explorer, showProjectExplorer)
oxModelEnd()
StudioUI::StudioUI(core::Context *ctx) noexcept {
m_ctx = ctx;
m_projectExplorer = new ProjectExplorer(m_ctx);
m_widgets.emplace_back(m_projectExplorer);
m_projectExplorer->fileChosen.connect(this, &StudioUI::openFile);
loadModules();
// open project and files
const auto [config, err] = studio::readConfig<StudioConfig>(ctx);
m_showProjectExplorer = config.showProjectExplorer;
if (!err) {
oxIgnoreError(openProject(config.projectPath));
for (const auto &f : config.openFiles) {
@ -61,18 +60,16 @@ void StudioUI::draw() noexcept {
drawMenu();
drawToolbar();
drawTabBar();
if (m_showProjectExplorer) {
m_projectExplorer->draw(m_ctx);
}
for (auto &w : m_widgets) {
w->draw(m_ctx);
}
constexpr auto aboutFlags = ImGuiWindowFlags_NoCollapse
| ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_Modal;
if (m_aboutEnabled &&
ImGui::Begin("About", &m_aboutEnabled, aboutFlags)) {
ImGui::SetWindowSize(ImVec2(400, 250));
ImGui::Text("Nostalgia Studio - dev build");
ImGui::End();
if (m_aboutEnabled) {
ImGui::OpenPopup("About");
}
drawAboutPopup();
}
void StudioUI::drawMenu() noexcept {
@ -108,7 +105,13 @@ void StudioUI::drawMenu() noexcept {
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View", false)) {
if (ImGui::BeginMenu("View")) {
if (ImGui::MenuItem("Project Explorer", "Ctrl+1", m_showProjectExplorer)) {
m_showProjectExplorer = !m_showProjectExplorer;
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
config->showProjectExplorer = m_showProjectExplorer;
});
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help")) {
@ -151,8 +154,9 @@ void StudioUI::drawToolbar() noexcept {
void StudioUI::drawTabBar() noexcept {
const auto viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x + 316, viewport->Pos.y + 71));
ImGui::SetNextWindowSize(ImVec2(viewport->Size.x - 316, viewport->Size.y - 71));
const auto mod = m_showProjectExplorer ? 316.f : 0.f;
ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x + mod, viewport->Pos.y + 71));
ImGui::SetNextWindowSize(ImVec2(viewport->Size.x - mod, viewport->Size.y - 71));
constexpr auto windowFlags = ImGuiWindowFlags_NoTitleBar
| ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoMove
@ -191,6 +195,19 @@ void StudioUI::drawTabs() noexcept {
}
}
void StudioUI::drawAboutPopup() noexcept {
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal("About", &m_aboutEnabled, modalFlags)) {
ImGui::Text("Nostalgia Studio - dev build");
ImGui::SetNextWindowPos(ImVec2(0.5f, 0.5f), ImGuiCond_Always, ImVec2(0.5f,0.5f));
if (ImGui::Button("Close")) {
ImGui::CloseCurrentPopup();
m_aboutEnabled = false;
}
ImGui::EndPopup();
}
}
void StudioUI::loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept {
for (auto &ext : editorMaker.fileTypes) {
m_editorMakers[ext] = editorMaker.make;
@ -244,6 +261,7 @@ ox::Error StudioUI::openFile(const ox::String &path) noexcept {
editor->closed.connect(this, &StudioUI::closeFile);
m_editors.emplace_back(editor);
} catch (const ox::Exception &ex) {
oxErrorf("Could not open Editor: {} ({}:{})", ex.msg, ex.file, ex.line);
return ex.toError();
}
m_openFiles.emplace_back(path);

View File

@ -32,6 +32,7 @@ class StudioUI: public ox::SignalHandler {
studio::Editor *m_acitveEditor = nullptr;
bool m_saveEnabled = false;
bool m_aboutEnabled = false;
bool m_showProjectExplorer = true;
public:
explicit StudioUI(core::Context *ctx) noexcept;
@ -54,6 +55,8 @@ class StudioUI: public ox::SignalHandler {
void drawTabs() noexcept;
void drawAboutPopup() noexcept;
void loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept;
void loadModule(studio::Module *module) noexcept;