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.
This commit is contained in:
parent
fdf1a1f7ae
commit
32ae3f8308
|
@ -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.
|
cannot be hidden or disabled like a @racket[panel%] object.
|
||||||
|
|
||||||
A @racket[pane%] object has a degenerate placement strategy for
|
A @racket[pane%] object has a degenerate placement strategy for
|
||||||
managing its children; it places them all in the upper left corner
|
managing its children: it places each child as if it was the only
|
||||||
and does not stretch any of them. The @racket[horizontal-pane%] and
|
child of the panel. The @racket[horizontal-pane%] and
|
||||||
@racket[vertical-pane%] classes provide useful geometry management.
|
@racket[vertical-pane%] classes provide useful geometry management
|
||||||
|
for multiple children.
|
||||||
|
|
||||||
See also @racket[grow-box-spacer-pane%].
|
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%)
|
@defconstructor[([parent (or/c (is-a?/c frame%) (is-a?/c dialog%)
|
||||||
(is-a?/c panel%) (is-a?/c pane%))]
|
(is-a?/c panel%) (is-a?/c pane%))]
|
||||||
|
|
|
@ -11,11 +11,15 @@ A panel is a both a container and a containee window. It serves mainly
|
||||||
object can be hidden or disabled.
|
object can be hidden or disabled.
|
||||||
|
|
||||||
A @racket[panel%] object has a degenerate placement strategy for
|
A @racket[panel%] object has a degenerate placement strategy for
|
||||||
managing its children; it places them all in the upper left corner
|
managing its children: it places each child as if it was the only
|
||||||
and does not stretch any of them. The @racket[horizontal-panel%]
|
child of the panel. The @racket[horizontal-panel%] and
|
||||||
and @racket[vertical-panel%] classes provide useful geometry
|
@racket[vertical-panel%] classes provide useful geometry management
|
||||||
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%)
|
@defconstructor[([parent (or/c (is-a?/c frame%) (is-a?/c dialog%)
|
||||||
(is-a?/c panel%) (is-a?/c pane%))]
|
(is-a?/c panel%) (is-a?/c pane%))]
|
||||||
|
|
|
@ -29,4 +29,4 @@
|
||||||
|
|
||||||
(define pkg-authors '(mflatt robby))
|
(define pkg-authors '(mflatt robby))
|
||||||
|
|
||||||
(define version "1.2")
|
(define version "1.3")
|
||||||
|
|
|
@ -389,15 +389,37 @@
|
||||||
[do-place-children
|
[do-place-children
|
||||||
(lambda (children-info width height)
|
(lambda (children-info width height)
|
||||||
(check-place-children 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])
|
(let loop ([children-info children-info])
|
||||||
(if (null? children-info)
|
(if (null? children-info)
|
||||||
null
|
null
|
||||||
(let ([curr-info (car children-info)])
|
(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
|
(cons
|
||||||
(list
|
(list
|
||||||
0 0
|
(if w-stretch?
|
||||||
(car curr-info) ; child-info-x-min
|
m
|
||||||
(cadr curr-info)) ; child-info-y-min
|
(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)))))))])
|
(loop (cdr children-info)))))))])
|
||||||
|
|
||||||
(define curr-spacing const-default-spacing)
|
(define curr-spacing const-default-spacing)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user