summaryrefslogtreecommitdiff
path: root/src/ui_elements/UI.h
blob: 102928970954d7a7b6e65a2f90635c9e4554960c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <raylib.h>
#include <stddef.h>

#ifndef UI_ELEMENTS_H
#define UI_ELEMENTS_H

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);
float MeasureChar(Font *font, int height, char symbol);

// ========== TEXT EDITOR ==========

static const size_t DEFAULT_TEXT_NODE_SIZE = 5;

typedef struct {
    void *PrevNode;
    void *NextNode;
    char *text;
    size_t len;
    size_t cap;
} TextNode;

typedef struct {
    TextNode *StartNode;
    /// For the quick access
    TextNode *CurrentNode;
    size_t NodeLenth;

    Vector2 CursorPosition;
} TextArea;

TextArea *CreateTextArea();
void FreeTextArea(TextArea *ta);
void DrawTextArea(TextArea *ta, Rectangle rec, Font *font, int height, int spacing);
void InsertChar(TextArea *ta, char new_char);
void DeleteChar(TextArea *ta);

void HandleKeyboard(TextArea *ta);
void MoveCursorRight(TextArea *ta);
void MoveCursorLeft(TextArea *ta);
void MoveCursorDown(TextArea *ta);

#endif // UI_ELEMENTS_H