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 <iostream>
9#include <map>
10#include <memory>
11#include <sstream>
12#include <string>
13#include <vector>
14
15namespace yaze {
16namespace app {
17namespace gui {
18
23namespace zeml {
24
28enum class TokenType {
30 String,
33 Comma,
35};
36
40struct Token {
42 std::string value;
43} typedef Token;
44
74
91 std::string id;
92 std::string title; // For Window, Button
93 std::string text; // For Text, Button
94 double min; // For Slider
95 double max; // For Slider
96 double value; // For Slidecar
97 float width; // For Columns
98 int count = 0; // For Columns
99 ImVec2 size = ImVec2(0, 0); // For BeginChild
100 bool* selected = nullptr; // For Selectable
101 std::shared_ptr<void> flags = nullptr; // For Various
102 void* data = nullptr; // For Various
103};
104
108enum class ActionType { Click, Change, Run };
109
113struct Action {
115 std::function<void()> callback;
116};
117
121std::vector<Token> Tokenize(const std::string& input);
122
127struct Node {
130 std::vector<Action> actions;
131 std::vector<Node> children;
132
133 Node* parent = nullptr;
134
135 Node* GetNode(const std::string& searchId) {
136 if (attributes.id == searchId) {
137 return this;
138 }
139 for (Node& child : children) {
140 Node* found = child.GetNode(searchId);
141 if (found != nullptr) {
142 return found;
143 }
144 }
145 return nullptr;
146 }
147};
148
152void Bind(Node* node, std::function<void()> callback);
153
157void BindAction(Node* node, ActionType type, std::function<void()> callback);
158
162void BindSelectable(Node* node, bool* selected, std::function<void()> callback);
163
167WidgetType MapType(const std::string& type);
168
172void ParseDefinitions(const std::vector<Token>& tokens, size_t& index,
173 std::map<std::string, Node>& definitions);
174
175void ParseFlags(const WidgetType& type, const std::string& flags,
176 WidgetAttributes& flags_ptr);
177
182 const std::vector<Token>& tokens, size_t& index, const WidgetType& type,
183 const std::map<std::string, void*>& data_bindings = {});
184
188Node ParseNode(const std::vector<Token>& tokens, size_t& index,
189 const std::map<std::string, void*>& data_bindings = {},
190 const std::map<std::string, Node>& definitions = {});
191
195Node Parse(const std::string& yazon_input,
196 const std::map<std::string, void*>& data_bindings = {});
197
201void Render(Node& node);
202
206void ExecuteActions(const std::vector<Action>& actions, ActionType type);
207
208std::string LoadFile(const std::string& filename);
209
210} // namespace zeml
211} // namespace gui
212} // namespace app
213} // namespace yaze
214
215#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:306
Node Parse(const std::string &yazon_input, const std::map< std::string, void * > &data_bindings)
Parse a zeml string.
Definition zeml.cc:361
void BindAction(Node *node, ActionType type, std::function< void()> callback)
Bind an action to a node.
Definition zeml.cc:575
void ExecuteActions(const std::vector< Action > &actions, ActionType type)
Execute actions for a node.
Definition zeml.cc:560
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:568
void BindSelectable(Node *node, bool *selected, std::function< void()> callback)
Bind a selectable node.
Definition zeml.cc:582
void Render(Node &node)
Render a zeml tree.
Definition zeml.cc:382
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:88
std::string LoadFile(const std::string &filename)
Definition zeml.cc:591
WidgetType MapType(const std::string &type)
Map a string to a widget type.
Definition zeml.cc:58
void ParseFlags(const WidgetType &type, const std::string &flags, WidgetAttributes &attributes)
Definition zeml.cc:136
std::vector< Token > Tokenize(const std::string &input)
Tokenize a zeml string.
Definition zeml.cc:23
Definition common.cc:21
std::function< void()> callback
Definition zeml.h:115
Node for a zeml tree.
Definition zeml.h:127
Node * GetNode(const std::string &searchId)
Definition zeml.h:135
std::vector< Action > actions
Definition zeml.h:130
std::vector< Node > children
Definition zeml.h:131
WidgetAttributes attributes
Definition zeml.h:129
Attributes for a widget.
Definition zeml.h:90
std::shared_ptr< void > flags
Definition zeml.h:101