-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
430dde1
commit a551600
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
packages/desktop/src/renderer/components/ParamVector3/ParamVector3.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* TODO: This CSS will eventually be removed when Vector3 is a dumb (compound) component in core */ | ||
.container { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 0.5rem; | ||
height: 100%; | ||
} | ||
|
||
.item { | ||
flex: 1; | ||
height: 100%; | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/desktop/src/renderer/components/ParamVector3/ParamVector3.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useRef } from 'react' | ||
import { useInterval } from 'usehooks-ts' | ||
import { NodeParamVector3 } from '@hedron/engine' | ||
import c from './ParamVector3.module.css' | ||
import { FloatSlider, FloatSliderHandle } from '@components/core/FloatSlider/FloatSlider' | ||
import { useOnNodeValueChange } from '@components/hooks/useOnNodeValueChange' | ||
import { engineStore, useEngineStore } from '@renderer/engine' | ||
|
||
interface ParamVector3Props { | ||
id: string | ||
} | ||
|
||
const SingleSlider = ({ id }: ParamVector3Props) => { | ||
const ref = useRef<FloatSliderHandle>(null) | ||
const onValueChange = useOnNodeValueChange(id) | ||
|
||
useInterval(() => { | ||
const nodeValue = engineStore.getState().nodeValues[id] | ||
if (typeof nodeValue !== 'number') { | ||
throw new Error('VectorComponentSlider value was not a number') | ||
} | ||
ref.current?.drawBar(nodeValue) | ||
}, 100) | ||
|
||
return <FloatSlider ref={ref} onValueChange={onValueChange} /> | ||
} | ||
|
||
export const ParamVector3 = ({ id }: ParamVector3Props) => { | ||
const node = useEngineStore((state) => state.nodes[id] as NodeParamVector3) | ||
|
||
const { childNodeIds } = node | ||
|
||
return ( | ||
<div className={c.container}> | ||
{childNodeIds.map((childId) => ( | ||
<div key={childId} className={c.item}> | ||
<SingleSlider key={childId} id={childId} /> | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters