Implemented uiButton on GTK+. All we need to do is get it to show up...

This commit is contained in:
Pietro Gagliardi 2015-04-07 13:58:50 -04:00
parent 205cc9c2cf
commit 3c427ed799
3 changed files with 59 additions and 1 deletions

56
new/button_unix.c Normal file
View File

@ -0,0 +1,56 @@
// 7 april 2015
#include "uipriv_unix.h"
struct button {
uiControl *c;
void (*onClicked)(uiControl *, void *);
void *onClickedData;
};
#define B(x) ((struct button *) (x))
static void onClicked(GtkButton *b, gpointer data)
{
(*(B(data)->onClicked))(B(data)->c, B(data)->onClickedData);
}
static void defaultOnClicked(uiControl *c, void *data)
{
// do nothing
}
// TODO destruction
uiControl *uiNewButton(const char *text)
{
struct button *b;
GParameter props[1];
GtkWidget *widget;
b = g_new0(struct button, 1);
props[0].name = "label";
g_value_init(&(props[0].value), G_TYPE_STRING);
g_value_set_string(&(props[0].value), text);
b->c = uiUnixNewControl(GTK_TYPE_BUTTON,
1, props,
FALSE, FALSE, FALSE, b);
g_value_unset(&(props[0].value)); // thanks to gregier in irc.gimp.net/#gtk+
widget = GTK_WIDGET(uiControlHandle(b->c));
g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b);
b->onClicked = defaultOnClicked;
return b->c;
}
// TODO text
void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
{
struct button *b;
b = (struct button *) uiUnixControlData(c);
b->onClicked = f;
b->onClickedData = data;
}

View File

@ -33,6 +33,7 @@ static void defaultOnClicked(uiControl *c, void *data)
// do nothing
}
// TODO destruction
uiControl *uiNewButton(const char *text)
{
struct button *b;

View File

@ -39,7 +39,8 @@ static void uiContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocati
gtk_widget_set_allocation(widget, allocation);
c = uiContainer(widget)->child;
(*(c->resize))(c, allocation->x, allocation->y, allocation->width, allocation->height, &d);
if (c != NULL)
(*(c->resize))(c, allocation->x, allocation->y, allocation->width, allocation->height, &d);
}
struct forall {