Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Scrolling canvases in LablTk 3.00
@ 2000-08-17  9:57 Fabien Fleutot
  2000-08-21  0:00 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Fabien Fleutot @ 2000-08-17  9:57 UTC (permalink / raw)
  To: caml-list

I can't figure how to add a scrollbar to a canvas; here is my code:

------------------------------------
 
open Tk
open Printf

let _ =
  let win = openTk() in
  let c = Canvas.create win ~width:2560 ~height:100 in
  let s = Scrollbar.create win ~orient:`Horizontal in

  (* draw clearer and clearer gray strips on the canvas. *)
  for i = 0 to 255 do
    let color = `Color (sprintf "#%02x%02x%02x" i i i) in
    ignore(Canvas.create_rectangle c ~x1:(i*10) ~x2:(i*10+10) ~y1:0 ~y2:99 
      ~fill:color)
  done ;

  Canvas.configure c ~xscrollcommand:(Scrollbar.set s) ;
  Scrollbar.configure s ~command:(Canvas.xview c) ;

  place c ~x:0 ~y:0;
  place s ~x:0 ~y:100 ~relwidth:1.;
  Wm.geometry_set win "300x125" ;
  mainLoop()

------------------------------------

The translator in the scrollbar uses 100% of the bar's width, instead of
(300/2560) = 11.7%.

using 'pack' intead of 'place' doesn't change amything, except that if I 
suppress the 'geometry_set', it creates a 2560 pixels wide window.

Does anybody know what's wrong with that piece of code ?





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Scrolling canvases in LablTk 3.00
  2000-08-17  9:57 Scrolling canvases in LablTk 3.00 Fabien Fleutot
@ 2000-08-21  0:00 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2000-08-21  0:00 UTC (permalink / raw)
  To: fabien.fleutot; +Cc: caml-list

> I can't figure how to add a scrollbar to a canvas; here is my code:
> 
> ------------------------------------
>  
> open Tk
> open Printf
> 
> let _ =
>   let win = openTk() in
>   let c = Canvas.create win ~width:2560 ~height:100 in
>   let s = Scrollbar.create win ~orient:`Horizontal in
> 
>   (* draw clearer and clearer gray strips on the canvas. *)
>   for i = 0 to 255 do
>     let color = `Color (sprintf "#%02x%02x%02x" i i i) in
>     ignore(Canvas.create_rectangle c ~x1:(i*10) ~x2:(i*10+10) ~y1:0 ~y2:99 
>       ~fill:color)
>   done ;
> 
>   Canvas.configure c ~xscrollcommand:(Scrollbar.set s) ;
>   Scrollbar.configure s ~command:(Canvas.xview c) ;
> 
>   place c ~x:0 ~y:0;
>   place s ~x:0 ~y:100 ~relwidth:1.;
>   Wm.geometry_set win "300x125" ;
>   mainLoop()
> 
> ------------------------------------

You should use the ~scrollregion option:
  Canvas.create win ~width:300 ~height:100 ~scrollregion:(0,0,2560,100)

Then you don't need the Wm.geometry_set anymore.

---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-08-21  9:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-17  9:57 Scrolling canvases in LablTk 3.00 Fabien Fleutot
2000-08-21  0:00 ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox