racket / gui

Other
63 stars 77 forks source link

Support control alignment #207

Open sorawee opened 3 years ago

sorawee commented 3 years ago

When labels are specified in controls like text-box%, the controls are put right after the labels, causing the layout to look weird.

Screen Shot 2021-01-01 at 7 12 38 AM

In contrast, this is how the controls are usually aligned in most applications.

Screen Shot 2021-01-01 at 7 14 02 AM
alex-hhh commented 3 years ago

You can already achieve that layout by using separate message% objects for the labels and a custom panel% type. There's table-panel available as a package, but I haven't used that. I also wrote my own grid-pane% for this purpose and you can use it like this:

Screenshot 2021-01-02 075550
#lang racket/gui
(require "grid-pane.rkt")

(define toplevel (new frame% [label "Hello"] [width 300] [height 100]))

(define p (new grid-pane%
               [parent toplevel]
               [columns 2] ;; children are placed in two columns
               [spacing 5]
               [border 5]
               [alignment '(left center)]))

(new message%
     [parent p]
     [label "Font Name"])
(new choice%
     [parent p]
     [label ""]
     [choices '("Menlo")]
     [stretchable-width #t])

(new message%
     [parent p]
     [label "Font Smoothing"])
(new choice%
     [parent p]
     [label ""]
     [choices '("Use system-wide default")]
     [stretchable-width #t])

(new message%
     [parent p]
     [label "Weight"])
(new choice%
     [parent p]
     [label ""]
     [choices '("Normal")]
     [stretchable-width #t])

(send toplevel show #t)
dancojocaru2000 commented 1 year ago

Your grid-pane% is published under GPL-3+, so it's not quite a replacement for this feature being in the gui package.

If anything, it's worth warning people that they should not look at your implementation if they wish to fix this issue in order to not write derived code that would then violate the GPL-3+ license if published as Apache-2 or MIT.