T. Kurt Bond (that would be me) wrote:
> I noticed that all the ?width options and ?height options for things
> like Label.create and Canvas.create have type int; Why don't these
> actually have type Tk.units so that one can specify them in any of the
> normal Tk screen units: Inches, Millimeters, Centimeters, Points, or
> Pixels, just like you can using raw Tcl/Tk or OcamlTk ?
Jacques Garrigue writes:
> The answer is in the LablTk section of the manual:
>
> 27.1 Module Tk: basic functions and types for LablTk
> Dimensions
> type units = [`Pix int|`Cm float|`In float|`Mm float|`Pt float]
> val pixels : units -> int
> Converts various on-screen units to pixels, respective to the
> default display. Available units are pixels, centimeters, inches,
> millimeters and points
Yes, I'd found Tk.pixels.
> Having to write units always explicitly was just a pain. This way you
> can either write directly in pixels, or convert from another unit.
I guess it's a matter of taste; I always found it helpful that it
encouraged one to use screen-independent values like points instead of
pixels, and I didn't mind specifying the units. Actually, since I
rarely specify raw pixel values in code, the conversion using
one of the pixels functions is actually more annoying, since I have to
write, for instance, (pixels (`Pt 72)) instead of just (`Pt 72).
> There is a very small glitch: if your application is intended to run
> on several displays with different dpi's, you must use the
> Winfo.pixels or Winfo.fpixels functions.
That's a good point I hadn't thought about.
Anyway, thanks for the explanation.
(I found out it's easy enough to switch, btw, even though I don't
fully understand tkcompiler: just change the definitions of "option
Height" and "option Width" in Widgets.src from [_; int] to [_;units]
and change one place in ocamlbrowser, I think, and everything seems to
recompile and work ok. I'll leave it alone, though, since it's the
intended behavior.)
-- T. Kurt Bond, tkb@tkb.mpl.com
This archive was generated by hypermail 2b29 : Fri Apr 28 2000 - 12:12:39 MET DST