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
|
#include <glib.h>
#include "button.h"
#include "log.h"
Button *button_simple_create(PangoAlignment align, Color color, Color line_color)
{
Button *btn = g_malloc0(sizeof(ButtonSimple));
btn->simple = true;
btn->align = align;
btn->color = color;
btn->line_color = line_color;
CAST(btn, ButtonSimple)->action = NULL;
return btn;
}
void button_simple_set_text(Button *btn, char *text, Color text_color)
{
g_assert(btn->simple);
ButtonSimple *sbtn = CAST(btn, ButtonSimple);
if (sbtn->text != NULL) g_free(sbtn->text);
sbtn->text = text;
sbtn->text_color = text_color;
}
const char *button_simple_get_text(Button *btn)
{
g_assert(btn->simple);
return CAST(btn, ButtonSimple)->text;
}
void button_simple_set_action(Button *btn, ButtonAction action, gpointer data)
{
g_assert(btn->simple);
CAST(btn, ButtonSimple)->action = action;
CAST(btn, ButtonSimple)->action_data = data;
}
ButtonAction button_simple_get_action(Button *btn)
{
g_assert(btn->simple);
return CAST(btn, ButtonSimple)->action;
}
Button *button_group_create(PangoAlignment align, Color color, Color line_color)
{
Button *btn = g_malloc0(sizeof(ButtonGroup));
btn->simple = false;
btn->align = align;
btn->color = color;
btn->line_color = line_color;
return btn;
}
void button_group_append(Button *btn, Button *child)
{
g_assert(!btn->simple);
CAST(btn, ButtonGroup)->children = g_list_append(CAST(btn, ButtonGroup)->children, child);
}
void button_set_padding(Button *btn, int x_pad, int y_pad)
{
g_assert(x_pad >= 0 && y_pad >= 0);
btn->x_pad = x_pad;
btn->y_pad = y_pad;
}
bool button_set_animation(Button *btn, Animation *anim)
{
if (btn->anim != NULL)
return false;
btn->anim = anim;
return true;
}
void button_destroy(Button *btn)
{
if (btn->simple) g_free(CAST(btn, ButtonSimple)->text);
animation_destroy(btn->anim);
g_free(btn);
}
|