From 32ae3f83080ab625f0bcfdf907e3682a2da9f36b Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 24 Aug 2014 07:18:45 -0600 Subject: [PATCH] racket/gui: change placement of children in `panel%` and `pane%` The `panel%` and `pane%` classes were not originally intended for direct instantiation; instead, `horizontal-pane[l]%` and `vertical-pane[l]%` provide basic placements that make sense for multiple children. Adjusting `pane[l]%` to just overlay all children seems both sensible and useful (if only one child is shown at a time, for example). As suggested by David Nelson. --- .../gui-doc/scribblings/gui/pane-class.scrbl | 11 ++++++-- .../gui-doc/scribblings/gui/panel-class.scrbl | 12 +++++--- pkgs/gui-pkgs/gui-lib/info.rkt | 2 +- .../gui-pkgs/gui-lib/mred/private/wxpanel.rkt | 28 +++++++++++++++++-- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/pkgs/gui-pkgs/gui-doc/scribblings/gui/pane-class.scrbl b/pkgs/gui-pkgs/gui-doc/scribblings/gui/pane-class.scrbl index 76ab43f2c8..528f733037 100644 --- a/pkgs/gui-pkgs/gui-doc/scribblings/gui/pane-class.scrbl +++ b/pkgs/gui-pkgs/gui-doc/scribblings/gui/pane-class.scrbl @@ -8,12 +8,17 @@ A pane is a both a container and a containee area. It serves only cannot be hidden or disabled like a @racket[panel%] object. A @racket[pane%] object has a degenerate placement strategy for - managing its children; it places them all in the upper left corner - and does not stretch any of them. The @racket[horizontal-pane%] and - @racket[vertical-pane%] classes provide useful geometry management. + managing its children: it places each child as if it was the only + child of the panel. The @racket[horizontal-pane%] and + @racket[vertical-pane%] classes provide useful geometry management + for multiple children. See also @racket[grow-box-spacer-pane%]. +@history[#:changed "1.3" @elem{Changed the placement strategy to + stretch and align children, instead of + placing all children at the top-left + corner.}] @defconstructor[([parent (or/c (is-a?/c frame%) (is-a?/c dialog%) (is-a?/c panel%) (is-a?/c pane%))] diff --git a/pkgs/gui-pkgs/gui-doc/scribblings/gui/panel-class.scrbl b/pkgs/gui-pkgs/gui-doc/scribblings/gui/panel-class.scrbl index dbe78b79f1..625c7b2389 100644 --- a/pkgs/gui-pkgs/gui-doc/scribblings/gui/panel-class.scrbl +++ b/pkgs/gui-pkgs/gui-doc/scribblings/gui/panel-class.scrbl @@ -11,11 +11,15 @@ A panel is a both a container and a containee window. It serves mainly object can be hidden or disabled. A @racket[panel%] object has a degenerate placement strategy for - managing its children; it places them all in the upper left corner - and does not stretch any of them. The @racket[horizontal-panel%] - and @racket[vertical-panel%] classes provide useful geometry - management. + managing its children: it places each child as if it was the only + child of the panel. The @racket[horizontal-panel%] and + @racket[vertical-panel%] classes provide useful geometry management + for multiple children. +@history[#:changed "1.3" @elem{Changed the placement strategy to + stretch and align children, instead of + placing all children at the top-left + corner.}] @defconstructor[([parent (or/c (is-a?/c frame%) (is-a?/c dialog%) (is-a?/c panel%) (is-a?/c pane%))] diff --git a/pkgs/gui-pkgs/gui-lib/info.rkt b/pkgs/gui-pkgs/gui-lib/info.rkt index bdbbeb1932..b5937687ff 100644 --- a/pkgs/gui-pkgs/gui-lib/info.rkt +++ b/pkgs/gui-pkgs/gui-lib/info.rkt @@ -29,4 +29,4 @@ (define pkg-authors '(mflatt robby)) -(define version "1.2") +(define version "1.3") diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wxpanel.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wxpanel.rkt index 213ad7f4ec..88321d85c4 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wxpanel.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wxpanel.rkt @@ -389,15 +389,37 @@ [do-place-children (lambda (children-info width height) (check-place-children children-info width height) + (define m (border)) + (define w (- width (* 2 m))) + (define h (- height (* 2 m))) (let loop ([children-info children-info]) (if (null? children-info) null (let ([curr-info (car children-info)]) + (define cw (car curr-info)) + (define ch (cadr curr-info)) + (define w-stretch? (caddr curr-info)) + (define h-stretch? (cadddr curr-info)) (cons (list - 0 0 - (car curr-info) ; child-info-x-min - (cadr curr-info)) ; child-info-y-min + (if w-stretch? + m + (case h-align + [(center) (quotient (- w cw) 2)] + [(right) (- w cw)] + [else 0])) + (if h-stretch? + m + (case v-align + [(center) (quotient (- h ch) 2)] + [(bottom) (- h ch)] + [else 0])) + (if w-stretch? + w + cw) + (if h-stretch? + h + ch)) (loop (cdr children-info)))))))]) (define curr-spacing const-default-spacing)