aboutsummaryrefslogtreecommitdiff
path: root/libs/libgui/gui.h
blob: 10d44d83c777b155b766681444a15a04464e6e47 (plain) (blame)
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
// MIT License, Copyright (c) 2021 Marvin Borner

#ifndef GUI_H
#define GUI_H

#include <def.h>
#include <errno.h>
#include <libgui/gfx.h>
#include <sys.h>
#include <vec.h>

enum gui_listener {
	GUI_LISTEN_MOUSEMOVE,
	GUI_LISTEN_MOUSECLICK,
};

enum gui_layer {
	GUI_LAYER_BG,
	GUI_LAYER_FG,
};

enum gui_layout {
	GUI_HLAYOUT, // New widgets get positioned right of previous widget
	GUI_VLAYOUT, // New widgets get positioned under previous widget
};

struct gui_event_mouse {
	u32 win;
	u32 widget;
	vec2 pos;
	s8 scroll; // Dir: -1 neg, +1 pos
	struct {
		u8 left : 1;
		u8 right : 1;
		u8 middle : 1;
	} but;
};

// Down here because of codependency stuff
#include <libgui/widgets.h>

/**
 * Window operations
 */

u32 gui_window(const char *name);
u32 gui_window_custom(const char *name, vec2 pos, vec2 size);
void gui_window_redraw(u32 id);
void gui_window_redraw_plain(u32 id); // Without widgets

/**
 * GFX wrappers
 */

void gui_clear(u32 win_id, u32 widget_id, enum gui_layer layer);
void gui_fill(u32 win_id, u32 widget_id, enum gui_layer layer, u32 c);
void gui_write(u32 win_id, u32 widget_id, enum gui_layer layer, vec2 pos, enum font_type font_type,
	       u32 c, const char *text);
void gui_draw_image(u32 win_id, u32 widget_id, enum gui_layer layer, vec2 pos, vec2 size,
		    const char *path) NONNULL;
void gui_draw_image_filter(u32 win_id, u32 widget_id, enum gui_layer layer, vec2 pos, vec2 size,
			   enum gfx_filter filter, const char *path) NONNULL;
void gui_draw_rectangle(u32 win_id, u32 widget_id, enum gui_layer layer, vec2 pos1, vec2 pos2,
			u32 c);
void gui_draw_border(u32 win_id, u32 widget_id, enum gui_layer layer, u32 width, u32 c);
void gui_draw_line(u32 win_id, u32 widget_id, enum gui_layer layer, vec2 pos1, vec2 pos2, u32 scale,
		   u32 c);

/**
 * Widget operations
 */

u32 gui_widget(u32 win_id, u32 widget_id, vec2 size);
u32 gui_widget_main(u32 win_id);
void gui_widget_listen(u32 win_id, u32 widget_id, enum gui_listener listener, u32 func);
void gui_widget_redraw(u32 win_id, u32 widget_id);

void gui_popup(const char *text);

/**
 * Getters/setters
 */

vec2 gui_window_size(u32 win_id);
vec2 gui_widget_size(u32 win_id, u32 widget_id);
struct gfx_context *gui_widget_context(u32 win_id, u32 widget_id, enum gui_layer layer);
void gui_widget_margin(u32 win_id, u32 widget_id, vec2 margin);
void gui_widget_layout(u32 win_id, u32 widget_id, enum gui_layout layout);

void gui_loop(void);
void gui_time_loop(u32 time, void (*callback)(struct timer *time));

#endif