diff options
Diffstat (limited to 'src/ui_elements/TextEditor.c')
| -rw-r--r-- | src/ui_elements/TextEditor.c | 27 |
1 files changed, 27 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; +} |
