import type { FnN4 } from "@thi.ng/api" ; import { pointInside } from "@thi.ng/geom/point-inside" ; import type { IShape } from "@thi.ng/geom-api" ; import { clamp } from "@thi.ng/math/interval" ; import { roundTo } from "@thi.ng/math/prec" ; import type { Vec } from "@thi.ng/vectors" ; import { add2 } from "@thi.ng/vectors/add" ; import { clamp2 } from "@thi.ng/vectors/clamp" ; import { roundN2 } from "@thi.ng/vectors/round" ; import { Key } from "../api.js" ; import type { IMGUI } from "../gui.js" ; export const isHoverSlider = ( gui , id , shape , cursor = "ew-resize" ) => { if ( gui . disabled ) return false ; const aid = gui . activeID ; const hover = aid === id || ( aid === "" && pointInside ( shape , gui . mouse ) ) ; if ( hover ) { gui . setCursor ( cursor ) ; gui . hotID = id ; } return hover ; } ; export const slider1Val = ( x , min , max , prec ) => clamp ( roundTo ( x , prec ) , min , max ) ; export const slider2Val = ( v , min , max , prec ) => clamp2 ( null , roundN2 ( [ ] , v , prec ) , min , max ) ; export const handleSlider1Keys = ( gui , min , max , prec , val ) => { switch ( gui . key ) { case Key . TAB : gui . switchFocus ( ) ; break ; case Key . UP : case Key . DOWN : { const step = ( gui . key === Key . UP ? prec : - prec ) * ( gui . isShiftDown ( ) ? 5 : 1 ) ; return slider1Val ( val + step , min , max , prec ) ; } default : } } ; export const handleSlider2Keys = ( gui , min , max , prec , val , yUp ) => { switch ( gui . key ) { case Key . TAB : gui . switchFocus ( ) ; break ; case Key . LEFT : case Key . RIGHT : { const step = ( gui . key === Key . RIGHT ? prec : - prec ) * ( gui . isShiftDown ( ) ? 5 : 1 ) ; return slider2Val ( add2 ( [ ] , val , [ step , 0 ] ) , min , max , prec ) ; } case Key . UP : case Key . DOWN : { const step = ( gui . key === Key . UP ? prec : - prec ) * ( yUp ? 1 : - 1 ) * ( gui . isShiftDown ( ) ? 5 : 1 ) ; return slider2Val ( add2 ( [ ] , val , [ 0 , step ] ) , min , max , prec ) ; } default : } } ;