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
|
// 11 april 2015
#include "uipriv_unix.h"
struct label {
uiLabel l;
};
static void onDestroy(GtkWidget *widget, gpointer data)
{
struct label *l = (struct label *) data;
uiFree(l);
}
#define LABEL(l) GTK_LABEL(uiControlHandle(uiControl(l)))
static char *getText(uiLabel *l)
{
// TODO change g_strdup() to a wrapper function for export in ui_unix.h
return g_strdup(gtk_label_get_text(LABEL(l)));
}
static void setText(uiLabel *l, const char *text)
{
gtk_label_set_text(LABEL(l), text);
}
uiLabel *uiNewLabel(const char *text)
{
struct label *l;
GtkWidget *widget;
l = uiNew(struct label);
uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL,
FALSE, FALSE,
"label", text,
"xalign", 0.0, // note: must be a float constant, otherwise the ... will turn it into an int and we get segfaults on some platforms (thanks ebassi in irc.gimp.net/#gtk+)
// TODO yalign 0?
NULL);
widget = GTK_WIDGET(LABEL(l));
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), l);
uiLabel(l)->Text = getText;
uiLabel(l)->SetText = setText;
return uiLabel(l);
}
|