aboutsummaryrefslogtreecommitdiff
path: root/libs/libgui/widgets.c
blob: d6e82cdd027c33929db250cfdbc7240a1d8a0d9a (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
// MIT License, Copyright (c) 2021 Marvin Borner

#include <def.h>
#include <libgui/gui.h>
#include <libgui/widgets.h>

#define TEXT_PAD 2

/**
 * Button
 */

void gui_button_custom(u32 window, u32 widget, vec2 pos, enum font_type font_type, u32 bg, u32 fg,
		       void (*click)(struct gui_event_mouse *event), const char *text)
{
	vec2 font_size = gfx_font_size(font_type);
	vec2 size = vec2(font_size.x * strlen(text) + TEXT_PAD * 2, font_size.y + TEXT_PAD * 2);
	u32 button = gui_widget(window, widget, pos, size);
	gui_fill(window, button, GUI_LAYER_BG, bg);
	gui_write(window, button, GUI_LAYER_FG, vec2(TEXT_PAD, TEXT_PAD), font_type, fg, text);
	gui_widget_listen(window, button, GUI_LISTEN_MOUSECLICK, (u32)click);
}

void gui_button(u32 window, u32 widget, void (*click)(struct gui_event_mouse *event),
		const char *text)
{
	gui_button_custom(window, widget, vec2(0, 0), FONT_16, COLOR_WHITE, COLOR_BLACK, click,
			  text);
}