goocanvas 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
- require 'goocanvas'
2
+ #
3
+ # This sample code is a port of
4
+ # goocanvas/demo/scalability-demo.c. It is licensed
5
+ # under the terms of the GNU Library General Public License, version
6
+ # 2 or (at your option) later.
7
+ #
8
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
9
+ #
10
+ # This library is free software; you can redistribute it and/or
11
+ # modify it under the terms of the GNU Lesser General Public
12
+ # License as published by the Free Software Foundation; either
13
+ # version 2.1 of the License, or (at your option) any later version.
14
+ #
15
+ # This library is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ # Lesser General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU Lesser General Public
21
+ # License along with this library; if not, write to the Free Software
22
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
+
24
+ require "goocanvas"
3
25
 
4
26
  # the values behind the comments are the ones used in the C version
5
27
  # but as with them it takes more than 20 sec on my computer for the window
@@ -19,7 +41,7 @@ def setup_canvas(canvas)
19
41
 
20
42
  item_width = 400
21
43
  item_height = 19
22
-
44
+
23
45
  cell_width = item_width + PADDING * 2
24
46
  cell_height = item_height + PADDING * 2
25
47
 
@@ -36,12 +58,16 @@ def setup_canvas(canvas)
36
58
  style = Goo::CanvasStyle.new
37
59
  color = Gdk::Color.parse("mediumseagreen")
38
60
  pattern = Cairo::SolidPattern.new(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0)
39
- style.fill_pattern = pattern
61
+ # NOTE: "Goo::CanvasStyle#fill_pattern=" doesn't work. (undefined method)
62
+ # Substitution is "Goo::CanvasRect#fill_color=".
63
+ #style.fill_pattern = pattern
40
64
 
41
65
  style2 = Goo::CanvasStyle.new
42
66
  color = Gdk::Color.parse("steelblue")
43
67
  pattern = Cairo::SolidPattern.new(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0)
44
- style2.fill_pattern = pattern
68
+ # NOTE: "Goo::CanvasStyle#fill_pattern=" doesn't work. (undefined method)
69
+ # Substitution is "Goo::CanvasRect#fill_color=".
70
+ #style2.fill_pattern = pattern
45
71
 
46
72
  total_items = 0
47
73
 
@@ -50,10 +76,10 @@ def setup_canvas(canvas)
50
76
  group_x = left_offset + (group_i * group_width);
51
77
  group_y = top_offset + (group_j * group_height);
52
78
 
53
- group = Goo::CanvasGroup.new(root)
79
+ group = Goo::CanvasGroup.new(:parent => root)
54
80
  total_items += 1
55
81
  group.translate(group_x, group_y)
56
-
82
+
57
83
  N_COLS.times do |i|
58
84
  N_ROWS.times do |j|
59
85
  item_x = (i * cell_width) + PADDING
@@ -61,21 +87,32 @@ def setup_canvas(canvas)
61
87
  rotation = i % 10 * 2
62
88
  rotation_x = item_x + item_width / 2
63
89
  rotation_y = item_y + item_height / 2
64
-
90
+
65
91
  current_id = "#{group_x + item_x}, #{group_y + item_y}"
66
-
67
- item = Goo::CanvasRect.new(group, item_x, item_y, item_width, item_height)
68
- item.style = (j % 2) == 1 ? style : style2
92
+
93
+ item = Goo::CanvasRect.new(:parent => group,
94
+ :x => item_x,
95
+ :y => item_y,
96
+ :width => item_width,
97
+ :height => item_height)
98
+ # NOTE: "Goo::CanvasStyle#fill_pattern=" doesn't work. (undefined method)
99
+ # "Goo::CanvasRect#fill_color=" is substitution.
100
+ item.fill_color = (j % 2) == 1 ? "mediumseagreen" : "steelblue"
101
+ #item.style = (j % 2) == 1 ? style : style2
69
102
  item.rotate(rotation, rotation_x, rotation_y)
70
-
103
+
71
104
  item.signal_connect('motion_notify_event') do
72
105
  puts "#{current_id} item received 'motion-notify' signal"
73
106
  end
74
107
 
75
- item = Goo::CanvasText.new(group, current_id,
76
- item_x + item_width / 2, item_y + item_height / 2, -1, Gtk::ANCHOR_CENTER)
108
+ item = Goo::CanvasText.new(:parent => group,
109
+ :text => current_id,
110
+ :x => item_x + item_width / 2,
111
+ :y => item_y + item_height / 2,
112
+ :width => -1,
113
+ :anchor => Goo::CanvasAnchorType::CENTER)
77
114
  item.rotate(rotation, rotation_x, rotation_y)
78
-
115
+
79
116
  total_items += 2
80
117
  break if ONLY_ONE
81
118
  end
@@ -94,7 +131,7 @@ def create_canvas
94
131
  # Create the canvas.
95
132
  canvas = Goo::Canvas.new
96
133
  canvas.set_size_request(600, 450)
97
-
134
+
98
135
  start = Time.new
99
136
  total_width, total_height, left_offset, top_offset = setup_canvas(canvas)
100
137
  puts "Create Canvas Time Used: #{Time.new - start}"
@@ -104,18 +141,18 @@ def create_canvas
104
141
  canvas.show
105
142
 
106
143
  first_time = true
107
- canvas.signal_connect("expose_event") do
144
+ canvas.signal_connect("draw") do
108
145
  if first_time
109
146
  puts "Update Canvas Time Used: #{Time.new - start}"
110
147
  first_time = false
111
148
  end
112
149
  false
113
150
  end
114
-
151
+
115
152
  canvas
116
153
  end
117
154
 
118
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
155
+ window = Gtk::Window.new(:toplevel)
119
156
  window.set_default_size(640, 600)
120
157
  window.show
121
158
  window.signal_connect('delete_event') { Gtk.main_quit }
@@ -124,7 +161,9 @@ scrolled_win = Gtk::ScrolledWindow.new
124
161
  scrolled_win.show
125
162
  window.add(scrolled_win)
126
163
 
164
+ GC.disable
127
165
  canvas = create_canvas
128
166
  scrolled_win.add(canvas)
167
+ GC.enable
129
168
 
130
169
  Gtk.main
@@ -21,9 +21,7 @@
21
21
  # License along with this library; if not, write to the Free Software
22
22
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
23
 
24
- require 'goocanvas-gi'
25
-
26
- Goo.init
24
+ require 'goocanvas'
27
25
 
28
26
  # Create the window and widgets.
29
27
  window = Gtk::Window.new(:toplevel)
@@ -1,5 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
- require 'goocanvas'
2
+ #
3
+ # This sample code is a port of
4
+ # goocanvas/demo/table-demo.c. It is licensed
5
+ # under the terms of the GNU Library General Public License, version
6
+ # 2 or (at your option) later.
7
+ #
8
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
9
+ #
10
+ # This library is free software; you can redistribute it and/or
11
+ # modify it under the terms of the GNU Lesser General Public
12
+ # License as published by the Free Software Foundation; either
13
+ # version 2.1 of the License, or (at your option) any later version.
14
+ #
15
+ # This library is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ # Lesser General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU Lesser General Public
21
+ # License along with this library; if not, write to the Free Software
22
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
+
24
+ require "goocanvas"
25
+
3
26
  DEMO_RECT_ITEM = 0
4
27
  DEMO_TEXT_ITEM = 1
5
28
  DEMO_WIDGET_ITEM = 2
@@ -7,16 +30,37 @@ DEMO_WIDGET_ITEM = 2
7
30
  def create_demo_item(table, demo_item_type, row, column, rows, columns, text)
8
31
  case demo_item_type
9
32
  when DEMO_RECT_ITEM
10
- item = Goo::CanvasRect.new(table, 0, 0, 38, 19, :fill_color => 'red')
33
+ item = Goo::CanvasRect.new(:parent => table,
34
+ :x => 0,
35
+ :y => 0,
36
+ :width => 38,
37
+ :height => 19,
38
+ :fill_color => "red")
11
39
  when DEMO_TEXT_ITEM
12
- item = Goo::CanvasText.new(table, text, 0, 0, -1, Gtk::ANCHOR_NW, nil)
40
+ item = Goo::CanvasText.new(:parent => table,
41
+ :text => text,
42
+ :x => 0,
43
+ :y => 0,
44
+ :width => -1,
45
+ :anchor => :nw)
13
46
  when DEMO_WIDGET_ITEM
14
- widget = Gtk::Button.new(text)
15
- item = Goo::CanvasWidget.new(table, widget, 0, 0, -1, -1)
47
+ widget = Gtk::Button.new(:label => text)
48
+ item = Goo::CanvasWidget.new(:parent => table,
49
+ :widget => widget,
50
+ :x => 0,
51
+ :y => 0,
52
+ :width => -1,
53
+ :height => -1)
16
54
  end
17
55
 
18
- table.set_child_properties(item, :row => row, :column => column, :rows => rows, :columns => columns,
19
- :x_expand => true, :x_fill => true, :y_expand => true, :y_fill => true)
56
+ table.set_child_property(item, "row", row)
57
+ table.set_child_property(item, "column", column)
58
+ table.set_child_property(item, "rows", rows)
59
+ table.set_child_property(item, "columns", columns)
60
+ table.set_child_property(item, "x-expand", true)
61
+ table.set_child_property(item, "x-fill", true)
62
+ table.set_child_property(item, "y-expand", true)
63
+ table.set_child_property(item, "y-fill", true)
20
64
 
21
65
  item.signal_connect('button_press_event') do |item, target, event|
22
66
  puts "#{text} received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
@@ -26,13 +70,20 @@ end
26
70
 
27
71
  def create_table(parent, row, column, embedding_level, x, y, rotation, scale, demo_item_type)
28
72
  # Add a few simple items.
29
- table = Goo::CanvasTable.new(parent, :row_spacing => 4.0, :column_spacing => 4.0)
73
+ table = Goo::CanvasTable.new(:parent => parent,
74
+ :row_spacing => 4.0,
75
+ :column_spacing => 4.0)
30
76
 
31
77
  table.translate(x, y)
32
78
  table.rotate(rotation, 0, 0)
33
79
  table.scale(scale, scale)
34
80
 
35
- parent.set_child_properties(table, :row => row, :column => column, :x_expand => true, :x_fill => true) if row
81
+ if row
82
+ parent.set_child_property(table, "row", row)
83
+ parent.set_child_property(table, "column", column)
84
+ parent.set_child_property(table, "x-expand", true)
85
+ parent.set_child_property(table, "x_fill", true)
86
+ end
36
87
 
37
88
  if embedding_level > 0
38
89
  level = embedding_level - 1
@@ -60,51 +111,81 @@ def create_table(parent, row, column, embedding_level, x, y, rotation, scale, de
60
111
  end
61
112
 
62
113
  def create_demo_table(root, x, y, width, height)
63
- table = Goo::CanvasTable.new(root, :row_spacing => 4.0, :column_spacing => 4.0, :width => width, :height => height)
114
+ table = Goo::CanvasTable.new(:parent => root,
115
+ :row_spacing => 4.0,
116
+ :column_spacing => 4.0,
117
+ :width => width,
118
+ :height => height)
64
119
  table.translate(x, y)
65
120
 
66
- square = Goo::CanvasRect.new(table, 0.0, 0.0, 50.0, 50.0, :fill_color => 'red')
67
- table.set_child_properties(square, :row => 0, :column => 0, :x_shrink => true)
121
+ square = Goo::CanvasRect.new(:parent => table,
122
+ :x => 0.0,
123
+ :y => 0.0,
124
+ :width => 50.0,
125
+ :height => 50.0,
126
+ :fill_color => "red")
127
+ table.set_child_property(square, "row", 0)
128
+ table.set_child_property(square, "column", 0)
129
+ table.set_child_property(square, "x_shrink", true)
68
130
  square.signal_connect('button_press_event') do |item, target, event|
69
131
  puts "Red square received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
70
132
  true
71
133
  end
72
134
 
73
- circle = Goo::CanvasEllipse.new(table, 0.0, 0.0, 25.0, 25.0, :fill_color => 'blue')
74
- table.set_child_properties(circle, :row => 0, :column => 1, :x_shrink => true)
135
+ circle = Goo::CanvasEllipse.new(:parent => table,
136
+ :x => 0.0,
137
+ :y => 0.0,
138
+ :radius_x => 25.0,
139
+ :radius_y => 25.0,
140
+ :fill_color => "blue")
141
+ table.set_child_property(circle, "row", 0)
142
+ table.set_child_property(circle, "column", 1)
143
+ table.set_child_property(circle, "x_shrink", true)
75
144
  circle.signal_connect('button_press_event') do |item, target, event|
76
145
  puts "Blue circle received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
77
146
  true
78
147
  end
79
148
 
80
- triangle = Goo::CanvasPolyline.new(table, true, [ [ 25.0, 0.0], [ 0.0, 50.0 ], [ 50.0, 50.0 ] ], :fill_color => "yellow")
81
- table.set_child_properties(triangle, :row => 0, :column => 2, :x_shrink => true)
149
+ points = Goo::CanvasPoints.new(3)
150
+ points.set_point(0, 25.0, 0.0)
151
+ points.set_point(1, 0.0, 50.0)
152
+ points.set_point(2, 50.0, 50.0)
153
+ triangle = Goo::CanvasPolyline.new(:parent => table,
154
+ :close_path => true,
155
+ :points => points,
156
+ :fill_color => "yellow")
157
+ table.set_child_property(triangle, "row", 0)
158
+ table.set_child_property(triangle, "column", 2)
159
+ table.set_child_property(triangle, "x_shrink", true)
82
160
  triangle.signal_connect('button_press_event') do |item, target, event|
83
161
  puts "Yellow triangle received 'button-press' signal at #{event.x}, #{event.y} (root: #{event.x_root}, #{event.y_root})"
84
162
  true
85
163
  end
86
164
  end
87
165
 
88
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
166
+ window = Gtk::Window.new(:toplevel)
89
167
  window.set_default_size(640, 600)
90
168
  window.signal_connect('delete_event') { Gtk.main_quit }
91
169
 
92
- vbox = Gtk::VBox.new(false, 4)
170
+ vbox = Gtk::Box.new(:vertical, 4)
93
171
  vbox.border_width = 4
94
172
  vbox.show
95
173
  window.add(vbox)
96
174
 
97
- hbox = Gtk::HBox.new(false, 4)
98
- vbox.pack_start(hbox, false, false, 0)
175
+ hbox = Gtk::Box.new(:horizontal, 4)
176
+ vbox.pack_start(hbox, :expand => false,
177
+ :fill => false,
178
+ :padding => 0)
99
179
  hbox.show
100
180
 
101
181
  scrolled_win = Gtk::ScrolledWindow.new
102
- scrolled_win.shadow_type = Gtk::SHADOW_IN
182
+ scrolled_win.shadow_type = :in
103
183
  scrolled_win.show
104
- vbox.pack_start(scrolled_win, true, true, 0)
184
+ vbox.pack_start(scrolled_win, :expand => true,
185
+ :fill => true,
186
+ :padding => 0)
105
187
 
106
188
  canvas = Goo::Canvas.new
107
- canvas.flags = Gtk::Widget::CAN_FOCUS
108
189
  canvas.set_size_request(600, 450)
109
190
  canvas.set_bounds(0, 0, 1000, 1000)
110
191
  scrolled_win.add(canvas)
@@ -21,9 +21,7 @@
21
21
  # License along with this library; if not, write to the Free Software
22
22
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
23
 
24
- require 'goocanvas-gi'
25
-
26
- Goo.init
24
+ require 'goocanvas'
27
25
 
28
26
  DATA = {
29
27
  :pixel => [ 100, 100, 200, 20, 10, 200, 310, 24 ],
@@ -1,5 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
- require 'goocanvas'
2
+ #
3
+ # This sample code is a port of
4
+ # goocanvas/demo/widgets-demo.c. It is licensed
5
+ # under the terms of the GNU Library General Public License, version
6
+ # 2 or (at your option) later.
7
+ #
8
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
9
+ #
10
+ # This library is free software; you can redistribute it and/or
11
+ # modify it under the terms of the GNU Lesser General Public
12
+ # License as published by the Free Software Foundation; either
13
+ # version 2.1 of the License, or (at your option) any later version.
14
+ #
15
+ # This library is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ # Lesser General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU Lesser General Public
21
+ # License along with this library; if not, write to the Free Software
22
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
+
24
+ require "goocanvas"
3
25
 
4
26
  num_added_widgets = 0
5
27
  added_widget_items = []
@@ -8,7 +30,15 @@ move_item = nil
8
30
 
9
31
  def create_focus_box(canvas, x, y, width, height, color)
10
32
  root = canvas.root_item
11
- item = Goo::CanvasRect.new(root, x, y, width, height, :stroke_pattern => nil, :fill_color => color, :line_width => 5.0, :can_focus => true)
33
+ item = Goo::CanvasRect.new(:parent => root,
34
+ :x => x,
35
+ :y => y,
36
+ :width => width,
37
+ :height => height,
38
+ :stroke_pattern => nil,
39
+ :fill_color => color,
40
+ :line_width => 5.0,
41
+ :can_focus => true)
12
42
 
13
43
  item.signal_connect('focus_in_event') do
14
44
  puts "#{color} received focus-in event"
@@ -39,25 +69,29 @@ def create_focus_box(canvas, x, y, width, height, color)
39
69
  end
40
70
 
41
71
  def add_button(hbox, button_name, &click_action)
42
- w = Gtk::Button.new(button_name)
43
- hbox.pack_start(w, false, false, 0)
72
+ w = Gtk::Button.new(:label => button_name)
73
+ hbox.pack_start(w, :expand => false,
74
+ :fill => false,
75
+ :padding => 0)
44
76
  w.show
45
77
  w.signal_connect('clicked', &click_action)
46
78
  end
47
79
 
48
80
  # Create the window and widgets.
49
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
81
+ window = Gtk::Window.new(:toplevel)
50
82
  window.set_default_size(640, 600)
51
83
  window.show
52
84
  window.signal_connect('delete_event') { Gtk.main_quit }
53
85
 
54
- vbox = Gtk::VBox.new(false, 4)
86
+ vbox = Gtk::Box.new(:vertical, 4)
55
87
  vbox.border_width = 4
56
88
  vbox.show
57
89
  window.add(vbox)
58
90
 
59
- hbox = Gtk::HBox.new(false, 4)
60
- vbox.pack_start(hbox, false, false, 0)
91
+ hbox = Gtk::Box.new(:horizontal, 4)
92
+ vbox.pack_start(hbox, :expand => false,
93
+ :fill => false,
94
+ :padding => 0)
61
95
  hbox.show
62
96
 
63
97
  add_button(hbox, 'Add Widget') do
@@ -68,7 +102,12 @@ add_button(hbox, 'Add Widget') do
68
102
  end
69
103
 
70
104
  root = canvas.root_item
71
- witem = Goo::CanvasWidget.new(root, widget, num_added_widgets * 50, num_added_widgets * 50, 200, 50, nil)
105
+ witem = Goo::CanvasWidget.new(:parent => root,
106
+ :widget => widget,
107
+ :x => num_added_widgets * 50,
108
+ :y => num_added_widgets * 50,
109
+ :width => 200,
110
+ :height => 50)
72
111
 
73
112
  added_widget_items.push(witem)
74
113
  num_added_widgets += 1
@@ -100,12 +139,14 @@ add_button(hbox, 'Move Widget') do
100
139
  end
101
140
 
102
141
  # here we have to do a little more complicated than in C because Ruby/Gtk+'s enums are not ints and we can't do + 1 on them
103
- moving_anchor = Gtk::ANCHOR_CENTER.to_i
142
+ moving_anchor = Goo::CanvasAnchorType::CENTER.to_i
104
143
  add_button(hbox, 'Change Anchor') do
105
- puts "Setting anchor to: #{Gtk::AnchorType.new(moving_anchor).name}"
144
+ puts "Setting anchor to: #{Goo::CanvasAnchorType.new(moving_anchor).name}"
106
145
  move_item.anchor = moving_anchor
107
146
  moving_anchor += 1
108
- moving_anchor = Gtk::ANCHOR_CENTER.to_i if moving_anchor > Gtk::ANCHOR_EAST.to_i
147
+ if moving_anchor > Goo::CanvasAnchorType::EAST.to_i
148
+ moving_anchor = Goo::CanvasAnchorType::CENTER.to_i
149
+ end
109
150
  end
110
151
 
111
152
  add_button(hbox, 'Change Widget') do
@@ -119,23 +160,26 @@ add_button(hbox, 'Change Widget') do
119
160
  end
120
161
  end
121
162
 
122
- hbox = Gtk::HBox.new(false, 4)
123
- vbox.pack_start(hbox, false, false, 0)
163
+ hbox = Gtk::Box.new(:horizontal, 4)
164
+ vbox.pack_start(hbox, :expand => false,
165
+ :fill => false,
166
+ :padding => 0)
124
167
  hbox.show
125
168
 
126
169
  add_button(hbox, 'Hide Canvas') { canvas.hide }
127
170
  add_button(hbox, 'Show Canvas') { canvas.show }
128
- add_button(hbox, 'Hide Item') { move_item.visibility = Goo::CanvasItem::INVISIBLE }
129
- add_button(hbox, 'Show Item') { move_item.visibility = Goo::CanvasItem::VISIBLE }
171
+ add_button(hbox, 'Hide Item') { move_item.visibility = :invisible }
172
+ add_button(hbox, 'Show Item') { move_item.visibility = :visible }
130
173
  add_button(hbox, 'Change Transform') { move_item.translate(25, 25) }
131
174
 
132
175
  scrolled_win = Gtk::ScrolledWindow.new
133
- scrolled_win.shadow_type = Gtk::SHADOW_IN
176
+ scrolled_win.shadow_type = :in
134
177
  scrolled_win.show
135
- vbox.pack_start(scrolled_win, true, true, 0)
178
+ vbox.pack_start(scrolled_win, :expand => true,
179
+ :fill => true,
180
+ :padding => 0)
136
181
 
137
182
  canvas = Goo::Canvas.new
138
- canvas.flags = Gtk::Widget::CAN_FOCUS
139
183
  canvas.set_size_request(600, 450)
140
184
  canvas.set_bounds(0, 0, 1000, 1000)
141
185
  scrolled_win.add(canvas)
@@ -144,47 +188,83 @@ root = canvas.root_item
144
188
 
145
189
  # Add a few simple items.
146
190
  label = Gtk::Label.new("Hello World")
147
- witem = Goo::CanvasWidget.new(root, label, 50, 50, 200, 100, nil)
191
+ witem = Goo::CanvasWidget.new(:parent => root,
192
+ :widget => label,
193
+ :x => 50,
194
+ :y => 50,
195
+ :width => 200,
196
+ :height => 100)
148
197
 
149
198
  entry = Gtk::Entry.new
150
- move_item = Goo::CanvasWidget.new(root, entry, 50, 250, 200, 50, nil)
199
+ move_item = Goo::CanvasWidget.new(:parent => root,
200
+ :widget => entry,
201
+ :x => 50,
202
+ :y => 250,
203
+ :width => 200,
204
+ :height => 50)
151
205
 
152
206
  entry = Gtk::Entry.new
153
207
  entry.text = "Size: -1 x -1"
154
- witem = Goo::CanvasWidget.new(root, entry, 50, 300, -1, -1, nil)
208
+ witem = Goo::CanvasWidget.new(:parent => root,
209
+ :widget => entry,
210
+ :x => 50,
211
+ :y => 300,
212
+ :width => -1,
213
+ :height => -1)
155
214
 
156
215
  entry = Gtk::Entry.new
157
216
  entry.text = "Size: 100 x -1"
158
- witem = Goo::CanvasWidget.new(root, entry, 50, 350, 100, -1, nil)
217
+ witem = Goo::CanvasWidget.new(:parent => root,
218
+ :widget => entry,
219
+ :x => 50,
220
+ :y => 350,
221
+ :width => 100,
222
+ :height => -1)
159
223
 
160
224
  # Use a textview so we can see the width & height of the widget.
161
225
  scrolled_win = Gtk::ScrolledWindow.new
162
- scrolled_win.shadow_type = Gtk::SHADOW_IN
163
- scrolled_win.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_NEVER)
226
+ scrolled_win.shadow_type = :in
227
+ scrolled_win.set_policy(:never, :never)
164
228
  textview = Gtk::TextView.new
165
229
  buffer = textview.buffer
166
230
  buffer.text = "Size: -1 x 100"
167
231
  textview.show
168
232
  scrolled_win.add(textview)
169
233
  scrolled_win.set_size_request(160, 50)
170
- witem = Goo::CanvasWidget.new(root, scrolled_win, 50, 400, -1, 100, nil)
234
+ witem = Goo::CanvasWidget.new(:parent => root,
235
+ :widget => scrolled_win,
236
+ :x => 50,
237
+ :y => 400,
238
+ :width => -1,
239
+ :height => 100)
171
240
 
172
241
  # Create a vbox item with several child entry widgets to check focus traversal.
173
- vbox = Gtk::VBox.new(false, 4)
242
+ vbox = Gtk::Box.new(:vertical, 4)
174
243
 
175
244
  entry = Gtk::Entry.new
176
245
  entry.show
177
- vbox.pack_start(entry, false, false, 0)
246
+ vbox.pack_start(entry, :expand => false,
247
+ :fill => false,
248
+ :padding => 0)
178
249
 
179
250
  entry = Gtk::Entry.new
180
251
  entry.show
181
- vbox.pack_start(entry, false, false, 0)
252
+ vbox.pack_start(entry, :expand => false,
253
+ :fill => false,
254
+ :padding => 0)
182
255
 
183
256
  entry = Gtk::Entry.new
184
257
  entry.show
185
- vbox.pack_start(entry, false, false, 0)
186
-
187
- witem = Goo::CanvasWidget.new(root, vbox, 50, 600, -1, -1, nil)
258
+ vbox.pack_start(entry, :expand => false,
259
+ :fill => false,
260
+ :padding => 0)
261
+
262
+ witem = Goo::CanvasWidget.new(:parent => root,
263
+ :widget => vbox,
264
+ :x => 50,
265
+ :y => 600,
266
+ :width => -1,
267
+ :height => -1)
188
268
 
189
269
  # Create a few normal canvas items that take keyboard focus.
190
270
  create_focus_box(canvas, 110, 80, 50, 30, 'red')