Skip to content

Commit 1e5053b

Browse files
committed
further Tahoe repairs and refinments
Tahoe's GUI changes affect the amount of padding around various controls, especially buttons. Provide more consoistent path for existing Racket applications by adding padding to bring things more in line. Also, aubstantial extra padding is needed around the content of a dialog box, where rounded corners especially cut into the content.
1 parent 2caa929 commit 1e5053b

File tree

10 files changed

+133
-16
lines changed

10 files changed

+133
-16
lines changed

gui-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(define deps '("srfi-lite-lib"
66
"data-lib"
77
["icons" #:version "1.3"]
8-
["base" #:version "8.3.0.3"]
8+
["base" #:version "9.0.0.6"]
99
["syntax-color-lib" #:version "1.7"]
1010
["draw-lib" #:version "1.18"]
1111
["snip-lib" #:version "1.6"]

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"const.rkt"
1010
"window.rkt"
1111
"../common/event.rkt"
12-
"image.rkt")
12+
"image.rkt"
13+
"liquid-glass.rkt")
1314

1415
(provide
1516
(protect-out button%
@@ -110,6 +111,30 @@
110111
(NSRect-origin f)
111112
(make-NSSize (+ (NSSize-width (NSRect-size f)) 2)
112113
(+ (NSSize-height (NSRect-size f)) 4))))))
114+
115+
(define-values (h-margin v-margin)
116+
(if liquid-glass?
117+
(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)))))
113138

114139
(define-values (cocoa image-cocoa)
115140
(if (and button-type

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"utils.rkt"
1313
"const.rkt"
1414
"types.rkt"
15+
"liquid-glass.rkt"
1516
"window.rkt"
1617
"frame.rkt"
1718
"dc.rkt"
@@ -123,7 +124,7 @@
123124
(tellv ctx saveGraphicsState)
124125
(let ([cg (tell #:type _CGContextRef ctx graphicsPort)]
125126
[r (tell #:type _NSRect self bounds)])
126-
(CGContextSetRGBFillColor cg 0 0 0 1.0)
127+
(CGContextSetRGBFillColor cg frame-black frame-black frame-black 1.0)
127128
(let* ([l (NSPoint-x (NSRect-origin r))]
128129
[t (NSPoint-y (NSRect-origin r))]
129130
[b (+ t (NSSize-height (NSRect-size r)))]
@@ -417,7 +418,8 @@
417418
(tell (tell (cond
418419
[is-combo? NSView]
419420
[has-control-border? FocusView]
420-
[(memq 'border style) (if (memq 'vscroll style)
421+
[(memq 'border style) (if (and (memq 'vscroll style)
422+
(not liquid-glass?))
421423
CornerlessFrameView
422424
FrameView)]
423425
[else NSView])

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"utils.rkt"
77
"const.rkt"
88
"types.rkt"
9+
"liquid-glass.rkt"
910
"window.rkt"
1011
"queue.rkt"
1112
"menu-bar.rkt"
@@ -28,7 +29,7 @@
2829

2930
(import-class NSWindow NSGraphicsContext NSMenu NSPanel
3031
NSApplication NSAutoreleasePool NSScreen
31-
NSToolbar NSArray)
32+
NSToolbar NSArray NSView)
3233

3334
(define NSWindowCloseButton 0)
3435
(define NSWindowToolbarButton 3)
@@ -319,12 +320,37 @@
319320

320321
(tellv cocoa setAcceptsMouseMovedEvents: #:type _BOOL #t)
321322

323+
(define inner-content-view
324+
(cond
325+
[(and is-dialog? liquid-glass?)
326+
(import-class NSLayoutConstraint)
327+
(define cv (tell (tell NSView alloc) init))
328+
(define win (tell cocoa contentView))
329+
(define margin 10)
330+
(tellv win addSubview: cv)
331+
(tellv cv setTranslatesAutoresizingMaskIntoConstraints: #:type _BOOL #false)
332+
(tellv NSLayoutConstraint
333+
activateConstraints:
334+
(tell NSArray
335+
arrayWithObjects: #:type (_list i _id)
336+
(list
337+
(tell (tell cv topAnchor) constraintEqualToAnchor: (tell win topAnchor) constant: #:type _CGFloat margin)
338+
(tell (tell cv leadingAnchor) constraintEqualToAnchor: (tell win leadingAnchor) constant: #:type _CGFloat margin)
339+
(tell (tell cv trailingAnchor) constraintEqualToAnchor: (tell win trailingAnchor) constant: #:type _CGFloat (- margin))
340+
(tell (tell cv bottomAnchor) constraintEqualToAnchor: (tell win bottomAnchor) constant: #:type _CGFloat (- margin)))
341+
count: #:type _NSUInteger 4))
342+
cv]
343+
[else #f]))
344+
322345
;; Setting the window in one-shot mode helps prevent the
323346
;; frame from being resurrected by a click on the dock icon.
324347
(tellv cocoa setOneShot: #:type _BOOL #t)
325348

349+
(define/override (get-frame)
350+
(tell #:type _NSRect cocoa frame))
351+
326352
(define/override (get-cocoa-content)
327-
(tell cocoa contentView))
353+
(or inner-content-view (tell cocoa contentView)))
328354
(define/override (get-cocoa-window) cocoa)
329355
(define/override (get-wx-window) this)
330356

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#lang racket/base
2+
(require ffi/unsafe
3+
ffi/unsafe/objc
4+
"utils.rkt"
5+
"types.rkt"
6+
"const.rkt")
7+
8+
(provide liquid-glass?)
9+
10+
(define liquid-glass?
11+
(and (version-26.0-or-later?)
12+
(let ()
13+
(import-class NSWindow)
14+
(objc-class-has-instance-method? NSWindow (selector _cornerRadius))
15+
;; This seems like a terrible way to detect whether we're using
16+
;; the GUI rendering introduced in Tahoe (it depends on how Racket
17+
;; is linked, not the OS it runs on), but this is the best
18+
;; recommendation I can find for now:
19+
(define cocoa
20+
(tell (tell NSWindow alloc)
21+
initWithContentRect: #:type _NSRect (make-NSRect (make-NSPoint 0 0)
22+
(make-NSSize 256 256))
23+
styleMask: #:type _int NSTitledWindowMask
24+
backing: #:type _int NSBackingStoreBuffered
25+
defer: #:type _BOOL NO))
26+
((tell #:type _double cocoa _cornerRadius) . > . 12.0))))
27+

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"utils.rkt"
1111
"types.rkt"
1212
"image.rkt"
13-
"color.rkt")
13+
"color.rkt"
14+
"liquid-glass.rkt")
1415

1516
(provide
1617
(protect-out message%))
@@ -130,6 +131,26 @@
130131
(tellv (get-cocoa) sizeToFit)
131132
#t)
132133

134+
(define b-margin
135+
(if liquid-glass?
136+
4
137+
0))
138+
139+
(define/override (get-frame)
140+
(define r (super get-frame))
141+
(cond
142+
[(= b-margin 0)
143+
r]
144+
[else
145+
(define p (NSRect-origin r))
146+
(define s (NSRect-size r))
147+
(make-NSRect p
148+
(make-NSSize (NSSize-width s)
149+
(+ (NSSize-height s) b-margin)))]))
150+
151+
(define/override (set-frame x y w h)
152+
(super set-frame x y w (max 0 (- h b-margin))))
153+
133154
(define/public (get-color) color)
134155
(define/public (set-color c)
135156
(when text-label?

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@
77
"utils.rkt"
88
"cg.rkt"
99
"window.rkt"
10-
"procs.rkt")
10+
"procs.rkt"
11+
"liquid-glass.rkt")
1112

1213
(provide
1314
(protect-out panel%
1415
panel-mixin
1516

16-
FrameView))
17+
FrameView
18+
frame-black
19+
frame-white))
1720

1821
(import-class NSView NSGraphicsContext)
1922

2023
(define-objc-class RacketPanelView NSView
2124
#:mixins (KeyMouseTextResponder CursorDisplayer)
2225
[wxb])
2326

27+
(define frame-black (if liquid-glass? 0.7 0))
28+
(define frame-white (if liquid-glass? 0.5 0.8))
29+
2430
(define-objc-class FrameView NSView
2531
[]
2632
(-a #:async-apply (box (void))
@@ -33,10 +39,10 @@
3339
(cond
3440
[wob?
3541
(CGContextSetRGBFillColor cg 0 0 0 1.0)
36-
(CGContextSetRGBStrokeColor cg 0.8 0.8 0.8 1.0)]
42+
(CGContextSetRGBStrokeColor cg frame-white frame-white frame-white 1.0)]
3743
[else
3844
(CGContextSetRGBFillColor cg 1.0 1.0 1.0 1.0)
39-
(CGContextSetRGBStrokeColor cg 0 0 0 1.0)])
45+
(CGContextSetRGBStrokeColor cg frame-black frame-black frame-black 1.0)])
4046
(CGContextAddRect cg r)
4147
(CGContextStrokePath cg))
4248
(tellv ctx restoreGraphicsState))))

gui-lib/mred/private/wx/cocoa/radio-box.rkt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"types.rkt"
99
"const.rkt"
1010
"utils.rkt"
11+
"liquid-glass.rkt"
1112
"window.rkt"
1213
"../common/event.rkt"
1314
"image.rkt")
@@ -85,7 +86,9 @@
8586
RacketImageButtonCell)
8687
numberOfRows: #:type _NSInteger (if horiz? 1 (length labels))
8788
numberOfColumns: #:type _NSInteger (if horiz? (length labels) 1)))])
88-
(tellv cocoa setIntercellSpacing: #:type _NSSize (make-NSSize 2 2))
89+
(tellv cocoa setIntercellSpacing: #:type _NSSize (if liquid-glass?
90+
(make-NSSize 5 5)
91+
(make-NSSize 2 2)))
8992
(for ([label (in-list labels)]
9093
[i (in-naturals)])
9194
(let ([button (tell cocoa

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
version-10.15-or-later?
3636
version-11.0-or-later?
3737
version-12.0-or-later?
38-
version-13.0-or-later?)
38+
version-13.0-or-later?
39+
version-26.0-or-later?)
3940
with-autorelease
4041
call-with-autorelease
4142
define-mz)
@@ -116,3 +117,5 @@
116117
(NSAppKitVersionNumber . >= . 2100))
117118
(define (version-13.0-or-later?) ; Ventura
118119
(NSAppKitVersionNumber . >= . 2200))
120+
(define (version-26.0-or-later?) ; Tahoe
121+
(NSAppKitVersionNumber . >= . 2600))

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,14 @@
738738

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

741-
(define/private (get-frame)
741+
(define/public (get-frame)
742+
(tellv cocoa layoutSubtreeIfNeeded)
742743
(tell #:type _NSRect cocoa frame))
743744

745+
(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))))
748+
744749
(define/public (flip y h)
745750
(if parent
746751
(let ([b (tell #:type _NSRect (send parent get-cocoa-content) bounds)])
@@ -810,8 +815,7 @@
810815
[y (if (not y) (get-y) y)])
811816
;; old location will need refresh:
812817
(tellv cocoa setNeedsDisplay: #:type _BOOL #t)
813-
(tellv cocoa setFrame: #:type _NSRect (make-NSRect (make-NSPoint x (flip y h))
814-
(make-NSSize w h)))
818+
(set-frame x y w h)
815819
;; new location needs refresh:
816820
(tellv cocoa setNeedsDisplay: #:type _BOOL #t))
817821
(queue-on-size))

0 commit comments

Comments
 (0)