-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEditor.c
More file actions
56 lines (52 loc) · 1.29 KB
/
Copy pathEditor.c
File metadata and controls
56 lines (52 loc) · 1.29 KB
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
#include "types.h"
#include "color.h"
#include "msg.h"
#include "themis_ui.h"
#include "user.h"
#include "fcntl.h"
char filename[40];
void saveBackBtn(window *win, int index, message* msg) {
printf(1, "saving\n");
int file = open(filename, 1);
int i;
for (i = 0; i < win->widget_number; i++) {
if (win->widgets[i].type == TEXT_AREA) {
break;
}
}
write(file, win->widgets[i].context.textArea->text, 512);
close(file);
printf(1, "saved\n");
}
int main(int argc, char *argv[]) {
RGBA black;
black.A = 255;
black.R = 0;
black.G = 0;
black.B = 0;
RGBA red;
red.A = 255;
red.R = 0;
red.G = 255;
red.B = 0;
window editor;
editor.width = 400;
editor.height = 300;
UI_createWindow(&editor, "Editor", 0);
int file = -1;
if (argc > 1) {
file = open(argv[1], 0);
strcpy(filename, argv[1]);
} else {
strcpy(filename, "new.txt");
}
int panel = addTextAreaWidget(&editor, black, "", 0, 0, 400, 275);
addButtonWidget(&editor, black, red, "save", saveBackBtn, 350, 278, 40, 20);
if (file >= 0) {
read(file, editor.widgets[panel].context.textArea->text, 512);
close(file);
}
drawAllWidget(&editor);
mainLoop(&editor);
return 0;
}