added widget.c

This commit is contained in:
Anselm R. Garbe 2006-06-13 18:24:08 +02:00
parent f774e68470
commit f043abedc3
4 changed files with 54 additions and 8 deletions

View File

@ -6,7 +6,7 @@ include ../config.mk
CFLAGS += -I../libixp -I../libcext
LDFLAGS += -L../libixp -lixp -L../libcext -lcext
SRC = blitz.c color.c font.c label.c layout.c window.c
SRC = blitz.c color.c font.c label.c layout.c window.c widget.c
OBJ = ${SRC:.c=.o}
all: liblitz.a

View File

@ -19,6 +19,7 @@ typedef struct BlitzLabel BlitzLabel;
typedef struct BlitzLayout BlitzLayout;
#define BLITZLAYOUT(p) ((BlitzLayout *)(p))
typedef union BlitzWidget BlitzWidget;
#define BLITZWIDGET(p) ((BlitzWidget *)(p))
typedef struct BlitzWin BlitzWin;
struct Blitz {
@ -63,6 +64,7 @@ struct BlitzLayout {
Bool expand;
BlitzWidget *next;
void (*draw)(BlitzWidget *);
void (*destroy)(BlitzWidget *);
/* widget specific */
BlitzWin *win;
BlitzWidget *rows;
@ -75,6 +77,7 @@ struct BlitzLabel {
Bool expand;
BlitzWidget *next;
void (*draw)(BlitzWidget *);
void (*destroy)(BlitzWidget *);
/* widget specific */
BlitzColor color;
BlitzAlign align;
@ -87,7 +90,9 @@ union BlitzWidget {
Bool expand;
BlitzWidget *next;
void (*draw)(BlitzWidget *);
void (*destroy)(BlitzWidget *);
BlitzLabel label;
BlitzLayout layout;
};
typedef struct {
@ -114,12 +119,16 @@ void blitz_drawlabel(BlitzDraw *d);
void blitz_drawborder(BlitzDraw *d);
/* layout.c */
BlitzLayout *blitz_create_layout(BlitzWin *win);
BlitzLayout *blitz_create_layout(BlitzWin *win, BlitzWidget **w);
/* font.c */
unsigned int blitz_textwidth(BlitzFont *font, char *text);
void blitz_loadfont(BlitzFont *font, char *fontstr);
/* widget.c */
void blitz_add_widget(BlitzWidget **l, BlitzWidget *w);
void blitz_rm_widget(BlitzWidget **l, BlitzWidget *w);
/* window.c */
BlitzWin *blitz_create_win(unsigned long mask,
int x, int y, int w, int h);

View File

@ -22,26 +22,36 @@ xscale(BlitzWidget *w)
}
static void
xdestroy(BlitzWidget *w)
{
BlitzLayout *l = BLITZLAYOUT(w);
for(w = l->cols; w; w = w->next)
w->destroy(w);
for(w = l->rows; w; w = w->next)
w->destroy(w);
}
static void
xdraw(BlitzWidget *w)
{
BlitzLayout *l = BLITZLAYOUT(w);
for(w = l->cols; w; w = w->next)
if(w->draw)
w->draw(w);
for(w = l->rows; w; w = w->next)
if(w->draw)
w->draw(w);
}
BlitzLayout *
blitz_create_layout(BlitzWin *win)
blitz_create_layout(BlitzWin *win, BlitzWidget **w)
{
BlitzLayout *l;
l = cext_emallocz(sizeof(BlitzLayout));
l->win = win;
l->cols = l->rows = nil;
l->scale = xscale;
l->destroy = xdestroy;
l->draw = xdraw;
l->scale = xscale;
blitz_add_widget(w, BLITZWIDGET(l));
return l;
}

27
liblitz/widget.c Normal file
View File

@ -0,0 +1,27 @@
/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <cext.h>
#include <stdlib.h>
#include "blitz.h"
void
blitz_add_widget(BlitzWidget **l, BlitzWidget *w)
{
BlitzWidget **wt;
for(wt = l; *wt; wt = &(*wt)->next);
w->next = nil;
*wt = w;
}
void
blitz_rm_widget(BlitzWidget **l, BlitzWidget *w)
{
BlitzWidget **wt;
for(wt = l; *wt && *wt != w; wt = &(*wt)->next);
cext_assert(*wt == w);
*wt = w->next;
}