Compare commits
2 Commits
main
...
kurt/live-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
143371166a | ||
|
|
14600d3899 |
@@ -7,6 +7,7 @@ import {
|
|||||||
CadhubBooleanParam,
|
CadhubBooleanParam,
|
||||||
CadhubNumberParam,
|
CadhubNumberParam,
|
||||||
} from './customizerConverter'
|
} from './customizerConverter'
|
||||||
|
import { debounce } from 'lodash'
|
||||||
|
|
||||||
const Customizer = () => {
|
const Customizer = () => {
|
||||||
const [open, setOpen] = React.useState(false)
|
const [open, setOpen] = React.useState(false)
|
||||||
@@ -186,7 +187,18 @@ function NumberParam({
|
|||||||
const [localValue, localValueSetter] = React.useState(0)
|
const [localValue, localValueSetter] = React.useState(0)
|
||||||
const [isLocked, isLockedSetter] = React.useState(false)
|
const [isLocked, isLockedSetter] = React.useState(false)
|
||||||
const [pixelsDragged, pixelsDraggedSetter] = React.useState(0)
|
const [pixelsDragged, pixelsDraggedSetter] = React.useState(0)
|
||||||
|
const handleRender = useRender()
|
||||||
|
const liveRenderHandler = debounce((a) => handleRender(a), 250)
|
||||||
const step = param.step || 1
|
const step = param.step || 1
|
||||||
|
const live = false // TODO get from param
|
||||||
|
let decimal = 0
|
||||||
|
if('decimal' in param){
|
||||||
|
decimal = param.decimal
|
||||||
|
}else{
|
||||||
|
let str = String(step)
|
||||||
|
const idx = str.indexOf('.')
|
||||||
|
if(idx !== -1) decimal = str.length - idx - 1
|
||||||
|
}
|
||||||
const commitChange = () => {
|
const commitChange = () => {
|
||||||
let num = localValue
|
let num = localValue
|
||||||
if (typeof param.step === 'number') {
|
if (typeof param.step === 'number') {
|
||||||
@@ -198,7 +210,7 @@ function NumberParam({
|
|||||||
if (typeof param.max === 'number') {
|
if (typeof param.max === 'number') {
|
||||||
num = Math.min(param.max, num)
|
num = Math.min(param.max, num)
|
||||||
}
|
}
|
||||||
num = Number(num.toFixed(2))
|
num = Number(num.toFixed(decimal))
|
||||||
localValueSetter(num)
|
localValueSetter(num)
|
||||||
onChange(num)
|
onChange(num)
|
||||||
}
|
}
|
||||||
@@ -245,7 +257,9 @@ function NumberParam({
|
|||||||
onMouseMove={({ movementX }) => {
|
onMouseMove={({ movementX }) => {
|
||||||
if (isLocked && movementX) {
|
if (isLocked && movementX) {
|
||||||
pixelsDraggedSetter(pixelsDragged + (movementX * step) / 8) // one step per 8 pixels
|
pixelsDraggedSetter(pixelsDragged + (movementX * step) / 8) // one step per 8 pixels
|
||||||
localValueSetter(Number(pixelsDragged.toFixed(2)))
|
const decimalFixed = Number((Math.round(pixelsDragged / step) * step).toFixed(decimal))
|
||||||
|
localValueSetter(decimalFixed)
|
||||||
|
if(live) liveRenderHandler({[param.name]: decimalFixed})
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useIdeContext } from 'src/helpers/hooks/useIdeContext'
|
|||||||
|
|
||||||
export const useRender = () => {
|
export const useRender = () => {
|
||||||
const { state, thunkDispatch } = useIdeContext()
|
const { state, thunkDispatch } = useIdeContext()
|
||||||
return () => {
|
return (paramOverrides: {[key: string]: any} = {}) => {
|
||||||
thunkDispatch((dispatch, getState) => {
|
thunkDispatch((dispatch, getState) => {
|
||||||
const state = getState()
|
const state = getState()
|
||||||
dispatch({ type: 'setLoading' })
|
dispatch({ type: 'setLoading' })
|
||||||
@@ -13,7 +13,10 @@ export const useRender = () => {
|
|||||||
code: state.code,
|
code: state.code,
|
||||||
viewerSize: state.viewerSize,
|
viewerSize: state.viewerSize,
|
||||||
camera: state.camera,
|
camera: state.camera,
|
||||||
parameters: state.currentParameters,
|
parameters: {
|
||||||
|
...state.currentParameters,
|
||||||
|
...paramOverrides,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
localStorage.setItem(makeCodeStoreKey(state.ideType), state.code)
|
localStorage.setItem(makeCodeStoreKey(state.ideType), state.code)
|
||||||
|
|||||||
Reference in New Issue
Block a user