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:  marshall-style-delta
color-prefs:  unmarshall-style-delta
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:  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

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.
Adds a preferences panel that configures the background color for editor:basic-mixin.

procedure

(color-prefs:add-to-preferences-panel name    
  func)  void?
  name : string?
  func : ((is-a?/c vertical-panel%) . -> . void?)
Calls func with the subpanel of the preferences coloring panel that corresponds to name.

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: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 false/c (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.
Sets the colors registered by color-prefs:register-color-preference to their white-on-black variety.
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.
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.

  • '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.

procedure

(color-prefs:set-current-color-scheme name)  void?

  name : symbol?
Sets the current color scheme to the scheme named name, if name is one of the color schemes. Otherwise, sets the color scheme to the default color scheme.
Returns the current color scheme’s name.

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: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.
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?]) 
  void?
  name : color-prefs:known-color-scheme-name?
  fn : 
(-> (if (color-prefs:color-scheme-style-name? name)
        (is-a?/c style-delta%)
        (is-a?/c color%))
    any)
  weak? : boolean? = #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.
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.