[nostalgia/studio] Make About modal and ProjectExplorer hide-able
This commit is contained in:
parent
a092c393a6
commit
4966aaffe4
@ -18,24 +18,23 @@ struct StudioConfig {
|
|||||||
static constexpr auto TypeVersion = 1;
|
static constexpr auto TypeVersion = 1;
|
||||||
ox::String projectPath;
|
ox::String projectPath;
|
||||||
ox::Vector<ox::String> openFiles;
|
ox::Vector<ox::String> openFiles;
|
||||||
|
bool showProjectExplorer = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
oxModelBegin(StudioConfig)
|
||||||
constexpr ox::Error model(T *h, StudioConfig *config) noexcept {
|
oxModelFieldRename(project_path, projectPath)
|
||||||
h->template setTypeInfo<StudioConfig>();
|
oxModelFieldRename(open_files, openFiles)
|
||||||
oxReturnError(h->field("project_path", &config->projectPath));
|
oxModelFieldRename(show_project_explorer, showProjectExplorer)
|
||||||
oxReturnError(h->field("open_files", &config->openFiles));
|
oxModelEnd()
|
||||||
return OxError(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
StudioUI::StudioUI(core::Context *ctx) noexcept {
|
StudioUI::StudioUI(core::Context *ctx) noexcept {
|
||||||
m_ctx = ctx;
|
m_ctx = ctx;
|
||||||
m_projectExplorer = new ProjectExplorer(m_ctx);
|
m_projectExplorer = new ProjectExplorer(m_ctx);
|
||||||
m_widgets.emplace_back(m_projectExplorer);
|
|
||||||
m_projectExplorer->fileChosen.connect(this, &StudioUI::openFile);
|
m_projectExplorer->fileChosen.connect(this, &StudioUI::openFile);
|
||||||
loadModules();
|
loadModules();
|
||||||
// open project and files
|
// open project and files
|
||||||
const auto [config, err] = studio::readConfig<StudioConfig>(ctx);
|
const auto [config, err] = studio::readConfig<StudioConfig>(ctx);
|
||||||
|
m_showProjectExplorer = config.showProjectExplorer;
|
||||||
if (!err) {
|
if (!err) {
|
||||||
oxIgnoreError(openProject(config.projectPath));
|
oxIgnoreError(openProject(config.projectPath));
|
||||||
for (const auto &f : config.openFiles) {
|
for (const auto &f : config.openFiles) {
|
||||||
@ -61,18 +60,16 @@ void StudioUI::draw() noexcept {
|
|||||||
drawMenu();
|
drawMenu();
|
||||||
drawToolbar();
|
drawToolbar();
|
||||||
drawTabBar();
|
drawTabBar();
|
||||||
|
if (m_showProjectExplorer) {
|
||||||
|
m_projectExplorer->draw(m_ctx);
|
||||||
|
}
|
||||||
for (auto &w : m_widgets) {
|
for (auto &w : m_widgets) {
|
||||||
w->draw(m_ctx);
|
w->draw(m_ctx);
|
||||||
}
|
}
|
||||||
constexpr auto aboutFlags = ImGuiWindowFlags_NoCollapse
|
if (m_aboutEnabled) {
|
||||||
| ImGuiWindowFlags_NoResize
|
ImGui::OpenPopup("About");
|
||||||
| ImGuiWindowFlags_Modal;
|
|
||||||
if (m_aboutEnabled &&
|
|
||||||
ImGui::Begin("About", &m_aboutEnabled, aboutFlags)) {
|
|
||||||
ImGui::SetWindowSize(ImVec2(400, 250));
|
|
||||||
ImGui::Text("Nostalgia Studio - dev build");
|
|
||||||
ImGui::End();
|
|
||||||
}
|
}
|
||||||
|
drawAboutPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StudioUI::drawMenu() noexcept {
|
void StudioUI::drawMenu() noexcept {
|
||||||
@ -108,7 +105,13 @@ void StudioUI::drawMenu() noexcept {
|
|||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
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();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
if (ImGui::BeginMenu("Help")) {
|
if (ImGui::BeginMenu("Help")) {
|
||||||
@ -151,8 +154,9 @@ void StudioUI::drawToolbar() noexcept {
|
|||||||
|
|
||||||
void StudioUI::drawTabBar() noexcept {
|
void StudioUI::drawTabBar() noexcept {
|
||||||
const auto viewport = ImGui::GetMainViewport();
|
const auto viewport = ImGui::GetMainViewport();
|
||||||
ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x + 316, viewport->Pos.y + 71));
|
const auto mod = m_showProjectExplorer ? 316.f : 0.f;
|
||||||
ImGui::SetNextWindowSize(ImVec2(viewport->Size.x - 316, viewport->Size.y - 71));
|
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
|
constexpr auto windowFlags = ImGuiWindowFlags_NoTitleBar
|
||||||
| ImGuiWindowFlags_NoResize
|
| ImGuiWindowFlags_NoResize
|
||||||
| ImGuiWindowFlags_NoMove
|
| 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 {
|
void StudioUI::loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept {
|
||||||
for (auto &ext : editorMaker.fileTypes) {
|
for (auto &ext : editorMaker.fileTypes) {
|
||||||
m_editorMakers[ext] = editorMaker.make;
|
m_editorMakers[ext] = editorMaker.make;
|
||||||
@ -244,6 +261,7 @@ ox::Error StudioUI::openFile(const ox::String &path) noexcept {
|
|||||||
editor->closed.connect(this, &StudioUI::closeFile);
|
editor->closed.connect(this, &StudioUI::closeFile);
|
||||||
m_editors.emplace_back(editor);
|
m_editors.emplace_back(editor);
|
||||||
} catch (const ox::Exception &ex) {
|
} catch (const ox::Exception &ex) {
|
||||||
|
oxErrorf("Could not open Editor: {} ({}:{})", ex.msg, ex.file, ex.line);
|
||||||
return ex.toError();
|
return ex.toError();
|
||||||
}
|
}
|
||||||
m_openFiles.emplace_back(path);
|
m_openFiles.emplace_back(path);
|
||||||
|
@ -32,6 +32,7 @@ class StudioUI: public ox::SignalHandler {
|
|||||||
studio::Editor *m_acitveEditor = nullptr;
|
studio::Editor *m_acitveEditor = nullptr;
|
||||||
bool m_saveEnabled = false;
|
bool m_saveEnabled = false;
|
||||||
bool m_aboutEnabled = false;
|
bool m_aboutEnabled = false;
|
||||||
|
bool m_showProjectExplorer = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StudioUI(core::Context *ctx) noexcept;
|
explicit StudioUI(core::Context *ctx) noexcept;
|
||||||
@ -54,6 +55,8 @@ class StudioUI: public ox::SignalHandler {
|
|||||||
|
|
||||||
void drawTabs() noexcept;
|
void drawTabs() noexcept;
|
||||||
|
|
||||||
|
void drawAboutPopup() noexcept;
|
||||||
|
|
||||||
void loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept;
|
void loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept;
|
||||||
|
|
||||||
void loadModule(studio::Module *module) noexcept;
|
void loadModule(studio::Module *module) noexcept;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user