yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
zeml.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_ZEML_H
2#define YAZE_APP_GUI_ZEML_H
3
4#include "imgui/imgui.h"
5
6#include <cctype>
7#include <functional>
8#include <map>
9#include <memory>
10#include <string>
11#include <vector>
12
13namespace yaze {
14namespace app {
15namespace gui {
16
21namespace zeml {
22
26enum class TokenType {
28 String,
31 Comma,
33};
34
38struct Token {
40 std::string value;
41} typedef Token;
42
72
89 std::string id;
90 std::string title; // For Window, Button
91 std::string text; // For Text, Button
92 double min; // For Slider
93 double max; // For Slider
94 double value; // For Slidecar
95 float width; // For Columns
96 int count = 0; // For Columns
97 ImVec2 size = ImVec2(0, 0); // For BeginChild
98 bool* selected = nullptr; // For Selectable
99 std::shared_ptr<void> flags = nullptr; // For Various
100 void* data = nullptr; // For Various
101};
102
106enum class ActionType { Click, Change, Run };
107
111struct Action {
113 std::function<void()> callback;
114};
115
119std::vector<Token> Tokenize(const std::string& input);
120
125struct Node {
128 std::vector<Action> actions;
129 std::vector<Node> children;
130
131 Node* parent = nullptr;
132
133 Node* GetNode(const std::string& searchId) {
134 if (attributes.id == searchId) {
135 return this;
136 }
137 for (Node& child : children) {
138 Node* found = child.GetNode(searchId);
139 if (found != nullptr) {
140 return found;
141 }
142 }
143 return nullptr;
144 }
145};
146
150void Bind(Node* node, std::function<void()> callback);
151
155void BindAction(Node* node, ActionType type, std::function<void()> callback);
156
160void BindSelectable(Node* node, bool* selected, std::function<void()> callback);
161
165WidgetType MapType(const std::string& type);
166
170void ParseDefinitions(const std::vector<Token>& tokens, size_t& index,
171 std::map<std::string, Node>& definitions);
172
173void ParseFlags(const WidgetType& type, const std::string& flags,
174 WidgetAttributes& flags_ptr);
175
180 const std::vector<Token>& tokens, size_t& index, const WidgetType& type,
181 const std::map<std::string, void*>& data_bindings = {});
182
186Node ParseNode(const std::vector<Token>& tokens, size_t& index,
187 const std::map<std::string, void*>& data_bindings = {},
188 const std::map<std::string, Node>& definitions = {});
189
193Node Parse(const std::string& yazon_input,
194 const std::map<std::string, void*>& data_bindings = {});
195
199void Render(Node& node);
200
204void ExecuteActions(const std::vector<Action>& actions, ActionType type);
205
206std::string LoadFile(const std::string& filename);
207
208} // namespace zeml
209} // namespace gui
210} // namespace app
211} // namespace yaze
212
213#endif // YAZE_APP_GUI_YAZON_H_
WidgetAttributes ParseAttributes(const std::vector< Token > &tokens, size_t &index, const WidgetType &type, const std::map< std::string, void * > &data_bindings)
ParseNode attributes for a widget.
Definition zeml.cc:305
Node Parse(const std::string &yazon_input, const std::map< std::string, void * > &data_bindings)
Parse a zeml string.
Definition zeml.cc:360
void BindAction(Node *node, ActionType type, std::function< void()> callback)
Bind an action to a node.
Definition zeml.cc:574
void ExecuteActions(const std::vector< Action > &actions, ActionType type)
Execute actions for a node.
Definition zeml.cc:559
void ParseDefinitions(const std::vector< Token > &tokens, size_t &index, std::map< std::string, Node > &definitions)
Parse a zeml definition.
void Bind(Node *node, std::function< void()> callback)
Bind a callback to a node.
Definition zeml.cc:567
void BindSelectable(Node *node, bool *selected, std::function< void()> callback)
Bind a selectable node.
Definition zeml.cc:581
void Render(Node &node)
Render a zeml tree.
Definition zeml.cc:381
Node ParseNode(const std::vector< Token > &tokens, size_t &index, const std::map< std::string, void * > &data_bindings, const std::map< std::string, Node > &definitions)
Parse a zeml node.
Definition zeml.cc:87
std::string LoadFile(const std::string &filename)
Definition zeml.cc:590
WidgetType MapType(const std::string &type)
Map a string to a widget type.
Definition zeml.cc:57
void ParseFlags(const WidgetType &type, const std::string &flags, WidgetAttributes &attributes)
Definition zeml.cc:135
std::vector< Token > Tokenize(const std::string &input)
Tokenize a zeml string.
Definition zeml.cc:22
Definition common.cc:22
std::function< void()> callback
Definition zeml.h:113
Node for a zeml tree.
Definition zeml.h:125
Node * GetNode(const std::string &searchId)
Definition zeml.h:133
std::vector< Action > actions
Definition zeml.h:128
std::vector< Node > children
Definition zeml.h:129
WidgetAttributes attributes
Definition zeml.h:127
Attributes for a widget.
Definition zeml.h:88
std::shared_ptr< void > flags
Definition zeml.h:99