Add flags, file mgmt, widgets to zeml

This commit is contained in:
scawful
2024-04-19 11:13:34 -04:00
parent ccf234aacd
commit b9be709832
2 changed files with 340 additions and 42 deletions

View File

@@ -54,15 +54,20 @@ enum class WidgetType {
TableNextColumn,
CollapsingHeader,
Columns,
Checkbox,
Selectable,
Function,
BeginChild,
BeginMenuBar,
BeginMenu,
BeginTabBar,
BeginTabItem,
MenuItem,
Separator,
HexInputByte,
HexInputWord,
Canvas,
Definition,
};
/**
@@ -82,16 +87,17 @@ enum class WidgetType {
*/
struct WidgetAttributes {
std::string id;
std::string title; // For Window, Button
double min; // For Slider
double max; // For Slider
double value; // For Slidecar
std::string text; // For Text, Button
int count = 0; // For Columns
ImVec2 size = ImVec2(0, 0);
void* flags = nullptr;
void* data = nullptr;
std::string title; // For Window, Button
std::string text; // For Text, Button
double min; // For Slider
double max; // For Slider
double value; // For Slidecar
float width; // For Columns
int count = 0; // For Columns
ImVec2 size = ImVec2(0, 0); // For BeginChild
bool* selected = nullptr; // For Selectable
void* flags = nullptr; // For Various
void* data = nullptr; // For Various
};
/**
@@ -104,8 +110,7 @@ enum class ActionType { Click, Change, Run };
*/
struct Action {
ActionType type;
std::function<void()> callback; // Using std::function to hold lambda
// expressions or function pointers
std::function<void()> callback;
};
/**
@@ -149,11 +154,25 @@ void Bind(Node* node, std::function<void()> callback);
*/
void BindAction(Node* node, ActionType type, std::function<void()> callback);
/**
* @brief Bind a selectable node
*/
void BindSelectable(Node* node, bool* selected, std::function<void()> callback);
/**
* @brief Map a string to a widget type
*/
WidgetType MapType(const std::string& type);
/**
* @brief Parse a zeml definition
*/
void ParseDefinitions(const std::vector<Token>& tokens, size_t& index,
std::map<std::string, Node>& definitions);
void ParseFlags(const WidgetType& type, const std::string& flags,
WidgetAttributes& flags_ptr);
/**
* @brief ParseNode attributes for a widget
*/
@@ -162,13 +181,14 @@ WidgetAttributes ParseAttributes(
const std::map<std::string, void*>& data_bindings = {});
/**
* @brief ParseNode a zeml node
* @brief Parse a zeml node
*/
Node ParseNode(const std::vector<Token>& tokens, size_t& index,
const std::map<std::string, void*>& data_bindings = {});
const std::map<std::string, void*>& data_bindings = {},
const std::map<std::string, Node>& definitions = {});
/**
* @brief ParseNode a zeml string
* @brief Parse a zeml string
*/
Node Parse(const std::string& yazon_input,
const std::map<std::string, void*>& data_bindings = {});
@@ -183,6 +203,8 @@ void Render(Node& node);
*/
void ExecuteActions(const std::vector<Action>& actions, ActionType type);
std::string LoadFile(const std::string& filename);
} // namespace zeml
} // namespace gui
} // namespace app