Re: Resizing a widget



Thanks, I kinda thought it would be hard.

I've come up with this in mzgtk2 (the binding I'm writing).
You'll probably be able to recognize the widgets and function equivalents

(require (lib "mzgtk2.scm" "mzgtk2"))

(define w (gtk-window))
(define h (gtk-hbox))
(define l (gtk-layout))
(define e (gtk-entry))
(define v (gtk-vbox))
(define b
 (let ((width  60)
   (height 50)
   (toggle  #f))
   (letrec ((button (gtk-button 'label "_hi"
                'closure (lambda (widget)
                       (if toggle
                       (begin
                        (set! width (/ width 2))
                        (set! height (/ height 2)))
                         (begin
                          (set! width (* width 2))
                          (set! height (* height 2))))
                       (-> b set-size-request width height)
                       (-> v set-size-request width height)
                       (-> w size 1 1)
                       (set! toggle (not toggle)))
                'closure-widget button
                )))
       button)))

(-> v set-size-request 120 100)
(-> l put b 0 0)
(-> l set-size 120 100)
(-> v add l)

(-> h add e v)
(-> b set-size-request 40 40)
(-> w add h)

(-> w connect "delete-event" (lambda (w)
                  (-> w destroy)
                  (gtk-main-quit)))

(-> w show-all)
(gtk-main)


Tristan Van Berkom schreef:

Hans Oesterholt wrote:

Hello all,

In Gtk+ there is a function to set the size of a window.


The closest you'll get afaik is gtk_window_set_default_size(),
your window might end up bigger if any child widgets have
a larger "size request"

Is it also possible to resize a widget, *after* it has been
showed?


   You can always ask for a minimal widget size with
gtk_widget_set_size_request (i.e. widget-request/height-request
widget properties), but I am not aware of any way to make
your widgets shrink; since gtk+ works with relative coordinates
and resizable containers designed for the desktop; precise
widget sizes dont really fit into the philosophy. (ofcourse
there is GtkFixed, which is not good for use in desktop apps,
I'm not sure if you can achieve widget shrinking with that though).

Cheers,
                                -Tristan





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]