diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-07-10 00:02:55 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-07-10 00:04:44 +0500 |
| commit | 55ef21312888cbfb9d449eee8f7958b74f85ac7c (patch) | |
| tree | ba819c6f1bc03c711e8cf1ad069be30a95e9f4f6 /src/ui_elements | |
| parent | 90988da0bdae2c56366abb01f402a0cd34279143 (diff) | |
more work on an editor
Diffstat (limited to 'src/ui_elements')
| -rw-r--r-- | src/ui_elements/TextEditor.c | 8 | ||||
| -rw-r--r-- | src/ui_elements/UI.h | 1 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/ui_elements/TextEditor.c b/src/ui_elements/TextEditor.c index ebc8671..fa85443 100644 --- a/src/ui_elements/TextEditor.c +++ b/src/ui_elements/TextEditor.c @@ -68,11 +68,13 @@ bool AddSpaceDetermined(TextNode *base, size_t additional_space) { void AppendTextToNode(TextNode *base, char *new_text) { if (base == NULL || new_text == NULL) return; size_t len = strlen(base->text); + size_t new_len = strlen(new_text); /// >= and not > because it needs a \0 - if (len + strlen(new_text) >= base->cap) { + if (len + new_len >= base->cap) { if (!AddSpace(base)) return; } strcpy(base->text + len, new_text); + base->len += new_len; } TextArea *CreateTextArea() { @@ -367,6 +369,10 @@ void HandleKeyboard(TextArea *ta) { if (IsKeyPressedFix(KEY_RIGHT)) MoveCursorRight(ta); if (IsKeyPressedFix(KEY_DOWN)) MoveCursorDown(ta); if (IsKeyPressedFix(KEY_UP)) MoveCursorUp(ta); + if (IsKeyPressedFix(KEY_TAB)) { + for (int i = 0; i < TAB_WIDTH; i++) + InsertChar(ta, ' '); + }; if (IsKeyPressedFix(KEY_HOME)) MoveCursorHome(ta); if (IsKeyPressedFix(KEY_END)) MoveCursorEnd(ta); diff --git a/src/ui_elements/UI.h b/src/ui_elements/UI.h index 779290f..eaf17e8 100644 --- a/src/ui_elements/UI.h +++ b/src/ui_elements/UI.h @@ -5,6 +5,7 @@ #define UI_ELEMENTS_H static const float SCROLL_SENC = 10; +static const float TAB_WIDTH = 4; void DrawRecBordered(Rectangle rec, Color bg, Color border_color, int border_width); void DrawTextInRec(Rectangle rec, char *text, Font *font, int height, Color color, float padding, int *scroll); |
