save state

This commit is contained in:
2026-01-15 17:57:24 +01:00
parent 1f8f06de2a
commit 6ad11773dd
8 changed files with 320 additions and 58 deletions

View File

@@ -2,39 +2,44 @@
#include <thread>
#include <chrono>
#include <filesystem>
#include <iostream>
#include <RmlUi/Core.h>
#include <RmlUi/Debugger.h>
#include <RmlUi_Backend.h>
#include <RmlUi_Include_Windows.h>
void load_fonts()
void load_fonts(const std::filesystem::path& dir)
{
const Rml::String directory = "assets/";
struct FontFace {
const char* filename;
bool fallback_face;
};
FontFace font_faces[] = {
{"LatoLatin-Regular.ttf", false},
{"LatoLatin-Italic.ttf", false},
{"LatoLatin-Bold.ttf", false},
{"LatoLatin-BoldItalic.ttf", false},
{"NotoEmoji-Regular.ttf", true},
};
for (const FontFace& face : font_faces)
Rml::LoadFontFace(directory + face.filename, face.fallback_face);
for (const auto& file : std::filesystem::directory_iterator(dir))
{
if (file.path().extension() == ".ttf")
{
Rml::LoadFontFace(file.path().string());
}
}
}
int main()
int main(const int argc, const char* argv[])
{
const int window_width = 1024;
const int window_height = 768;
constexpr int window_width = 540;
constexpr int window_height = 960;
if (argc < 2)
{
std::println("Usage: mosis-designer file.rml");
return EXIT_FAILURE;
}
const std::filesystem::path file = argv[1];
if (!std::filesystem::exists(file))
{
std::println("File does not exist");
return EXIT_FAILURE;
}
if (!Backend::Initialize("Load Document Sample", window_width, window_height, true))
{
return -1;
return EXIT_FAILURE;
}
Rml::SetSystemInterface(Backend::GetSystemInterface());
@@ -46,21 +51,19 @@ int main()
{
Rml::Shutdown();
Backend::Shutdown();
return -1;
return EXIT_FAILURE;
}
load_fonts();
const std::filesystem::path assets_path = std::filesystem::absolute(file.parent_path());
load_fonts(assets_path);
Rml::ElementDocument* document = context->LoadDocument("assets/demo.rml");
Rml::ElementDocument* document = context->LoadDocument(file.string());
if (document)
{
document->Show();
}
const std::wstring assets_path = std::filesystem::absolute(
std::filesystem::current_path() / "assets").wstring();
HANDLE hNotif = FindFirstChangeNotification(assets_path.c_str(),
const HANDLE hNotif = FindFirstChangeNotification(assets_path.c_str(),
TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE);
bool running = true;
@@ -73,7 +76,7 @@ int main()
context->UnloadDocument(document);
context->Update();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
document = context->LoadDocument("assets/demo.rml");
document = context->LoadDocument(file.string());
if (document)
{
document->ReloadStyleSheet();