Toast Engine
Loading...
Searching...
No Matches
ui_file_interface.hpp
Go to the documentation of this file.
1
8
9#pragma once
10#include <RmlUi/Core/FileInterface.h>
11#include <cstdint>
12#include <functional>
13#include <optional>
14#include <string>
15#include <string_view>
16#include <unordered_map>
17#include <vector>
18
19namespace ui {
20
27class UIFileInterface final : public Rml::FileInterface {
28public:
29 using ColorResolver = std::function<std::optional<std::string>(std::string_view)>;
30
31 explicit UIFileInterface(ColorResolver color_resolver);
32
33 auto Open(const Rml::String& path) -> Rml::FileHandle override;
34 void Close(Rml::FileHandle file) override;
35
36 auto Read(void* buffer, size_t size, Rml::FileHandle file) -> size_t override;
37 auto Seek(Rml::FileHandle file, long offset, int origin) -> bool override;
38 auto Tell(Rml::FileHandle file) -> size_t override;
39 auto Length(Rml::FileHandle file) -> size_t override;
40
41private:
42 struct OpenFile {
43 std::vector<uint8_t> data;
44 size_t cursor = 0;
45 };
46
47 Rml::FileHandle m_next_handle = 1;
48 std::unordered_map<Rml::FileHandle, OpenFile> m_open_files;
49 ColorResolver m_color_resolver;
50};
51
52}