Skip to content

Commit ee2927e

Browse files
committed
Mac OS: improve control alignment
As Cocoa rendering has changed slightly over versions, labels and control content have become misaligned. Tweak control shapes to make horizontally centered controls look better. A better solution would involve controls reporting a baseline, and then panel alignment modes that take baselines into account. That's a much bigger change, however, since it would change the child-placement protocol.
1 parent a667079 commit ee2927e

6 files changed

Lines changed: 59 additions & 30 deletions

File tree

gui-lib/mred/private/wx/cocoa/button.rkt

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,15 @@
112112
(make-NSSize (+ (NSSize-width (NSRect-size f)) 2)
113113
(+ (NSSize-height (NSRect-size f)) 4))))))
114114

115-
(define-values (h-margin v-margin)
115+
(define/override (get-margin-adjustments)
116116
(if liquid-glass?
117117
(if (eq? event-type 'check-box)
118-
(values 1 1)
119-
(values 5 5))
120-
(values 0 0)))
121-
122-
(define/override (get-frame)
123-
(define r (super get-frame))
124-
(cond
125-
[(and (= h-margin 0) (= v-margin 0))
126-
r]
127-
[else
128-
(define p (NSRect-origin r))
129-
(define s (NSRect-size r))
130-
(make-NSRect (make-NSPoint (+ (NSPoint-x p) h-margin)
131-
(+ (NSPoint-y p) v-margin))
132-
(make-NSSize (+ (NSSize-width s) (* 2 h-margin))
133-
(+ (NSSize-height s) (* 2 h-margin))))]))
134-
135-
(define/override (set-frame x y w h)
136-
(super set-frame (+ x v-margin) (+ y h-margin)
137-
(max 0 (- w (* 2 h-margin))) (max 0 (- h (* 2 v-margin)))))
118+
(values 1 1 1 1)
119+
(values 5 5 5 5))
120+
(if (and (eq? event-type 'check-box)
121+
(version-10.9-or-later?))
122+
(values 0 0 0 4)
123+
(values 0 0 0 0))))
138124

139125
(define-values (cocoa image-cocoa)
140126
(if (and button-type

gui-lib/mred/private/wx/cocoa/canvas.rkt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,14 @@
513513
(define/override (set-size x y w h)
514514
(do-set-size x y w h))
515515

516+
(define/override (get-margin-adjustments)
517+
(if (and is-combo?
518+
(version-10.9-or-later?))
519+
(if liquid-glass?
520+
(values 0 -1 0 0)
521+
(values 0 0 0 1))
522+
(values 0 0 0 0)))
523+
516524
(define tr #f)
517525

518526
(define/override (show on?)

gui-lib/mred/private/wx/cocoa/choice.rkt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"const.rkt"
99
"utils.rkt"
1010
"window.rkt"
11-
"../common/event.rkt")
11+
"../common/event.rkt"
12+
"liquid-glass.rkt")
1213

1314
(provide
1415
(protect-out choice%))
@@ -58,7 +59,13 @@
5859
(callback this (new control-event%
5960
[event-type 'choice]
6061
[time-stamp (current-milliseconds)])))
61-
62+
63+
(define/override (get-margin-adjustments)
64+
(if (and (not liquid-glass?)
65+
(version-10.9-or-later?))
66+
(values 0 2 0 0)
67+
(values 0 0 0 0)))
68+
6269
(define/public (set-selection i)
6370
(tellv (get-cocoa) selectItemAtIndex: #:type _NSInteger i))
6471
(define/public (get-selection)

gui-lib/mred/private/wx/cocoa/message.rkt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@
117117
[callback void]
118118
[no-show? (memq 'deleted style)])
119119

120+
(define/override (get-margin-adjustments) (values 0
121+
(if (or liquid-glass?
122+
(not (version-10.9-or-later?)))
123+
0
124+
-3)
125+
0
126+
(if liquid-glass?
127+
-5
128+
0)))
129+
120130
(define/override (set-label label)
121131
(set! text-label? (string? label))
122132
(cond

gui-lib/mred/private/wx/cocoa/window.rkt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,26 @@
738738

739739
(define/public (is-group?) #f)
740740

741+
(define/public (get-margin-adjustments) (values 0 0 0 0))
742+
741743
(define/public (get-frame)
742744
(tellv cocoa layoutSubtreeIfNeeded)
743-
(tell #:type _NSRect cocoa frame))
745+
(define r (tell #:type _NSRect cocoa frame))
746+
(define-values (lm tm rm bm) (get-margin-adjustments))
747+
(cond
748+
[(= 0 lm tm rm bm) r]
749+
[else
750+
(define p (NSRect-origin r))
751+
(define s (NSRect-size r))
752+
(make-NSRect (make-NSPoint (- (NSPoint-x p) lm)
753+
(- (NSPoint-y p) tm))
754+
(make-NSSize (+ (NSSize-width s) lm rm)
755+
(+ (NSSize-height s) tm bm)))]))
744756

745757
(define/public (set-frame x y w h)
746-
(tellv cocoa setFrame: #:type _NSRect (make-NSRect (make-NSPoint x (flip y h))
747-
(make-NSSize w h))))
758+
(define-values (lm tm rm bm) (get-margin-adjustments))
759+
(tellv cocoa setFrame: #:type _NSRect (make-NSRect (make-NSPoint (+ x lm) (flip (+ y tm) (- h tm bm)))
760+
(make-NSSize (max 0 (- w lm rm)) (max 0 (- h tm bm))))))
748761

749762
(define/public (flip y h)
750763
(if parent

gui-lib/mred/private/wxtextfield.rkt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@
200200
(if (null? children-info)
201201
null
202202
(let ([r (super-place-children children-info width height)])
203-
(if horiz?
203+
(if (and horiz? (pair? (cdr r)))
204204
;; Line up label right with text:
205-
(cons (list* (caar r) (+ (cadar r) dy) (cddar r))
206-
(cdr r))
205+
(list (list* (caar r) (+ (cadar r) dy) (cddar r))
206+
(list* (caadr r) (+ (cadadr r)) (cddadr r)))
207207
r))))])
208208
(super-make-object #f proxy parent (if (memq 'deleted style) '(deleted) null) #f)
209209
(unless (memq 'deleted style)
@@ -215,6 +215,11 @@
215215
[(memq 'horizontal-label style) #t]
216216
[else (eq? (send (send parent get-window) get-label-position) 'horizontal)]))
217217
(define dy 0)
218+
(define label-align-margin (if (memq 'combo style)
219+
0
220+
(case (system-type)
221+
[(macosx) 2]
222+
[else 0])))
218223
(define p
219224
(if horiz?
220225
this
@@ -286,7 +291,7 @@
286291
(send l skip-subwindow-events? #t)
287292
(send l x-margin 0))
288293
(send c set-x-margin 2)
289-
(send c set-y-margin 2)
294+
(send c set-y-margin (+ 2 label-align-margin))
290295
(send e set-line-spacing 0)
291296
(send e set-paste-text-only #t)
292297
(send e auto-wrap (and multi? (not (memq 'hscroll style))))

0 commit comments

Comments
 (0)