Skip to content

Commit f01591b

Browse files
committed
adjust the way that the preferences dialog presents the options for color schemes
1 parent a3d78df commit f01591b

File tree

2 files changed

+89
-82
lines changed

2 files changed

+89
-82
lines changed

gui-lib/framework/private/color-prefs.rkt

Lines changed: 88 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,87 +1242,19 @@ on top's background stays in the wrong mode.
12421242
(new-vertical-panel%
12431243
[parent parent]
12441244
[style '(auto-vscroll)]))
1245-
(extras vp)
1246-
(define buttons
1247-
(for/list ([color-scheme (in-list known-color-schemes)])
1248-
(define hp (new-horizontal-panel%
1249-
[parent vp]
1250-
[alignment '(left top)]
1251-
[stretchable-height #t]
1252-
[style '(border)]))
1253-
(define t (new racket:text%))
1254-
(define str (color-scheme-example color-scheme))
1255-
(send t insert str)
1256-
(define ec (new editor-canvas%
1257-
[parent hp]
1258-
[style '(no-border auto-hscroll no-vscroll)]
1259-
[editor t]))
1260-
(define (update-colors defaults?)
1261-
(define bkg-name 'framework:basic-canvas-background)
1262-
(send ec set-canvas-background
1263-
(lookup-in-color-scheme/given-mapping
1264-
bkg-name
1265-
(if defaults?
1266-
(hash)
1267-
(preferences:get (color-scheme-entry-name->pref-name bkg-name)))
1268-
color-scheme))
1269-
(send t set-style-list (color-scheme->style-list color-scheme defaults?)))
1270-
(send ec set-line-count (+ 1 (for/sum ([c (in-string str)])
1271-
(if (equal? c #\newline)
1272-
1
1273-
0))))
1274-
(define bp (new-vertical-panel% [parent hp]
1275-
[stretchable-height #f]
1276-
[stretchable-width #f]))
1277-
(define msg
1278-
(new message%
1279-
[stretchable-width #t]
1280-
[label (color-scheme-button-label color-scheme)]
1281-
[parent bp]))
1282-
(define check-box
1283-
(new check-box%
1284-
[label (if (color-scheme-white-on-black-base? color-scheme)
1285-
(string-constant dark-mode-color-scheme)
1286-
(string-constant light-mode-color-scheme))]
1287-
[parent bp]
1288-
[value (equal?
1289-
(preferences:get (if (color-scheme-white-on-black-base? color-scheme)
1290-
'framework:color-scheme-wob
1291-
'framework:color-scheme))
1292-
(color-scheme-name color-scheme))]
1293-
[callback (λ (x y)
1294-
(preferences:set (if (color-scheme-white-on-black-base? color-scheme)
1295-
'framework:color-scheme-wob
1296-
'framework:color-scheme)
1297-
(color-scheme-name color-scheme)))]))
1298-
(preferences:add-callback
1299-
(if (color-scheme-white-on-black-base? color-scheme)
1300-
'framework:color-scheme-wob
1301-
'framework:color-scheme)
1302-
(λ (sym val)
1303-
(send check-box set-value
1304-
(equal? val (color-scheme-name color-scheme)))))
1305-
(update-colors #f)
1306-
msg))
1307-
(define bottom-hp
1308-
(new horizontal-panel%
1309-
[parent vp]
1310-
[stretchable-height #f]))
1311-
(define revert-button%
1312-
(new button%
1313-
[label (string-constant revert-colors-to-color-scheme-defaults)]
1314-
[parent bottom-hp]
1315-
[callback
1316-
(λ (x y)
1317-
(revert-to-color-scheme-defaults
1318-
(get-current-color-scheme
1319-
#:wob?
1320-
(white-on-black-color-scheme?))))]))
1245+
(define top-hp (new-horizontal-panel%
1246+
[parent vp]
1247+
[stretchable-height #f]
1248+
[alignment '(center center)]))
1249+
(define top-hp2 (new-horizontal-panel%
1250+
[parent vp]
1251+
[stretchable-height #f]
1252+
[alignment '(center center)]))
13211253
(define white-on-black-mode-choice
13221254
(case (system-type)
13231255
[(windows)
13241256
(new choice%
1325-
[parent bottom-hp]
1257+
[parent top-hp]
13261258
[label (string-constant color-mode)]
13271259
[choices (list (string-constant light-mode)
13281260
(string-constant dark-mode))]
@@ -1335,7 +1267,7 @@ on top's background stays in the wrong mode.
13351267
[1 #t])))])]
13361268
[else
13371269
(new choice%
1338-
[parent bottom-hp]
1270+
[parent top-hp]
13391271
[label (string-constant color-mode)]
13401272
[choices (list (string-constant use-os-dark-mode-selection)
13411273
(string-constant always-light-mode)
@@ -1365,9 +1297,84 @@ on top's background stays in the wrong mode.
13651297
['platform 0]
13661298
[#t 2]
13671299
[#f 1]))))])
1368-
(define wid (apply max (map (λ (x) (send x get-width)) buttons)))
1369-
(for ([b (in-list buttons)])
1370-
(send b min-width wid))
1300+
1301+
(define (setup-color-scheme-choice dark-mode? label pref-sym)
1302+
(define this-mode-color-schemes
1303+
(for/list ([color-scheme (in-list known-color-schemes)]
1304+
#:when (equal? dark-mode? (color-scheme-white-on-black-base? color-scheme)))
1305+
color-scheme))
1306+
(define this-mode-choice
1307+
(new choice%
1308+
[parent top-hp2]
1309+
[label label]
1310+
[choices (for/list ([color-scheme (in-list this-mode-color-schemes)])
1311+
(color-scheme-button-label color-scheme))]
1312+
[callback
1313+
(λ (_1 _2)
1314+
(preferences:set pref-sym
1315+
(color-scheme-name
1316+
(list-ref this-mode-color-schemes
1317+
(send this-mode-choice get-selection)))))]))
1318+
(define (update-choice val)
1319+
(send this-mode-choice set-selection
1320+
(for/or ([i (in-naturals)]
1321+
[color-scheme (in-list this-mode-color-schemes)])
1322+
(and (equal? (color-scheme-name color-scheme) val)
1323+
i))))
1324+
(preferences:add-callback pref-sym (λ (sym val) (update-choice val)))
1325+
(update-choice (preferences:get pref-sym)))
1326+
(setup-color-scheme-choice #f (string-constant light-mode-scheme) 'framework:color-scheme)
1327+
(setup-color-scheme-choice #t (string-constant dark-mode-scheme) 'framework:color-scheme-wob)
1328+
1329+
(define color-scheme-examples-vp
1330+
(new-vertical-panel%
1331+
[spacing 10]
1332+
[border 10]
1333+
[parent vp]))
1334+
(for ([color-scheme (in-list known-color-schemes)])
1335+
(define hp (new-vertical-panel%
1336+
[parent color-scheme-examples-vp]
1337+
[alignment '(center top)]
1338+
[stretchable-height #t]
1339+
[style '(border)]))
1340+
(define t (new racket:text%))
1341+
(define str (color-scheme-example color-scheme))
1342+
(send t insert str)
1343+
(define msg
1344+
(new message%
1345+
[stretchable-width #f]
1346+
[label (color-scheme-button-label color-scheme)]
1347+
[parent hp]))
1348+
(define ec (new editor-canvas%
1349+
[parent hp]
1350+
[style '(no-border auto-hscroll no-vscroll)]
1351+
[editor t]))
1352+
(define (update-colors defaults?)
1353+
(define bkg-name 'framework:basic-canvas-background)
1354+
(send ec set-canvas-background
1355+
(lookup-in-color-scheme/given-mapping
1356+
bkg-name
1357+
(if defaults?
1358+
(hash)
1359+
(preferences:get (color-scheme-entry-name->pref-name bkg-name)))
1360+
color-scheme))
1361+
(send t set-style-list (color-scheme->style-list color-scheme defaults?)))
1362+
(send ec set-line-count (+ 1 (for/sum ([c (in-string str)])
1363+
(if (equal? c #\newline)
1364+
1
1365+
0))))
1366+
(update-colors #f))
1367+
(define revert-button%
1368+
(new button%
1369+
[label (string-constant revert-colors-to-color-scheme-defaults)]
1370+
[parent vp]
1371+
[callback
1372+
(λ (x y)
1373+
(revert-to-color-scheme-defaults
1374+
(get-current-color-scheme
1375+
#:wob?
1376+
(white-on-black-color-scheme?))))]))
1377+
(extras vp)
13711378
(void))))
13721379

13731380
(define (revert-to-color-scheme-defaults color-scheme)

gui-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"pict-lib"
1414
"scheme-lib"
1515
["scribble-lib" #:version "1.36"]
16-
["string-constants-lib" #:version "1.55"]
16+
["string-constants-lib" #:version "1.56"]
1717
"option-contract-lib"
1818
"2d-lib"
1919
"compatibility-lib"

0 commit comments

Comments
 (0)