2
# simple scrollable canvas widget demo (called by 'widget')
5
# toplevel widget ��¸�ߤ���к������
6
if defined?($cscroll_demo) && $cscroll_demo
11
# demo �Ѥ� toplevel widget ������
12
$cscroll_demo = TkToplevel.new {|w|
13
title("Scrollable Canvas Demonstration")
19
TkLabel.new($cscroll_demo, 'font'=>$font, 'wraplength'=>'4i',
20
'justify'=>'left', 'text'=>"���Υ�����ɥ��ˤϥ���������С���ޥ����Υܥ���2 �ǥ���������Ǥ��륭���Х� widget ��ɽ������Ƥ��ޤ����ͳѤξ�ǥܥ���1 ��å�����ȡ����Υ���ǥå�����ɸ����Ϥ˽��Ϥ���ޤ���"){
25
$cscroll_buttons = TkFrame.new($cscroll_demo) {|frame|
30
tmppath = $cscroll_demo
34
}.pack('side'=>'left', 'expand'=>'yes')
38
command proc{showCode 'cscroll'}
39
}.pack('side'=>'left', 'expand'=>'yes')
41
$cscroll_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
44
unless $tk_version =~ /^4\.[01]/
45
$cscroll_grid = TkFrame.new($cscroll_demo) {
46
pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)
48
TkGrid.rowconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0)
49
TkGrid.columnconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0)
53
$cscroll_canvas = TkCanvas.new($cscroll_demo,
54
'relief'=>'sunken', 'borderwidth'=>2,
55
'scrollregion'=>['-11c', '-11c', '50c', '20c']
57
if $tk_version =~ /^4\.[01]/
58
pack('expand'=>'yes', 'fill'=>'both')
60
grid('in'=>$cscroll_grid, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>0,
61
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
64
TkScrollbar.new($cscroll_demo, 'command'=>proc{|*args| c.yview(*args)}) {|vs|
65
c.yscrollcommand(proc{|first,last| vs.set first,last})
66
if $tk_version =~ /^4\.[01]/
67
pack('side'=>'right', 'fill'=>'y')
69
grid('in'=>$cscroll_grid, 'padx'=>1, 'pady'=>1, 'row'=>0, 'column'=>1,
70
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
74
TkScrollbar.new($cscroll_demo, 'orient'=>'horiz',
75
'command'=>proc{|*args| c.xview(*args)}) {|hs|
76
c.xscrollcommand(proc{|first,last| hs.set first,last})
77
if $tk_version =~ /^4\.[01]/
78
pack('side'=>'bottom', 'fill'=>'x')
80
grid('in'=>$cscroll_grid, 'padx'=>1, 'pady'=>1, 'row'=>1, 'column'=>0,
81
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
86
bg = $cscroll_canvas.configinfo('bg')[4]
91
TkcRectangle.new($cscroll_canvas, "#{x}c", "#{y}c", "#{x+2}c", "#{y+2}c",
92
'outline'=>'black', 'fill'=>bg, 'tags'=>'rect')
93
TkcText.new($cscroll_canvas, "#{x+1}c", "#{y+1}c",
94
'text'=>"#{i},#{j}", 'anchor'=>'center', 'tags'=>'text')
99
$cscroll_canvas.itembind('all', 'Any-Enter', proc{scrollEnter $cscroll_canvas})
100
$cscroll_canvas.itembind('all', 'Any-Leave', proc{scrollLeave $cscroll_canvas})
101
$cscroll_canvas.itembind('all', '1', proc{scrollButton $cscroll_canvas})
102
$cscroll_canvas.itembind('all', 'Any-Enter', proc{scrollEnter $cscroll_canvas})
103
$cscroll_canvas.bind('2', proc{|x,y| $cscroll_canvas.scan_mark(x,y)}, '%x %y')
104
$cscroll_canvas.bind('B2-Motion',
105
proc{|x,y| $cscroll_canvas.scan_dragto(x,y)}, '%x %y')
108
id = c.find_withtag('current')[0].id
109
id -= 1 if c.gettags('current').include?('text')
110
$oldFill = c.itemconfiginfo(id, 'fill')[4]
111
if TkWinfo.depth(c) > 1
112
c.itemconfigure(id, 'fill'=>'SeaGreen1')
114
c.itemconfigure(id, 'fill'=>'black')
115
c.itemconfigure(id+1, 'fill'=>'white')
120
id = c.find_withtag('current')[0].id
121
id -= 1 if c.gettags('current').include?('text')
122
c.itemconfigure(id, 'fill'=>$oldFill)
123
c.itemconfigure(id+1, 'fill'=>'black')
127
id = c.find_withtag('current')[0].id
128
id += 1 unless c.gettags('current').include?('text')
129
print "You buttoned at #{c.itemconfiginfo(id,'text')[4]}\n"