More config options, menu bar and global getter for QuickApp.
This commit is contained in:
parent
7a18cce60c
commit
75773778e9
@ -20,6 +20,7 @@ namespace
|
||||
{
|
||||
constexpr int GL_COLOR_BUFFER_BIT = 0x00004000;
|
||||
const char* IMGUI_GLSL_VERSION = "#version 130";
|
||||
QuickApp* gAppInstance = nullptr;
|
||||
}
|
||||
|
||||
int Application::run(int argc, char** argv)
|
||||
@ -93,7 +94,7 @@ int Application::run(int argc, char** argv)
|
||||
ImGui::SetNextWindowPos({0, 0});
|
||||
ImGui::SetNextWindowSize(imguiIO.DisplaySize);
|
||||
|
||||
ImGui::Begin("##main", nullptr, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration);
|
||||
ImGui::Begin("##main", nullptr, mMainWindowFlags);
|
||||
render();
|
||||
ImGui::End();
|
||||
|
||||
@ -304,22 +305,31 @@ void Application::saveImGuiConfig()
|
||||
void QuickApp::init(QuickAppOptions options)
|
||||
{
|
||||
MIJIN_ASSERT_FATAL(options.callbacks.render, "Missing render callback.");
|
||||
mOptions = std::move(options);
|
||||
mRenderCallback = std::move(options.callbacks.render);
|
||||
mFolderName = std::move(options.folderName);
|
||||
setMainWindowFlags(options.mainWindowFlags);
|
||||
}
|
||||
|
||||
QuickApp& QuickApp::get()
|
||||
{
|
||||
MIJIN_ASSERT_FATAL(gAppInstance != nullptr, "No QuickApp is running.");
|
||||
return *gAppInstance;
|
||||
}
|
||||
|
||||
void QuickApp::render()
|
||||
{
|
||||
mOptions.callbacks.render();
|
||||
mRenderCallback();
|
||||
}
|
||||
|
||||
std::string QuickApp::getFolderName()
|
||||
{
|
||||
return mOptions.folderName;
|
||||
return mFolderName;
|
||||
}
|
||||
|
||||
int runQuick(int argc, char* argv[], QuickAppOptions options)
|
||||
{
|
||||
QuickApp app;
|
||||
gAppInstance = &app;
|
||||
app.init(std::move(options));
|
||||
return app.run(argc, argv);
|
||||
}
|
||||
|
@ -7,6 +7,18 @@ namespace
|
||||
{
|
||||
void render()
|
||||
{
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
{
|
||||
if (ImGui::MenuItem("Quit"))
|
||||
{
|
||||
raid::QuickApp::get().requestQuit();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
ImGui::Text("hi");
|
||||
|
||||
ImGui::Begin("Test");
|
||||
@ -20,6 +32,8 @@ int main(int argc, char* argv[])
|
||||
return raid::runQuick(argc, argv, {
|
||||
.callbacks = {
|
||||
.render = &render
|
||||
}
|
||||
},
|
||||
.folderName = "raid_test_app",
|
||||
.mainWindowFlags = raid::DEFAULT_MAIN_WINDOW_FLAGS | ImGuiWindowFlags_MenuBar
|
||||
});
|
||||
}
|
||||
|
@ -7,12 +7,18 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <fmt/format.h>
|
||||
#include <imgui.h>
|
||||
#include <mijin/virtual_filesystem/stacked.hpp>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
namespace raid
|
||||
{
|
||||
inline constexpr int ERR_INIT_FAILED = 100;
|
||||
inline constexpr ImGuiWindowFlags DEFAULT_MAIN_WINDOW_FLAGS = 0
|
||||
| ImGuiWindowFlags_NoBackground
|
||||
| ImGuiWindowFlags_NoDecoration
|
||||
| ImGuiWindowFlags_NoBringToFrontOnFocus
|
||||
| ImGuiWindowFlags_NoNav;
|
||||
|
||||
enum class MessageSeverity : unsigned char
|
||||
{
|
||||
@ -30,12 +36,14 @@ struct Message
|
||||
class Application
|
||||
{
|
||||
private:
|
||||
bool mRunning = true;
|
||||
SDL_Window* mWindow = nullptr;
|
||||
SDL_GLContext mGLContext = nullptr;
|
||||
|
||||
mijin::StackedFileSystemAdapter mFS;
|
||||
|
||||
bool mRunning = true;
|
||||
ImGuiWindowFlags mMainWindowFlags = DEFAULT_MAIN_WINDOW_FLAGS;
|
||||
|
||||
using glClear_fn_t = void (*)(std::uint32_t);
|
||||
using glClearColor_fn_t = void (*)(float, float, float, float);
|
||||
|
||||
@ -44,6 +52,13 @@ private:
|
||||
public:
|
||||
virtual ~Application() = default;
|
||||
|
||||
[[nodiscard]]
|
||||
ImGuiWindowFlags getMainWindowFlags() const { return mMainWindowFlags; }
|
||||
|
||||
void setMainWindowFlags(ImGuiWindowFlags flags) { mMainWindowFlags = flags; }
|
||||
|
||||
void requestQuit() { mRunning = false; }
|
||||
|
||||
[[nodiscard]]
|
||||
int run(int argc, char* argv[]);
|
||||
|
||||
@ -122,16 +137,20 @@ struct QuickAppOptions
|
||||
render_cb_t render;
|
||||
} callbacks;
|
||||
std::string folderName = "raid";
|
||||
ImGuiWindowFlags mainWindowFlags = DEFAULT_MAIN_WINDOW_FLAGS;
|
||||
};
|
||||
|
||||
class QuickApp : public Application
|
||||
{
|
||||
private:
|
||||
QuickAppOptions mOptions;
|
||||
render_cb_t mRenderCallback;
|
||||
std::string mFolderName;
|
||||
public:
|
||||
void init(QuickAppOptions options);
|
||||
void render() override;
|
||||
std::string getFolderName() override;
|
||||
|
||||
static QuickApp& get();
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user