Added configuration helper types.
This commit is contained in:
@@ -5,6 +5,7 @@ src_files = Split("""
|
||||
main.cpp
|
||||
|
||||
application.cpp
|
||||
frames/config.cpp
|
||||
frames/data_table.cpp
|
||||
""")
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ bool Application::init()
|
||||
setMainWindowStyle(ImGuiStyleVar_WindowPadding, ImVec2());
|
||||
setMainWindowStyle(ImGuiStyleVar_WindowBorderSize, 0.f);
|
||||
std::ranges::fill(mFrameOpen, true);
|
||||
|
||||
if (const mijin::Result<> result = mConfig.init(getFS().getPath("/config/persistent.yml")); !result.isSuccess()) {
|
||||
msgError("Error initializing config: {}.", result.getError().message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,6 +30,10 @@ void Application::configureImgui()
|
||||
|
||||
void Application::render()
|
||||
{
|
||||
if (const mijin::Result<> result = mConfig.save(); !result.isSuccess()) {
|
||||
msgError("Error while saving config: {}.", result.getError().message);
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <array>
|
||||
#include "raid/raid.hpp"
|
||||
#include "./frames/config.hpp"
|
||||
#include "./frames/data_table.hpp"
|
||||
|
||||
namespace raid_test
|
||||
@@ -20,12 +21,17 @@ private:
|
||||
render_fn_t render;
|
||||
};
|
||||
static constexpr Frame FRAMES[] = {
|
||||
{.title = CONFIG_TITLE, .render = &renderConfig},
|
||||
{.title = DATA_TABLE_TITLE, .render = &renderDataTable}
|
||||
};
|
||||
static constexpr std::size_t NUM_FRAMES = sizeof(FRAMES) / sizeof(FRAMES[0]);
|
||||
|
||||
raid::FileConfig mConfig;
|
||||
bool mShowMetrics = false;
|
||||
std::array<bool, NUM_FRAMES> mFrameOpen{};
|
||||
public:
|
||||
[[nodiscard]]
|
||||
raid::FileConfig& getConfig() noexcept { return mConfig; }
|
||||
protected:
|
||||
bool init() override;
|
||||
void configureImgui() override;
|
||||
|
||||
26
private/raid_test/frames/config.cpp
Normal file
26
private/raid_test/frames/config.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
#include "raid_test/frames/config.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
#include "raid/config.hpp"
|
||||
#include "raid_test/application.hpp"
|
||||
|
||||
namespace raid_test
|
||||
{
|
||||
void renderConfig(bool& open)
|
||||
{
|
||||
if (!ImGui::Begin(CONFIG_TITLE, &open))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
static constexpr const char* TEST_BOOL_PATH = "test/section/bool";
|
||||
bool testBool = gApplication.getConfig().getValue(TEST_BOOL_PATH).asBool();
|
||||
if (ImGui::Checkbox("Test Bool", &testBool)) {
|
||||
gApplication.getConfig().setValue(TEST_BOOL_PATH, testBool);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
14
private/raid_test/frames/config.hpp
Normal file
14
private/raid_test/frames/config.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(RAID_TEST_FRAMES_CONFIG_HPP_INCLUDED)
|
||||
#define RAID_TEST_FRAMES_CONFIG_HPP_INCLUDED 1
|
||||
|
||||
namespace raid_test
|
||||
{
|
||||
inline constexpr const char* CONFIG_TITLE = "Config";
|
||||
|
||||
void renderConfig(bool& open);
|
||||
} // namespace raid_test
|
||||
|
||||
#endif // !defined(RAID_TEST_FRAMES_CONFIG_HPP_INCLUDED)
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#include "raid_test/frames/data_table.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
#include <imgui.h>
|
||||
|
||||
Reference in New Issue
Block a user