diff --git a/src/mol-plugin/ui/controls/parameters.tsx b/src/mol-plugin/ui/controls/parameters.tsx index ad5116ba188376a185411a9c8a39795260d75ae9..bfaff131f548ccdb73cd6add74e849067d3efc85 100644 --- a/src/mol-plugin/ui/controls/parameters.tsx +++ b/src/mol-plugin/ui/controls/parameters.tsx @@ -8,7 +8,7 @@ import * as React from 'react' import { ParamDefinition as PD } from 'mol-util/param-definition'; import { camelCaseToWords } from 'mol-util/string'; -import { ColorNames } from 'mol-util/color/tables'; +import { ColorNames, ColorNamesValueMap } from 'mol-util/color/tables'; import { Color } from 'mol-util/color'; import { Slider, Slider2 } from './slider'; @@ -172,6 +172,13 @@ function ColorOptions() { return _colors; } +function ColorValueOption(color: Color) { + return !ColorNamesValueMap.has(color) ? <option key={Color.toHexString(color)} value={color} style={{ background: `${Color.toStyle(color)}` }} > + {Color.toHexString(color)} + </option> : null +} + + export class ColorControl extends SimpleParam<PD.Color> { onChange = (e: React.ChangeEvent<HTMLSelectElement>) => { this.update(Color(parseInt(e.target.value))); @@ -179,6 +186,7 @@ export class ColorControl extends SimpleParam<PD.Color> { renderControl() { return <select value={this.props.value} onChange={this.onChange} style={{ borderLeft: `16px solid ${Color.toStyle(this.props.value)}` }}> + {ColorValueOption(this.props.value)} {ColorOptions()} </select>; } diff --git a/src/mol-util/color/tables.ts b/src/mol-util/color/tables.ts index 758fe153507c286071972d72d88fd2340e960322..b4380176ccfb35ad09a8681d2893aa0988ba9b96 100644 --- a/src/mol-util/color/tables.ts +++ b/src/mol-util/color/tables.ts @@ -259,4 +259,13 @@ export const ColorNames = ColorMap({ whitesmoke: 0xf5f5f5, yellow: 0xffff00, yellowgreen: 0x9acd32 -}) \ No newline at end of file +}) +export type ColorNames = typeof ColorNames +export type ColorName = keyof ColorNames +export const ColorNamesValueMap = (function(){ + const map = new Map<Color, ColorName>() + Object.keys(ColorNames).forEach(name => { + map.set(ColorNames[name as ColorName], name as ColorName) + }) + return map +})()