@@ -21,10 +21,29 @@ import { tooltipRaw } from "./tooltip.js";
21
21
22
22
export interface RampOpts extends Omit < ComponentOpts , "label" > {
23
23
ramp : Ramp < number > ;
24
+ /**
25
+ * User defined interpolation mode. Only used to compute internal hash of
26
+ * ramp curve geometry, i.e. if the {@link RampOpts.ramp} interpolation
27
+ * method changes, so should this mode value.
28
+ */
24
29
mode ?: number ;
30
+ /**
31
+ * Normalized snap/selection tolerance for ramp control point positions
32
+ *
33
+ * @defaultValue 0.05
34
+ */
35
+ eps ?: number ;
25
36
}
26
37
27
- export const ramp = ( { gui, layout, id, ramp, mode = 0 , info } : RampOpts ) => {
38
+ export const ramp = ( {
39
+ gui,
40
+ layout,
41
+ id,
42
+ ramp,
43
+ mode = 0 ,
44
+ info,
45
+ eps = 0.05 ,
46
+ } : RampOpts ) => {
28
47
const { x, y, w, h } = layoutBox ( layout ) ;
29
48
const maxX = x + w ;
30
49
const maxY = y + h ;
@@ -42,7 +61,7 @@ export const ramp = ({ gui, layout, id, ramp, mode = 0, info }: RampOpts) => {
42
61
const focused = gui . requestFocus ( id ) ;
43
62
if ( hover ) {
44
63
sel = clamp01_2 ( null , fit2 ( [ ] , gui . mouse , pos , maxPos , ZERO2 , ONE2 ) ) ;
45
- selID = ramp . closestIndex ( sel [ 0 ] , 0.05 ) ;
64
+ selID = ramp . closestIndex ( sel [ 0 ] , eps ) ;
46
65
if ( gui . isMouseDown ( ) ) {
47
66
gui . activeID = id ;
48
67
if ( selID >= 0 ) {
@@ -51,12 +70,12 @@ export const ramp = ({ gui, layout, id, ramp, mode = 0, info }: RampOpts) => {
51
70
ramp . setStopAt (
52
71
roundTo ( sel [ 0 ] , 1e-3 ) ,
53
72
roundTo ( sel [ 1 ] , 1e-3 ) ,
54
- 0.05
73
+ eps
55
74
) ;
56
75
}
57
76
res = ramp ;
58
77
}
59
- if ( focused && selID >= 0 && handleRampKeys ( gui , ramp , selID ) ) {
78
+ if ( focused && selID >= 0 && __handleRampKeys ( gui , ramp , selID ) ) {
60
79
res = ramp ;
61
80
}
62
81
info && gui . draw && tooltipRaw ( gui , info ) ;
@@ -73,7 +92,7 @@ export const ramp = ({ gui, layout, id, ramp, mode = 0, info }: RampOpts) => {
73
92
[
74
93
[ x , maxY ] ,
75
94
mix2 ( [ ] , pos , maxPos , [ 0 , stops [ 0 ] [ 1 ] ] ) ,
76
- ...rampVertices ( ramp , pos , maxPos ) ,
95
+ ...__rampVertices ( ramp , pos , maxPos ) ,
77
96
mix2 ( [ ] , pos , maxPos , [ 1 , stops [ stops . length - 1 ] [ 1 ] ] ) ,
78
97
[ maxX , maxY ] ,
79
98
] ,
@@ -106,14 +125,16 @@ export const ramp = ({ gui, layout, id, ramp, mode = 0, info }: RampOpts) => {
106
125
return res ;
107
126
} ;
108
127
109
- const rampVertices = (
128
+ /** @internal */
129
+ const __rampVertices = (
110
130
ramp : Ramp < number > ,
111
131
pos : Vec ,
112
132
maxPos : Vec ,
113
133
numSamples = 100
114
134
) => map ( ( p ) => mix2 ( p , pos , maxPos , p ) , ramp . samples ( numSamples ) ) ;
115
135
116
- const handleRampKeys = ( gui : IMGUI , ramp : Ramp < number > , selID : number ) => {
136
+ /** @internal */
137
+ const __handleRampKeys = ( gui : IMGUI , ramp : Ramp < number > , selID : number ) => {
117
138
switch ( gui . key ) {
118
139
case Key . TAB :
119
140
gui . switchFocus ( ) ;
0 commit comments