Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
ui-parser.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4#include "tinyxml2.h"
5#include "ui-types.h"
6
7#include "flint/core/asset-loader.h"
8#include "flint/graphics/gpu/gpu-texture.h"
9#include "flint/graphics/types/color.h"
10
11#include <string>
12#include <vector>
13
14namespace Flint {
15
16 struct Property {
17 std::string name;
18 std::string value;
19 };
20
21 struct Node {
22 std::string name;
23 std::string id;
24 std::string type;
25 std::vector<Property> properties;
26 std::vector<Node> children;
27 std::string textContent;
28 bool textBeforeChildren = false;
29 };
30
31 struct Context {
32 std::string name;
33 Node rootNode;
34 };
35
36 class UIParser {
37 public:
38 bool loadFromFile(const std::string &mapData, IAssetLoader *assetsLoader);
39 const std::vector<Context> &getContexts() const;
40
41 static UILayoutDirection parseLayoutDirection(std::string alignString);
42
43 static UIAlign parseAlign(std::string alignString);
44
45 static UIPadding parsePadding(std::string value);
46
47 static Color parseColor(const std::string &value);
48
49 static bool parseBool(const std::string &value);
50
51 static bool parseFloat(const std::string &invalue, float &outValue);
52 static bool parseInt(const std::string &invalue, int &outValue);
53
54 private:
55 std::vector<Context> m_contexts;
56
57 Node parseNode(tinyxml2::XMLElement *nodeElement);
58
59 static Color parseRGBColor(const std::string &value);
60 static Color parseRGBAColor(const std::string &value);
61
62 std::string resolvePath(const std::string &basePath, const std::string &relativePath);
63
64 static constexpr std::pair<const char *, Color> preDefinedColors[] = {
65 { "white", Colors::white},
66 { "black", Colors::black},
67 { "red", Colors::red},
68 { "green", Colors::green},
69 { "blue", Colors::blue},
70 { "yellow", Colors::yellow},
71 { "cyan", Colors::cyan},
72 { "magenta", Colors::magenta},
73 {"transparent", Colors::transparent}
74 };
75 };
76}
Abstract interface for loading raw asset data by path.
RGBA color with 8-bit unsigned components.
Definition color.h:13
Defines the internal spacing boundaries (in pixels) for UI layout containers.
Definition ui-types.h:50