libui/unix/button.c

56 lines
1.0 KiB
C
Raw Normal View History

2015-06-11 18:07:06 -05:00
// 10 june 2015
#include "uipriv_unix.h"
2015-08-27 14:30:55 -05:00
struct uiButton {
uiUnixControl c;
2015-06-11 18:07:06 -05:00
GtkWidget *widget;
GtkButton *button;
2015-06-11 18:07:06 -05:00
void (*onClicked)(uiButton *, void *);
void *onClickedData;
};
uiUnixControlAllDefaults(uiButton)
2015-06-11 18:07:06 -05:00
static void onClicked(GtkButton *button, gpointer data)
{
2015-08-27 14:30:55 -05:00
uiButton *b = uiButton(data);
2015-08-27 14:30:55 -05:00
(*(b->onClicked))(b, b->onClickedData);
2015-06-11 18:07:06 -05:00
}
static void defaultOnClicked(uiButton *b, void *data)
{
// do nothing
}
2015-08-27 14:30:55 -05:00
char *uiButtonText(uiButton *b)
2015-06-11 18:07:06 -05:00
{
return uiUnixStrdupText(gtk_button_get_label(b->button));
2015-06-11 18:07:06 -05:00
}
2015-08-27 14:30:55 -05:00
void uiButtonSetText(uiButton *b, const char *text)
2015-06-11 18:07:06 -05:00
{
gtk_button_set_label(b->button, text);
2015-06-11 18:07:06 -05:00
}
2015-08-27 14:30:55 -05:00
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
2015-06-11 18:07:06 -05:00
{
b->onClicked = f;
b->onClickedData = data;
}
uiButton *uiNewButton(const char *text)
{
2015-08-27 14:30:55 -05:00
uiButton *b;
2015-06-11 18:07:06 -05:00
uiUnixNewControl(uiButton, b);
2015-06-11 18:07:06 -05:00
b->widget = gtk_button_new_with_label(text);
b->button = GTK_BUTTON(b->widget);
2015-06-11 18:07:06 -05:00
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
2015-08-27 14:30:55 -05:00
uiButtonOnClicked(b, defaultOnClicked, NULL);
2015-06-11 18:07:06 -05:00
2015-08-27 14:30:55 -05:00
return b;
2015-06-11 18:07:06 -05:00
}