xref: /inferno-os/module/prefab.m (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1Prefab: module
2{
3	PATH:	con	"$Prefab";
4
5	# types of Elements
6	EIcon:		con 0;
7	EText:		con 1;
8	ETitle:		con 2;
9	EHorizontal:	con 3;
10	EVertical:	con 4;
11	ESeparator:	con 5;
12
13	# first arg to Element.adjust: size of elements
14	Adjpack:	con 10;	# leave alone, pack tightly
15	Adjequal:	con 11;	# make equal
16	Adjfill:	con 12;	# make equal, filling available space
17
18	# second arg: position of element within space
19	Adjleft:	con 20;
20	Adjup:		con 20;
21	Adjcenter:	con 21;
22	Adjright:	con 22;
23	Adjdown:	con 22;
24
25	# default fonts and colors for objects
26	Style: adt
27	{
28		titlefont:	ref Draw->Font;
29		textfont:	ref Draw->Font;
30		elemcolor:	ref Draw->Image;
31		edgecolor:	ref Draw->Image;
32		titlecolor:	ref Draw->Image;
33		textcolor:	ref Draw->Image;
34		highlightcolor:	ref Draw->Image;
35	};
36
37	# drawing environment for objects
38	Environ: adt
39	{
40		screen:	ref Draw->Screen;
41		style:	ref Style;
42	};
43
44	# operand for layout operators; set either (font, color, text) or (icon, mask)
45	Layout: adt
46	{
47		font:		ref Draw->Font;
48		color:		ref Draw->Image;
49		text:		string;
50		icon:		ref Draw->Image;
51		mask:		ref Draw->Image;
52		tag:		string;
53	};
54
55	# graphical objects in the interface, recursively defined for making lists
56	Element: adt
57	{
58		# part of Ell elements
59		kind:		int;			# type: EIcon, EText, etc.
60		r:		Draw->Rect;		# rectangle on screen
61		environ:	ref Environ;		# graphics screen, style
62		tag:		string;			# identifier for selection
63
64		# different fields defined for different kinds of Elements
65		kids:		list of ref Element;	# children of EHorizontal, EVertical
66		str:		string;			# text in an EText element
67		mask:		ref Draw->Image;	# part of Eicon, ESeparator
68		image:		ref Draw->Image;	# part of Eicon, ESeparator, EText, Etitle
69		font:		ref Draw->Font;		# part of EText, Etitle
70
71		# constructors
72		icon:		fn(env: ref Environ, r: Draw->Rect, icon, mask: ref Draw->Image): ref Element;
73		text:		fn(env: ref Environ, text: string, r: Draw->Rect, kind: int): ref Element;
74		layout:	fn(env: ref Environ, lay: list of Layout, r: Draw->Rect, kind: int): ref Element;
75		elist:		fn(env: ref Environ, elem: ref Element, kind: int): ref Element;
76		separator:	fn(env: ref Environ, r: Draw->Rect, icon, mask: ref Draw->Image): ref Element;
77
78		# editing and geometry
79		append:	fn(elist: self ref Element, elem: ref Element): int;
80		adjust:	fn(elem: self ref Element, equal: int, dir: int);
81		clip:		fn(elem: self ref Element, r: Draw->Rect);
82		scroll:	fn(elem: self ref Element, d: Draw->Point);
83		translate:	fn(elem: self ref Element, d: Draw->Point);
84		show:	fn(elist: self ref Element, elem: ref Element): int;
85	};
86
87	# connects an element to a window for display
88	Compound: adt
89	{
90		image:		ref Draw->Image;	# window on which contents are drawn
91		environ:	ref Environ;		# graphics screen, style
92		r:		Draw->Rect;		# rectangle on screen
93		title:		ref Element;		# above the line (may be nil)
94		contents:	ref Element;		# below the line
95
96		# constructors
97		iconbox:	fn(env: ref Environ, p: Draw->Point, title: string, icon, mask: ref Draw->Image): ref Compound;
98		textbox:	fn(env: ref Environ, r: Draw->Rect, title, text: string): ref Compound;
99		layoutbox:fn(env: ref Environ, r: Draw->Rect, title: string, lay: list of Layout): ref Compound;
100		box:		fn(env: ref Environ, p: Draw->Point, title, elist: ref Element): ref Compound;
101
102		# display
103		draw:	fn(comp: self ref Compound);
104		redraw:	fn(comp: self ref Compound, r: Draw->Rect);
105		scroll:	fn(comp: self ref Compound, elem: ref Element, d: Draw->Point);
106		show:	fn(comp: self ref Compound, elem: ref Element): int;
107
108		# support for using EHorizontal and EVertical as menus
109		select:	fn(comp: self ref Compound, elem: ref Element, i: int, c: chan of int): (int, int, ref Element);
110		tagselect:	fn(comp: self ref Compound, elem: ref Element, i: int, c: chan of int): (int, int, ref Element);
111		highlight:	fn(comp: self ref Compound, elem: ref Element, on: int);
112	};
113};
114