;;;;
;;;; grid1.stk                      -- Grid Demo
;;;;
;;;; Copyright © 2000-2021 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;;
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;;;; USA.
;;;;
;;;;           Author: Erick Gallesio [eg@unice.fr]
;;;;    Creation date:  3-Sep-2000 20:31 (eg)
;;;;

(include "demos-utils.stk")

(define msg "
A Grid Layout Demo

In this demo, you can see a set of buttons in a 5x4 grid.
By clicking on a button you'll see how it has been placed
in the layout widget.
")

(define (print-button button e)
  (let ((infos  (container-info button)))
    (format #t "You have clicked on ~A (#:x ~A #:y ~A #:width ~A #:height ~A)\n"
            (text button) (key-get infos #:x) (key-get infos #:y)
            (key-get infos #:width) (key-get infos #:height))))


(define (main  args)
  (let* ((win (make <demo-window> #:title "Grid Demo"
                                  #:file "grid1" #:border-width 5
                                  #:message msg))
         (grid (make <grid> #:parent win)))
    ;; Create the buttons
    (for-each (lambda (x)
                (apply (lambda (n x y w h)
                         (let ((b (make <button> #:text (format #f "button #~S" n)
                                        #:command print-button)))
                           (container-add! grid b
                                           #:left x #:top y
                                           #:width w #:height h
                                           #:pad-x 2 #:pad-y 2)))
                       x))
              '((1 0 0 4 1)
                (2 0 1 1 2)
                (3 1 1 1 1)
                (4 2 1 1 1)
                (5 1 2 1 1)
                (6 2 2 1 1)
                (7 3 1 1 2)
                (8 0 3 4 1)))
    (gtk-main)))




