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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#include <raylib.h>
#include <stddef.h>
#include "../scenes/scenes.h"
#ifndef UI_ELEMENTS_H
#define UI_ELEMENTS_H
static const float ROUNDNESS = 0.015f;
static const int ROUNDNESS_SEGMENTS = 8;
static const float SCROLL_SENC = 10;
static const float TAB_WIDTH = 4;
static const int PADDING = 10;
static const int HEADER_FONT_SIZE = 50;
static const int EDITOR_PADDING = 3;
static const int BORDER = 2;
static const int FOOTER_HEIGHT = 30;
// Sure about this value
static const int MIN_FONT_SIZE = 10;
// Unsure about this value
static const int MAX_FONT_SIZE = 100;
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);
bool IsMouseInRec(Rectangle rec);
// ========== BUTTON ==========
typedef struct {
Scene *parent;
void *userData;
void (*OnClick)(Scene *);
Texture *atlas;
Rectangle textrueLocation;
Rectangle previousFramePosition;
} Button;
void UpdateButton(Button *btn);
void DrawButton(Button *btn, Rectangle *location);
// ========== PAGE VIEW ==========
static const int PAGE_DOTS_SPACING = 15;
static const int PAGE_DOTS_PADDING = 15;
static const int PAGE_DOTS_RADIUS = 3;
static const char PAGE_DOTS_TRANSPARENCY = (char)192;
/// Draws the little dots that represent the page you are on
void DrawPageView(int y, unsigned int pages, unsigned int current_page);
// ========== TEXT EDITOR ==========
static const size_t DEFAULT_TEXT_NODE_SIZE = 256;
typedef struct {
void *PrevNode;
void *NextNode;
char *text;
size_t len;
size_t cap;
} TextNode;
typedef struct {
Font *font;
int font_size;
int spacing;
int scroll_h;
int scroll_v;
/// DO NOT MODIFY THAT! It's for internal use only
int _area_width;
/// DO NOT MODIFY THAT! It's for internal use only
int _area_height;
} TextAreaDisplayParams;
typedef struct {
TextNode *StartNode;
/// For the quick access
TextNode *CurrentNode;
size_t NodeLenth;
Vector2 CursorPosition;
TextAreaDisplayParams *DisplayParams;
} TextArea;
TextArea *CreateTextArea(TextAreaDisplayParams *DisplayParams);
TextArea *CreateTextAreaFromText(TextAreaDisplayParams *DisplayParams, char *text);
void DrawTextArea(TextArea *ta, Rectangle rec);
void UpdateTextArea(TextArea *ta, Rectangle rec);
char *GetText(TextArea *ta);
void FreeTextArea(TextArea *ta);
/// Fills pane1 and pane2 with the panes location
/// proporion_h and proportion_v are the scale ratio of the panes in horizontal
/// and vertical orientation
void GetPanesSplit(Rectangle *pane1, Rectangle *pane2, Rectangle body, float proportion_h, float proportion_v);
#endif // UI_ELEMENTS_H
|