R. Mark Volkmann
12/5/2004 3:45:00 PM
----- Original Message -----
From: "Hidetoshi NAGAI" <nagai@ai.kyutech.ac.jp>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Sunday, December 05, 2004 2:09 AM
Subject: Re: Tk scrolled canvas
> Hi,
>
> From: "R. Mark Volkmann" <mark@ociweb.com>
> Subject: Tk scrolled canvas
> Date: Sun, 5 Dec 2004 12:17:01 +0900
> Message-ID: <05b101c4da78$e39092d0$0200a8c0@MarkDesktop>
>> I think I should be able to create a scrolled canvas like this, but it
>> doesn't work.
>
> Please define the widget class which you want. ;-)
I don't understand why I have to write my own TkScrolledCanvas class.
Why doesn't a scrolled canvas already exist?
It is discussed in the book "Learning Perl/Tk" on the first page of chapter
9.
The author says you can either create a plain "Canvas" or a "Scrolled" which
is a scrollable Canvas.
> See sample scripts at ext/tk/samples directory of Ruby source archive.
>
> If refer to ext/tk/samples/tktextframe.rb,
> TkScrolledCanvas can be defined as such as the following.
> ---------------------------------------------------------------------
> #!/usr/bin/env ruby
> require 'tk'
>
> class TkScrolledCanvas < TkCanvas
> include TkComposite
>
> def initialize_composite(keys={})
> @h_scr = TkScrollbar.new(@frame)
> @v_scr = TkScrollbar.new(@frame)
>
> @canvas = TkCanvas.new(@frame)
> @path = @canvas.path
>
> @canvas.xscrollbar(@h_scr)
> @canvas.yscrollbar(@v_scr)
>
> TkGrid.rowconfigure(@frame, 0, :weight=>1, :minsize=>0)
> TkGrid.columnconfigure(@frame, 0, :weight=>1, :minsize=>0)
>
> @canvas.grid(:row=>0, :column=>0, :sticky=>'news')
> @h_scr.grid(:row=>1, :column=>0, :sticky=>'ew')
> @v_scr.grid(:row=>0, :column=>1, :sticky=>'ns')
>
> delegate('DEFAULT', @canvas)
> delegate('background', @text, @h_scr, @v_scr)
> delegate('activeforeground', @h_scr, @v_scr)
> delegate('troughcolor', @h_scr, @v_scr)
> delegate('repeatdelay', @h_scr, @v_scr)
> delegate('repeatinterval', @h_scr, @v_scr)
> delegate('borderwidth', @frame)
> delegate('relief', @frame)
>
> delegate_alias('canvasborderwidth', 'borderwidth', @canvas)
> delegate_alias('canvasrelief', 'relief', @canvas)
>
> delegate_alias('scrollbarborderwidth', 'borderwidth', @h_scr, @v_scr)
> delegate_alias('scrollbarrelief', 'relief', @h_scr, @v_scr)
>
> configure(keys) unless keys.empty?
> end
> end
>
> c = TkScrolledCanvas.new(:scrollregion=>[0,0,500,400]).pack
> TkcRectangle.new(c, [100,100], [300, 200])
>
> Tk.mainloop
> ---------------------------------------------------------------------
> --
> Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
>
>