shithub: guifs

ref: c51962a648b3f38fc378ad0081b1d1aa037142d5
dir: guifs/guifs.h

View raw version
enum {
	Pbackground,
	Pborder,
	Pmargin,
	Ppadding,
	Porientation,
	Pbordercolour,
	Ptext,
	Ptextcolour,
	Pmenus,
	Pmax,
};

enum {
	nbaseprops = 6
};

enum {
	Gcontainer,
	Gtextbox,
	Gmax,
};

enum {
	Horizontal,
	Vertical,
	Up,
	Down,
};

enum {
	Xmousedown,
	Xmouseup,
	Xmouseclick,
	Xmousescroll,
	Xmenuhit,
	Xkeyboard,
	Xmax,
};

typedef struct Colour Colour;
typedef struct Spacing Spacing;
typedef struct MenuSpec MenuSpec;
typedef union PropVal PropVal;
typedef struct PropSpec PropSpec;
typedef struct Prop Prop;
typedef struct Event Event;
typedef struct GuiSpec GuiSpec;
typedef struct GuiElement GuiElement;

struct Colour {
	Image *image;
	ulong code;
};

struct Spacing {
	int up;
	int right;
	int down;
	int left;
};

struct MenuSpec {
	char seps[3];
	Menu *menus[3];
};

union PropVal {
	Colour *colour;
	Spacing *spacing;
	MenuSpec *menus;
	int orientation;
	Rune *text;
};

struct PropSpec {
	char *name;
	PropVal (*def)(int, int);
	char *(*print)(PropVal);
	char *(*parse)(char *, PropVal *);
};

struct Prop {
	int tag;
	PropVal val;
	Qid qid;
};

struct Event {
	int type;
	union {
		int i;
		Mouse m;
		Rune r;
		int direction;
		struct {
			char button;
			int which;
			char *text;
		} hit;
	};
};

struct GuiSpec {
	char *name;
	void (*draw)(GuiElement *);
	void (*layout)(GuiElement *, Rectangle);
	int leafnode;
	int nprops;
	int *proptags;
};

struct GuiElement {
	RWLock lock;

	int type;
	int id;

	Qid qid;
	Qid qclone;
	Qid qevent;
	Qid qtype;
	Qid qprops;

	int nchildren;
	GuiElement **children;

	GuiElement *parent;

	int nprops;
	Prop *props;

	uvlong listening; /* the user is reading from the 'event' file. Bitmask of which events are wanted */
	Channel *events;
	char *currentevents;
	int buttons;

	Rectangle border;
	Rectangle rect;
	Rectangle content;
};

extern Point mousexy;
extern GuiElement *root;
extern PropSpec propspecs[Pmax];
extern GuiSpec guispecs[Gmax];
extern int baseprops[nbaseprops];
extern Mousectl *mousectl;

void *emalloc(ulong);
void *erealloc(void *, ulong);
int allspace(char *);

Colour *mkcolour(ulong);
void initgraphics(void);
void layout(GuiElement *, Rectangle);
void updategui(int);
void drawcontainer(GuiElement *);
void drawtextbox(GuiElement *);

void layoutcontainer(GuiElement *, Rectangle);
void layouttextbox(GuiElement *, Rectangle);

PropVal getprop(GuiElement *, int, int);
void setprop(GuiElement *, int, PropVal, int);

int mouseevent(Mouse);
int keyboardevent(Rune);