PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/vision/basic_examples/basic_events.e

http://github.com/tybor/Liberty
Specman e | 69 lines | 47 code | 8 blank | 14 comment | 1 complexity | 8c8d83dbef2836cc38e3d1da54114fc0 MD5 | raw file
 1class BASIC_EVENTS
 2	-- This example show:
 3	-- how to add widgets into the window,
 4	-- how to use COLUMN_LAYOUT and it's border and spacing,
 5	-- how to register procedure to be called for each user action.
 6
 7inherit
 8	GRAPHIC
 9		-- Give access to constants (vision, colors...)
10
11creation {ANY}
12	make
13
14feature {}
15	toplevel_window: TOPLEVEL_WINDOW
16
17	column_layout: COLUMN_LAYOUT
18
19	make is
20		local
21			label: LABEL; horizontal_line: HORIZONTAL_LINE; button: BUTTON
22		do
23			create column_layout
24			create toplevel_window.make(column_layout)
25			-- minimal space between the border and objects inside
26			column_layout.set_border(5)
27			-- minimal space between each object inside
28			column_layout.set_spacing(5)
29			toplevel_window.set_title("Hello World")
30			toplevel_window.set_background_color(white_color)
31			toplevel_window.map
32			-- put the window on the screen; may be done later
33			-- register procedure to call on user requests on 'toplevel_window'
34			toplevel_window.when_wheel_up(agent border(1))
35			toplevel_window.when_wheel_down(agent border(-1))
36			create label.make(U"Hello World ! Please, use the wheel.")
37			toplevel_window.when_left_down(agent label.set_text(U"Hello World !"))
38			toplevel_window.when_right_down(agent label.set_text(U"Use the wheel"))
39			-- windows are containers, you add widgets into them
40			toplevel_window.child_attach(label)
41			create horizontal_line
42			toplevel_window.child_attach(horizontal_line)
43			create button.with_label(toplevel_window, U"Exit")
44			-- register procedure to call on user requests on 'quit'
45			button.when_left_clicked(agent vision.loop_stack.break)
46			button.when_right_down(agent background(black_color))
47			button.when_right_up(agent background(white_color))
48			-- start the event loop. The event loop executes registred
49			-- behavior for user actions.
50			-- It will stop when break is called (vision.loop_stack.break).
51			vision.start
52			io.put_string("The end%N")
53		end
54
55feature {}
56	background (c: COLOR) is
57		do
58			toplevel_window.set_background_color(c)
59			toplevel_window.refresh
60		end
61
62	border (i: INTEGER) is
63		do
64			if column_layout.border + i >= 0 then
65				column_layout.set_border(column_layout.border + i)
66			end
67		end
68
69end -- class BASIC_EVENTS