6 Color Prefs

▼ |  | Framework: Racket GUI Application Framework

1 | Framework Libraries Overview
2 | Application
3 | Autosave
4 | Canvas
5 | Color Model
6 | Color Prefs
7 | Color
8 | Comment Box
9 | Decorated Editor Snip
10 | Editor Snip
11 | Editor
12 | Exit
13 | Finder
14 | Frame
15 | Group
16 | GUI Utilities
17 | Handler
18 | Icon
19 | Keymap
20 | Menu
21 | Mode
22 | Notify-boxes
23 | Number Snip
24 | Panel
25 | Pasteboard
26 | Path Utils
27 | Preferences
28 | Preferences, Textual
29 | Racket
30 | Srcloc Snips
31 | Text
32 | Splash
33 | Test
34 | Version
35 | Backwards Compatibility
36 | Signatures
37 | Unit
| Index

On this page:

color-prefs: set-default/ color-scheme
color-prefs: register-color-preference
color-prefs: add-background-preferences-panel
color-prefs: add-to-preferences-panel
color-prefs: build-color-selection-panel
color-prefs: normalize-color-selection-button-widths
color-prefs: marshall-style-delta
color-prefs: unmarshall-style-delta
color-prefs: white-on-black-color-scheme?
color-prefs: white-on-black
color-prefs: black-on-white
color-prefs: add-color-scheme-entry
color-prefs: add-color-scheme-preferences-panel
color-prefs: register-info-based-color-schemes
color-prefs: set-current-color-scheme
color-prefs: get-current-color-scheme-name
color-prefs: known-color-scheme-name?
color-prefs: get-inverted-base-color-scheme
color-prefs: color-scheme-style-name?
color-prefs: color-scheme-color-name?
color-prefs: lookup-in-color-scheme
color-prefs: set-in-color-scheme
color-prefs: register-color-scheme-entry-change-callback
color-prefs: get-color-scheme-names

Racket
top contents ← prev up next →

## 6 Color Prefs🔗ℹ

> > procedure
> > (color-prefs:set-default/color-scheme |  | pref-sym |
> > |  | black-on-white-color |
> > |  | white-on-black-color) |
> → void?
> pref-sym : symbol?
> black-on-white-color : (or/c (is-a?/c color%) string?)
> white-on-black-color : (or/c (is-a?/c color%) string?)

Registers a preference whose value will be updated when the user clicks on one of the color scheme default settings in the preferences dialog, but does not give it a name that can be configured by a color scheme; consider using color-prefs:add-color-scheme-entry instead.

Also calls preferences:set-default and preferences:set-un/marshall with appropriate arguments to register the preference.

> > procedure
> > (color-prefs:register-color-preference |
> > |  | pref-name |
> > |  | style-name |
> > |  | color/sd |
> > | [ | white-on-black-color |
> > |  | #:background background]) |
> → void?
> pref-name : symbol?
> style-name : string?
> color/sd : (or/c (is-a?/c color%) (is-a?/c style-delta%))
> white-on-black-color : (or/c string? (is-a?/c color%) #f) = #f
> background : (or/c (is-a?/c color%) #f) = #f

This function registers a color preference but does not give it a name that can be configured by a color scheme; consider using color-prefs:add-color-scheme-entry instead.

This function calls preferences:set-default and preferences:set-un/marshall to install the pref for pref-name, using color/sd as the default color. The preference is bound to a style-delta%, and initially the style-delta% changes the foreground color to color/sd, unless color/sd is a style delta already, in which case it is just used directly. Then, it calls editor:set-standard-style-list-delta passing the style-name and the current value of the preference pref-name.

Finally, it adds calls preferences:add-callback to set a callback for pref-name that updates the style list when the preference changes.

If white-on-black-color is not #f, then the color of the color/sd argument is used in combination with white-on-black-color to register this preference with color-prefs:set-default/color-scheme.

If background is not #f, then it is used to construct the default background color for the style delta.

> procedure (color-prefs:add-background-preferences-panel) → void?

Adds a preferences panel that configures the background color for editor:basic-mixin.

> > procedure
> > (color-prefs:add-to-preferences-panel |  | name |  |  |  |
> > |  | func |  |  |  |
> > | [ | #:style style]) |  | → |  | void?
> name : string?
> func : (-> (is-a?/c vertical-panel%) void?)
> | style |  | : |  |
> (listof (or/c 'border
> 'hscroll 'auto-hscroll 'hide-hscroll
> 'vscroll 'auto-vscroll 'hide-vscroll))
> |  |  | = |  | '()

Calls func with the subpanel of the preferences coloring panel that corresponds to name.

The panel is created as a vertical-panel%, passing style as the style argument to its constructor.

Changed in version 1.61 of package gui-lib: Added the #:style argument.

> > procedure
> > (color-prefs:build-color-selection-panel |
> > |  | parent |
> > |  | pref-sym |
> > |  | style-name |
> > |  | example-text |
> > | [ | #:background? background?]) |
> → void?
> parent : (is-a?/c area-container<%>)
> pref-sym : symbol?
> style-name : string?
> example-text : string?
> background? : boolean? = #f

Builds a panel with a number of controls for configuring a font: its color (including a background configuration if background is #t) and check boxes for bold, italic, and underline. The parent argument specifies where the panel will be placed. The pref-sym should be a preference (suitable for use with preferences:get and preferences:set). The style-name specifies the name of a style in the style list returned from editor:get-standard-style-list and example-text is shown in the panel so users can see the results of their configuration.

> procedure (color-prefs:normalize-color-selection-button-widths parent)
> → void?
> parent : (is-a?/c area-container<%>)

Given a panel that was passed to color-prefs:build-color-selection-panel (perhaps multiple times), color-prefs:normalize-color-selection-button-widths will ensure that the panel contents line up with each other, by making sure that the color selection buttons all have the same size.

Added in version 1.72 of package gui-lib.

> procedure (color-prefs:marshall-style-delta style-delta) → printable/c
> style-delta : (is-a?/c style-delta%)

Builds a printed representation for a style-delta.

> procedure (color-prefs:unmarshall-style-delta marshalled-style-delta)
> → (or/c #f (is-a?/c style-delta%))
> marshalled-style-delta : printable/c

Builds a style delta from its printed representation. Returns #f if the printed form cannot be parsed.

> procedure (color-prefs:white-on-black-color-scheme?) → boolean?

Returns #true if the current color scheme is in dark mode (i.e. has a light foreground with a dark background) and #false if it is in light mode (i.e. a dark foreground with a light background).

This function uses the 'framework:white-on-black-mode? preference; returning its value if it is a boolean and using white-on-black-panel-scheme? if it is set to 'platform. This function is intended to be used in place of white-on-black-panel-scheme? for code that supports color schemes.

Added in version 1.79 of package gui-lib.

> procedure (color-prefs:white-on-black) → any

Sets the colors registered by color-prefs:register-color-preference to their white-on-black variety.

> procedure (color-prefs:black-on-white) → any

Sets the colors registered by color-prefs:register-color-preference to their black-on-white variety.

> > procedure
> > (color-prefs:add-color-scheme-entry |  | name |
> > |  | black-on-white-color |
> > |  | white-on-black-color |
> > | [ | #:style style |
> > |  | #:bold? bold |
> > |  | #:underline? underline? |
> > |  | #:italic? italic? |
> > |  | #:background background]) |
> → void?
> name : symbol?
> black-on-white-color : (or/c string? (is-a?/c color%))
> white-on-black-color : (or/c string? (is-a?/c color%))
> style : (or/c #f string?) = #f
> bold : (if style (or/c boolean? 'base) #f) = #f
> underline? : (if style boolean? #f) = #f
> italic? : (if style boolean? #f) = #f
> | background |  | : |  |
> (if style
> (or/c #f string? (is-a?/c color%))
> #f)
> |  | = |  | #f

Registers a new color or style named name for use in the color schemes. If style is not #f, a new style is registered; if not a color is registered.

If a style is registered, the style is stored in the style list returned from editor:get-standard-style-list.

Use color-prefs:lookup-in-color-scheme to get the current value of the entry.

> procedure (color-prefs:add-color-scheme-preferences-panel [#:extras extras])
> → void?
> extras : (-> (is-a?/c panel%) any) = void

Adds a panel for choosing a color-scheme to the preferences dialog.

The extras argument is called after the color schemes have been added to the preferences panel. It is passed the panel containing the color schemes and can add items to it.

> procedure (color-prefs:register-info-based-color-schemes) → void?

Reads the "info.rkt" file in each collection, looking for the key 'framework:color-schemes. Each definition must bind a list of hash tables, each of which introduces a new color scheme. Each hash table should have keys that specify details of the color scheme, as follows:

- 'name: must be either a string or a symbol; it names the entire color scheme. If it is a symbol and string-constant?, it is passed to dynamic-string-constant to get the name; otherwise it is used as the name directly. If absent, the name of the directory containing the "info.rkt" file is used as the name.

- 'white-on-black-base?: must be a boolean indicating if this color-scheme is based on an inverted color scheme. If absent, it is #f.

- 'inverted-base-name: must be a symbol or #f. This field is no longer used; in the past it linked two color schemes and was used when switching between light and dark modes. Now, two separate preferences are kept; the user’s choice for dark mode and their choice for light mode.

- 'example: must be a string and is used in the preferences dialog to show an example of the color scheme. If absent, the string used in the “Classic” color scheme is used.

- 'colors: must be a non-empty list whose first position is a symbol, naming a color or style entry in the color scheme. The rest of the elements describe the style or color. In either case, an element may be a vector describing a color, see below. If the name corresponds to a style, then the list may also contain

  - Symbols 'bold, 'italic, or 'underline, changing the font style or underline status, or

  - A prefab struct `#s(background ,vec), specifying the background color where vec is a vector describing a color.

  A vector describing a color is either a vector of three bytes describing the red, green and blue component of a non-transparent color, or a vector of three bytes followed by a real number between 0 and 1, giving the alpha value in addition to color components. In other words, a vector satisfying the following contract describes a color:

  > (or/c (vector/c byte? byte? byte? #:flat? #t)
  > (vector/c byte? byte? byte? (between/c 0.0 1.0) #:flat? #t))

  Examples:

  > '((framework:syntax-color:scheme:symbol
  > #(0 0 0))
  > (framework:syntax-color:scheme:comment
  > #(194 116 31) italic)
  > (framework:syntax-color:scheme:error
  > bold underline #(255 0 0))
  > (plt:htdp:test-coverage-off
  > #(255 165 0)
  > #s(background #(0 0 0))))

The names of the colors and styles are extensible; new ones can be added by calling color-prefs:add-color-scheme-entry. When color-prefs:register-info-based-color-schemes is called, it logs the active set of color names and style names to the color-scheme logger at the info level. So, for example, starting up DrRacket like this: racket -W info@color-scheme -l drracket will print out the styles used in your version of DrRacket.

Changed in version 1.68 of package gui-lib: Added 'inverted-base-name.
Changed in version 1.79: Ignore 'inverted-base-name.

> procedure (color-prefs:set-current-color-scheme name) → void?
> name : symbol?

Set’s the user’s preferred color scheme to the one whose name is name. Also, updates the colors in DrRacket’s GUI to the colors in that color scheme if the named color scheme matches the dark/light mode that the GUI is in.

> procedure (color-prefs:get-current-color-scheme-name [#:wob? wob?])
> → symbol?
> wob? : boolean? = (white-on-black-color-scheme?)

Returns the name of either the user’s preferred dark mode or light mode color scheme, based on the wob? boolean. If the boolean is #true, returns the dark mode’s name, otherwise the light mode’s.

> procedure (color-prefs:known-color-scheme-name? name) → boolean?
> name : any/c

Returns #t if the input is a symbol? that names a color or style that is an entry in the current color scheme.

In order to return #t, name must have been passed as the first argument to color-prefs:add-color-scheme-entry.

> procedure (color-prefs:get-inverted-base-color-scheme name)
> → (or/c #f symbol?)
> name : symbol?

Returns the inverted-base color scheme name of color scheme named name, if it has one.

Added in version 1.68 of package gui-lib.
Changed in version 1.79: This function is no longer used.

> procedure (color-prefs:color-scheme-style-name? name) → boolean?
> name : any/c

Returns #t if name is a known color scheme name, and is connected to a style.

In order to return #t, name must have been passed as the first argument to color-prefs:add-color-scheme-entry and the #:style argument must have also been passed.

> procedure (color-prefs:color-scheme-color-name? name) → boolean?
> name : any/c

Returns #t if name is a known color scheme name, and is connected to a color.

In order to return #t, name must have been passed as the first argument to color-prefs:add-color-scheme-entry and the #:style argument must have also been omitted or be #f.

> > procedure
> > (color-prefs:lookup-in-color-scheme |  | name |
> > | [ | #:wob? wob]) |
> | → |  |
> (if (color-prefs:color-scheme-style-name? name)
> (is-a?/c style-delta%)
> (is-a?/c color%))
> name : color-prefs:known-color-scheme-name?
> wob : boolean? = (white-on-black-color-scheme?)

Returns the current style delta or color associated with name.

> > procedure
> > (color-prefs:set-in-color-scheme |  | name |  |  |  |
> > |  | new-val) |  | → |  | void?
> name : color-prefs:known-color-scheme-name?
> | new-val |  | : |  |
> (if (color-prefs:color-scheme-style-name? name)
> (is-a?/c style-delta%)
> (is-a?/c color%))

Updates the current color or style delta associated with name in the current color scheme.

> > procedure
> > (color-prefs:register-color-scheme-entry-change-callback |
> > |  | name |
> > |  | fn |
> > | [ | weak? |
> > |  | #:style-list style-list]) |
> → void?
> name : color-prefs:known-color-scheme-name?
> | fn |  | : |  |
> (if weak?
> (procedure-arity-includes/c 1)
> (-> (if (color-prefs:color-scheme-style-name? name)
> (is-a?/c style-delta%)
> (is-a?/c color%))
> any))
> weak? : boolean? = #f
> style-list : (or/c #f (is-a?/c style-list%)) = #f

Registers a callback that is invoked whenever the color mapped by name changes. Changes may happen due to calls to color-prefs:set-in-color-scheme or due to calls to color-prefs:set-current-color-scheme.

If weak? is #t, the fn argument is held onto weakly; otherwise it is held onto strongly.

If style-list is not #f then calls to all of the registered callbacks (including fn) are bracketed by calls to begin-style-change-sequence and end-style-change-sequence for the given style-list%.

Changed in version 1.68 of package gui-lib: added the style-list argument

> > procedure
> > (color-prefs:get-color-scheme-names) |  | → |  |
> > set? |  | set?

Returns two sets; the first is the known color scheme names that are just colors and the second is the known color scheme names that are styles.

These are all of the names that have been passed to color-prefs:add-color-scheme-entry.

top contents ← prev up next →