Re: width and height methods not dynamic?

From: Erick Gallesio <eg_at_kaolin.unice.fr>
Date: Mon, 17 Jun 1996 11:57:54 +0100

> Clifford Beshers writes
>
> I was surprised to learn that the width and height fields in a widget
> are not dynamic. This is not a bug in STk, but apparently part of the
> design of Tk. The only way I can find to get the actual geometry of a
> window seems to be with 'winfo geometry <widget>', which returns a X11
> geometry string.
>
> Is this the only way? Am I the only one who thinks this is completely
> brain-dead?
>
No you aren't...
Tk return the requested width and heiths of the objet rather than the real ones.
One way to make things simpler (in STklos) consists to create two virtual slots for accessing the current width and height. One way to implement this could be to modify the definition of <Tk-sizeable> in the file Basics.stk
For instance:
(define-class <Tk-sizeable> ()
  ((width :accessor width
               :init-keyword :width
               :allocation :tk-virtual)
   (height :accessor height
               :init-keyword :height
               :allocation :tk-virtual)
   (cur-width :accessor cur-width
               :init-keyword :cur-width
               :allocation :virtual
               :slot-ref (lambda (o)
                               (winfo 'width (slot-ref o 'Id)))
               :slot-set! (lambda (o v)
                               (error "Cannot set the current width of ~S to ~S"
                                       o v)))
   (cur-height :accessor cur-height
               :init-keyword :cur-height
               :allocation :virtual
               :slot-ref (lambda(o)
                               (winfo 'height (slot-ref o 'Id)))
               :slot-set! (lambda (o v)
                               (error "Cannot set the current height of ~S to ~S"
                                      o v))))
  :metaclass <Tk-metaclass>)

cur-width and cur-height give the current width and height in pixels
We have:
        STk> (define b (make <Button> :text "Hello"))
        #[undefined]
        STk> (pack b)
        ()
        STk> (width b)
        0
        STk> (cur-width b)
        61
However be careful:
        - if the object is not on screen cur-width would be 1.
        - cur-width is expressed in pixels whereas width, for some widgets, is
          expressed in chars
                STk> (set! (width b) 30)
                #[undefined]
                STk> (width b)
                30
                STk> (cur-width b)
                242
                STk>


                -- Erick
Received on Mon Jun 17 1996 - 11:57:55 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST