PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/tutorial/vision/layout/fixed_widgets.e

http://github.com/tybor/Liberty
Specman e | 116 lines | 91 code | 15 blank | 10 comment | 0 complexity | ae2a4160c6f5946c1e9191cd97a4a178 MD5 | raw file
  1class FIXED_WIDGETS
  2--
  3-- This example show how standards layouts (row/column) handle fixed size widgets.
  4--
  5-- See also WIDGET for more information on size.
  6--
  7	
  8inherit
  9	GRAPHIC
 10
 11creation {ANY}
 12	make
 13
 14feature {}
 15	toplevel_window: TOPLEVEL_WINDOW
 16
 17	layouts: ARRAY[ROW_LAYOUT]
 18
 19	make is
 20		local
 21			container: CONTAINER; one, two, three: UNICODE_STRING
 22		do
 23			one := U"Button ONE"
 24			two := U"Button TWO"
 25			three := U"Button THREE"
 26			create toplevel_window
 27			-- The default layout is column.
 28			toplevel_window.set_title("Buttons example")
 29			toplevel_window.set_background_color(white_color)
 30			toplevel_window.map
 31			create layouts.make(1, 0)
 32			
 33			-- First line: 3 buttons, automatically spaced
 34			container := new_container
 35			new_button(container, one)
 36			new_button(container, two)
 37			new_button(container, three)
 38			
 39			-- Second line: 1 space before the 3 buttons
 40			container := new_container
 41			layouts.last.insert_button_space
 42			new_button(container, one)
 43			new_button(container, two)
 44			new_button(container, three)
 45			
 46			-- Third line: 2 spaces (at the begining and at the end)
 47			container := new_container
 48			layouts.last.insert_button_space
 49			new_button(container, one)
 50			new_button(container, two)
 51			new_button(container, three)
 52			layouts.last.insert_button_space
 53			
 54			-- Fourth line: 1 space to separate buttons in 2 groups
 55			container := new_container
 56			new_button(container, one)
 57			layouts.last.insert_button_space
 58			new_button(container, two)
 59			new_button(container, three)
 60			toplevel_window.when_left_down(agent increase_border)
 61			toplevel_window.when_right_down(agent increase_spacing)
 62			toplevel_window.when_middle_down(agent vision.loop_stack.break)
 63			
 64			vision.start
 65			io.put_string("The end%N")
 66		end
 67
 68	new_container: CONTAINER is
 69		local
 70			layout: ROW_LAYOUT
 71		do
 72			create layout
 73			layouts.add_last(layout)
 74			create Result.make_layout(toplevel_window, layout)
 75			Result.set_x_expand(True)
 76			Result.set_y_expand(True)
 77		end
 78
 79	increase_border is
 80		local
 81			i: INTEGER
 82		do
 83			from
 84				i := layouts.lower
 85			until
 86				i > layouts.upper
 87			loop
 88				layouts.item(i).set_border(layouts.item(i).border + 1)
 89				i := i + 1
 90			end
 91		end
 92
 93	increase_spacing is
 94		local
 95			i: INTEGER
 96		do
 97			from
 98				i := layouts.lower
 99			until
100				i > layouts.upper
101			loop
102				layouts.item(i).set_spacing(layouts.item(i).spacing + 1)
103				i := i + 1
104			end
105		end
106
107	new_button (container: CONTAINER; text: UNICODE_STRING) is
108		local
109			button: BUTTON
110		do
111			create button.with_label(container, text)
112			button.when_left_clicked(agent io.put_string(once "Left click on %"" + text.to_utf8 + once "%"%N"))
113			button.when_right_clicked(agent vision.loop_stack.break)
114		end
115
116end -- class FIXED_WIDGETS