add System/ImGuiConfig

This commit is contained in:
falsycat 2022-05-25 16:10:46 +09:00
parent ad4752a1b3
commit 10602428e5
3 changed files with 70 additions and 0 deletions

View File

@ -51,6 +51,7 @@ target_sources(nf7
common/yas.hh
file/system_dir.cc
file/system_imgui_config.cc
file/system_logger.cc
)
target_link_libraries(nf7

View File

@ -0,0 +1,67 @@
#include <memory>
#include <string>
#include <string_view>
#include <typeinfo>
#include <utility>
#include <imgui.h>
#include <yas/serialize.hpp>
#include <yas/types/std/string.hpp>
#include <yas/types/std/string_view.hpp>
#include "nf7.hh"
#include "common/dir.hh"
#include "common/ptr_selector.hh"
#include "common/type_info.hh"
using namespace std::literals;
namespace nf7 {
namespace {
class ImGuiConfig final : public File, public nf7::DirItem {
public:
static inline const GenericTypeInfo<ImGuiConfig> kType = {"System/ImGuiConfig", {}};
ImGuiConfig(Env& env) noexcept :
File(kType, env), DirItem(DirItem::kMenu) {
}
ImGuiConfig(Env& env, Deserializer& ar) noexcept : ImGuiConfig(env) {
std::string buf;
ar(buf);
if (buf.empty()) return;
ImGui::LoadIniSettingsFromMemory(buf.data(), buf.size());
}
void Serialize(Serializer& ar) const noexcept override {
if (std::exchange(const_cast<bool&>(skip_save_), false)) {
ar(""s);
} else {
size_t n;
const char* ini = ImGui::SaveIniSettingsToMemory(&n);
ar(std::string_view(ini, n));
}
}
std::unique_ptr<File> Clone(Env& env) const noexcept override {
return std::make_unique<ImGuiConfig>(env);
}
void UpdateMenu() noexcept override;
File::Interface* interface(const std::type_info& t) noexcept override {
return InterfaceSelector<nf7::DirItem>(t).Select(this);
}
private:
bool skip_save_ = false;
};
void ImGuiConfig::UpdateMenu() noexcept {
ImGui::MenuItem("skip next serialization", nullptr, &skip_save_);
}
}
} // namespace nf7

View File

@ -42,6 +42,8 @@ int main(void) {
# define WINDOW_(shown) shown
ar("System/Dir"s, std::map<std::string, L> {
{ "_imgui"s,
Write(ar, "System/ImGuiConfig"s, ""s) },
{ "_logger"s,
Write(ar, "System/Logger"s, WINDOW_(true), 1024, false, false) },
{ "home"s,