aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/frontend/html/pages/test.js
blob: 2a84ff16304b7cd336d0fa6e3f5f12d49033f610 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright Epic Games, Inc. All Rights Reserved.

"use strict";

import { ZenPage } from "./page.js"
import { Table, PropTable, Toolbar, ProgressBar } from "../util/widgets.js"
import { Modal, } from "../util/modal.js"

////////////////////////////////////////////////////////////////////////////////
export class Page extends ZenPage
{
	main()
	{
		var gen_word = (function() {
			var s = 0x314251;
			var r = function(a, b) {
				s = (s * 0x493) & 0x7fffffff;
				return ((s >> 3) % (b - a)) + a;
			};
			return function(a=5, b=10) {
				const co = "aeioubcdfghjklmnpqrstvwxyz";
				var ret = "";
				for (var i = 0, n = r(a,b); i < n; ++i)
					ret += co[r(0, co.length)];
				return ret;
			};
		})();
		var gen_para = function(a=5, b=10, s=" ") {
			var ret = gen_word(2, 9);
			for (var i = 0; i < ((ret.length * 0x493) % (b - a)) + b; ++i)
				ret += s + gen_word(2, 9);
			return ret;
		}

		this.set_title("test");

		// swatches
		const swatches = this.tag()
			.style("position", "absolute")
			.style("top", "3.5em")
			.style("left", "3.5em")
		for (var suffix of ["g0", "g1", "g2", "g3", "g4",
							"p0", "p1", "p2", "p3", "p4",
							"ln", "er"])
		{
			swatches.tag()
				.style("float", "left")
				.style("width", "2em")
				.style("height", "2em")
				.style("background-color", `var(--theme_${suffix})`)
				.text(suffix);
		}

		// section
		var section0 = this.add_section("section");
		var section1 = section0.add_section("sub-section");
		var section2 = section1.add_section("sub-sub-section");

		// table
		const cols = [gen_word(), gen_word(), gen_word(), gen_word()];
		var tables = [
			section0.add_widget(Table, cols),
			section1.add_widget(Table, cols, Table.Flag_EvenSpacing, 5),
			section2.add_widget(Table, cols, Table.Flag_EvenSpacing, -1),
		];

		for (const table of tables)
		{
			table.add_row(gen_word());
			table.add_row(gen_word(), gen_word(), gen_word(), gen_word());
			table.add_row(gen_word(), gen_word(), gen_para(15, 25), gen_word(), gen_word(), gen_word(), gen_word(), gen_word());
		}

		// spacing tests
		{
			const spacing_section = section0.add_section("spacing");
			const flags = {
				"EvenSpacing"			: Table.Flag_EvenSpacing,
				"EvenSpacing|BiasLeft"	: Table.Flag_EvenSpacing | Table.Flag_BiasLeft,
				"PackRight"				: Table.Flag_PackRight,
			};
			for (const flag_name in flags)
			{
				const flag = flags[flag_name];
				const another_table = spacing_section.add_widget(
					Table,
					[flag_name, gen_word(), gen_word(), gen_word(), gen_word()],
					flag,
				);
				for (var i = 0; i < 3; ++i)
					another_table.add_row(gen_para(1, 5), gen_para(1, 3), gen_word(), gen_word(), gen_word());
			}
		}

		// prop-table
		var pt_section = section0.add_section("prop-table")
		var prop_table = pt_section.add_widget(PropTable);
		for (var i = 0; i < 7; ++i)
			prop_table.add_property(gen_word(), gen_para(1, 20, "/"));

		// misc
		const misc_section = section0.add_section("misc").add_section("misc");
		misc_section.tag().text("just text");
		misc_section.tag().text("this is a link").link();
		misc_section.tag().text("MODAL DIALOG").on_click((e) => {
			new Modal()
				.title("modal")
				.message("here is a message what I wrote")
				.option("press me!", () => { alert("hi"); })
				.option("cancel", () => void(0));
		});

		// toolbar
		pt_section.add_section("toolbar");
		var toolbar = pt_section.add_widget(Toolbar);
		for (const side of [toolbar.left(), toolbar.right()])
		{
			side.add("tb_item0");
			side.add("tb_item1");
			side.sep();
			side.add("tb_item2");
		}

		var tb_item_clicked = function(arg0, arg1) {
			alert(arg0 + " != " + arg1);
		};
		var row = prop_table.add_property("toolbar", "");
		toolbar = new Toolbar(row.get_cell(-1), true);
		toolbar.left() .add("tbitem0").on_click(tb_item_clicked, 11, -22);
		toolbar.left() .add("tbitem1").on_click(tb_item_clicked, 22, -33);
		toolbar.right().add("tbitem2").on_click(tb_item_clicked, 33, -55);
		toolbar.right().add("tbitem3").on_click(tb_item_clicked, 44, -88);

		// progress bar
		const progress_bar = this.add_widget(ProgressBar);
		setInterval(function() {
			var count = 0
			return () => {
				count = (count + 1) % 100;
				progress_bar.set_progress("testing", count, 100);
			};
		}(), 49.3);

		// error
		throw Error("deliberate error");
	}
}