mirror of
https://github.com/0intro/wmii
synced 2024-12-26 05:16:59 +03:00
added basic layout.c to liblitz
This commit is contained in:
parent
d7fea5865f
commit
1b6bf46fe6
@ -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 window.c
|
||||
SRC = blitz.c color.c font.c label.c layout.c window.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
all: liblitz.a
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "blitz.h"
|
||||
|
||||
/* blitz.c */
|
||||
void
|
||||
blitz_x11_init(Display *dpy)
|
||||
{
|
||||
|
@ -10,12 +10,15 @@
|
||||
#define BLITZ_SELCOLORS "#ffffff #335577 #447799"
|
||||
#define BLITZ_NORMCOLORS "#222222 #eeeeee #666666"
|
||||
|
||||
enum {BLITZ_LAYOUT, BLITZ_LABEL, BLITZ_LAST};
|
||||
typedef struct Blitz Blitz;
|
||||
typedef enum BlitzAlign BlitzAlign;
|
||||
typedef struct BlitzColor BlitzColor;
|
||||
typedef struct BlitzFont BlitzFont;
|
||||
typedef struct BlitzLabel BlitzLabel;
|
||||
#define BLITZLABEL(p) ((BlitzLabel *)(p))
|
||||
typedef struct BlitzLayout BlitzLayout;
|
||||
#define BLITZLAYOUT(p) ((BlitzLayout *)(p))
|
||||
typedef union BlitzWidget BlitzWidget;
|
||||
typedef struct BlitzWin BlitzWin;
|
||||
|
||||
@ -57,25 +60,36 @@ struct BlitzWin{
|
||||
};
|
||||
|
||||
struct BlitzLayout {
|
||||
int type;
|
||||
XRectangle rect;
|
||||
Bool expand;
|
||||
BlitzWidget *next;
|
||||
/* widget specific */
|
||||
BlitzWin *win;
|
||||
BlitzWidget *widgets;
|
||||
void (*scale)(BlitzLayout *l);
|
||||
void (*draw)(BlitzLayout *l);
|
||||
BlitzWidget *rows;
|
||||
BlitzWidget *cols;
|
||||
void (*scale)(BlitzWidget *l);
|
||||
void (*draw)(BlitzWidget *l);
|
||||
};
|
||||
|
||||
struct BlitzLabel {
|
||||
int type;
|
||||
XRectangle rect;
|
||||
Bool expand;
|
||||
BlitzWidget *next;
|
||||
/* widget specific */
|
||||
BlitzColor color;
|
||||
BlitzAlign align;
|
||||
BlitzFont font;
|
||||
char *text;
|
||||
void (*draw)(BlitzLayout *l);
|
||||
void (*draw)(BlitzWidget *l);
|
||||
};
|
||||
|
||||
union BlitzWidget {
|
||||
int type;
|
||||
XRectangle rect;
|
||||
Bool expand;
|
||||
BlitzWidget *next;
|
||||
BlitzLabel label;
|
||||
};
|
||||
|
||||
@ -102,6 +116,12 @@ int blitz_loadcolor(BlitzColor *c, char *colstr);
|
||||
void blitz_drawlabel(BlitzDraw *d);
|
||||
void blitz_drawborder(BlitzDraw *d);
|
||||
|
||||
/* layout.c */
|
||||
BlitzLayout *blitz_create_layout(BlitzWin *win);
|
||||
void blitz_add_widget(BlitzWidget **l, BlitzWidget *w);
|
||||
void blitz_rm_widget(BlitzWidget **l, BlitzWidget *w);
|
||||
int blitz_destroy_layout(BlitzLayout *l);
|
||||
|
||||
/* font.c */
|
||||
unsigned int blitz_textwidth(BlitzFont *font, char *text);
|
||||
void blitz_loadfont(BlitzFont *font, char *fontstr);
|
||||
|
85
liblitz/layout.c
Normal file
85
liblitz/layout.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* (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"
|
||||
|
||||
/*
|
||||
* Each layout can be a widget. A layout may consist of
|
||||
* columns or rows of widgets, or of columns and rows of widgets.
|
||||
* Rows are scaled left to right, the first widget with
|
||||
* expand == True takes the remaining space of the overall row.
|
||||
* Columns are scaled top to bottom, the first widget with
|
||||
* expand == True takes the remaining space of the overall column.
|
||||
*/
|
||||
static void
|
||||
xscale(BlitzWidget *w)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
xdraww(BlitzWidget *w)
|
||||
{
|
||||
switch(w->type) {
|
||||
case BLITZ_LABEL:
|
||||
BLITZLABEL(w)->draw(w);
|
||||
break;
|
||||
case BLITZ_LAYOUT:
|
||||
BLITZLAYOUT(w)->draw(w);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xdraw(BlitzWidget *w)
|
||||
{
|
||||
BlitzLayout *l = BLITZLAYOUT(w);
|
||||
for(w = l->cols; w; w = w->next)
|
||||
xdraww(w);
|
||||
for(w = l->rows; w; w = w->next)
|
||||
xdraww(w);
|
||||
}
|
||||
|
||||
BlitzLayout *
|
||||
blitz_create_layout(BlitzWin *win)
|
||||
{
|
||||
BlitzLayout *l;
|
||||
l = cext_emallocz(sizeof(BlitzLayout));
|
||||
l->win = win;
|
||||
l->cols = l->rows = nil;
|
||||
l->scale = xscale;
|
||||
l->draw = xdraw;
|
||||
return l;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int
|
||||
blitz_destroy_layout(BlitzLayout *l)
|
||||
{
|
||||
if(l->cols || l->rows)
|
||||
return -1;
|
||||
free(l);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user