summaryrefslogtreecommitdiff
path: root/src/ui_elements
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui_elements')
-rw-r--r--src/ui_elements/TextEditor.c27
-rw-r--r--src/ui_elements/UI.h1
2 files changed, 28 insertions, 0 deletions
diff --git a/src/ui_elements/TextEditor.c b/src/ui_elements/TextEditor.c
index 620abea..1097f1c 100644
--- a/src/ui_elements/TextEditor.c
+++ b/src/ui_elements/TextEditor.c
@@ -507,3 +507,30 @@ void DrawTextArea(TextArea *ta, Rectangle rec) {
}
EndScissorMode();
}
+
+char *GetText(TextArea *ta) {
+ size_t size = 0;
+ TextNode *node = ta->StartNode;
+ while (node != NULL) {
+ size += node->len + 1;
+ node = node->NextNode;
+ }
+
+ char *outp = malloc(size + 1);
+ if (outp == NULL) {
+ TraceLog(LOG_ERROR, "Failed to create a text from a text area");
+ return NULL;
+ }
+
+ size_t idx = 0;
+ node = ta->StartNode;
+ while (node != NULL) {
+ memcpy(outp + idx, node->text, node->len);
+ idx += node->len + 1;
+ outp[idx - 1] = '\n';
+ node = node->NextNode;
+ }
+ outp[size] = 0x0;
+
+ return outp;
+}
diff --git a/src/ui_elements/UI.h b/src/ui_elements/UI.h
index 9f126c3..f461cf5 100644
--- a/src/ui_elements/UI.h
+++ b/src/ui_elements/UI.h
@@ -58,6 +58,7 @@ void InsertChar(TextArea *ta, char new_char);
void DeleteChar(TextArea *ta);
void HandleKeyboard(TextArea *ta);
+char *GetText(TextArea *ta);
void FreeTextArea(TextArea *ta);
#endif // UI_ELEMENTS_H