File: menu.bs

package info (click to toggle)
storm-lang 0.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,100 kB
  • sloc: ansic: 261,471; cpp: 140,438; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (89 lines) | stat: -rw-r--r-- 1,617 bytes parent folder | download | duplicates (2)
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
use ui;
use layout;
use core:geometry;

class MenuWindow extends Frame {
	init() {
		MenuBar root;
		PopupMenu help;

		init("Menu test", Size(300, 100)) {
			root = root;
			help = help;
			button = Button("Test button");
		}

		help << Menu:Check("Enable help", &this.enableHelp);
		help << Menu:Text("Help", &this.showHelp) << Menu:Separator() << Menu:Text("About...", &this.showAbout());
		help[1].enabled = false;

		root << Menu:Text("Test") << Menu:Submenu("Help", help);
		menu = root;

		add(button);
		button.pos(Rect(0, 0, 300, 100).shrink(Size(8)));

		create();
	}

	MenuBar root;
	PopupMenu help;
	Button button;

	Bool onClick(Bool pressed, Point at, MouseButton button) : override {
		if (pressed) {
			if (button == MouseButton:left) {
				if (menu)
					menu = null;
				else
					menu = root;
			} else if (button == MouseButton:middle) {
				fullscreen = !fullscreen;
			} else if (button == MouseButton:right) {
				popupMenu(help);
			}
		}

		true;
	}

	void showAbout() {
		AboutWindow win;
		Int r = win.show(this);
		print("Result: ${r}");
	}

	void enableHelp(Bool enabled) {
		help[1].enabled = enabled;
	}

	void showHelp() {
		root << Menu:Text("Bonus");
	}
}

dialog AboutWindow {
	layout Grid {
		expandCol: 0;
		expandRow: 0;

		Edit e() { row: 0; col: 0; colspan: 3; }
		Button close("Close") { row: 1; col: 1; }
		Button ok("OK") { row:1; col: 2; }
	}

	init() {
		init("About", Size(200, 100)) {}

		var me = this;
		close.onClick = () => me.close(1);
		defaultChoice = ok;
		ok.onClick = () => me.close(100);
	}
}

void menu() {
	MenuWindow w;
	w.waitForClose;
	print("Done!");
}