summaryrefslogtreecommitdiff
path: root/src/widget/widget_label.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/widget/widget_label.c')
-rw-r--r--src/widget/widget_label.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c
index 15dea4d..c0b3f35 100644
--- a/src/widget/widget_label.c
+++ b/src/widget/widget_label.c
@@ -1,47 +1,65 @@
#include <stdlib.h>
+#include <assert.h>
#include "main.h"
#include "interface.h"
#include "font.h"
#include "widget_label.h"
+#include "widget.h"
-widget_label_t* newWidgetLabel(char *text, int x, int y, int bind)
+widget_t* newWidgetLabel(char *text, int x, int y, int bind)
{
widget_label_t *new;
new = malloc( sizeof(widget_label_t) );
new->text = strdup(text);
- new->x = x;
- new->y = y;
new->bind = bind;
- getTextSize(text, &new->w, &new->h);
+ getTextSize(text, &(new->w), &(new->h));
- return new;
+ return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new);
}
-void drawWidgetLabel(widget_label_t *p)
+void drawWidgetLabel(widget_t *widget)
{
+ widget_label_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_LABEL );
+
+ p = (widget_label_t *) widget->private_data;
+
switch( p->bind )
{
case WIDGET_LABEL_RIGHT :
- drawFont(p->text, p->x+p->w, p->y + p->h/2, COLOR_WHITE);
+ drawFont(p->text, widget->x+p->w, widget->y + p->h/2, COLOR_WHITE);
break;
case WIDGET_LABEL_LEFT :
- drawFont(p->text, p->x, p->y + p->h/2, COLOR_WHITE);
+ drawFont(p->text, widget->x, widget->y + widget->h/2, COLOR_WHITE);
break;
case WIDGET_LABEL_CENTER :
- drawFont(p->text, p->x-p->w/2, p->y + p->h/2, COLOR_WHITE);
+ drawFont(p->text, widget->x-p->w/2, widget->y + p->h/2, COLOR_WHITE);
break;
}
}
-void eventWidgetLabel(widget_label_t *p)
+void eventWidgetLabel(widget_t *widget)
{
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_LABEL );
}
-void destroyWidgetLabel(widget_label_t *p)
+void destroyWidgetLabel(widget_t *widget)
{
+ widget_label_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_LABEL );
+
+ p = (widget_label_t *) widget->private_data;
+
free(p->text);
free(p);
+
+ destroyWidget(widget);
}