1- import { SVGPause , SVGPlay , SVGRestart , SVGStop } from "@dumbcode/shared/icons" ;
1+ import { SVGLink , SVGPause , SVGPlay , SVGRestart , SVGStop } from "@dumbcode/shared/icons" ;
22import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
33import NumericInput from "../../../components/NumericInput" ;
44import { ButtonWithTooltip } from "../../../components/Tooltips" ;
@@ -22,6 +22,8 @@ const AnimatorScrubBar = ({ animation }: { animation: DcaAnimation | null }) =>
2222 const [ maxGiven ] = useListenableObjectNullable ( animation ?. maxTime )
2323 const max = maxGiven ?? 1
2424
25+ const [ shouldContinueLooping , setShouldContinueLooping ] = useListenableObjectNullable ( animation ?. shouldContinueLooping )
26+
2527 const ref = useRef < HTMLDivElement > ( null )
2628
2729 const isMoving = isHovering || isDragging
@@ -80,18 +82,26 @@ const AnimatorScrubBar = ({ animation }: { animation: DcaAnimation | null }) =>
8082
8183 const onToggle = useCallback ( ( ) => {
8284 setPlaying ( ! isPlaying )
85+ if ( ! isPlaying && animation ?. time . value === 0 ) {
86+ setShouldContinueLooping ( true )
87+ }
8388 } , [ isPlaying , setPlaying ] )
8489
8590 const onRestart = useCallback ( ( ) => {
8691 setTimeAt ( 0 )
8792 setPlaying ( true )
93+ setShouldContinueLooping ( true )
8894 } , [ setTimeAt , setPlaying ] )
8995
9096 const onStop = useCallback ( ( ) => {
9197 setTimeAt ( 0 )
9298 setPlaying ( false )
9399 } , [ setTimeAt , setPlaying ] )
94100
101+ const toggleLooping = ( ) => {
102+ setShouldContinueLooping ( ! shouldContinueLooping )
103+ }
104+
95105 useKeyComboPressed (
96106 useMemo ( ( ) => ( {
97107 animator : {
@@ -108,6 +118,8 @@ const AnimatorScrubBar = ({ animation }: { animation: DcaAnimation | null }) =>
108118 const [ stopName ] = useListenableObject ( keycombos . stop_animation . displayName )
109119 const [ pauseName ] = useListenableObject ( keycombos . pause_or_play . displayName )
110120 const [ resetName ] = useListenableObject ( keycombos . restart_animation . displayName )
121+ const [ loopingName ] = useListenableObject ( keycombos . toggle_looping . displayName )
122+
111123
112124 return (
113125 < div className = "flex flex-col items-center justify-end h-full dark:bg-gray-800 bg-white" >
@@ -123,9 +135,13 @@ const AnimatorScrubBar = ({ animation }: { animation: DcaAnimation | null }) =>
123135 : < SVGPlay className = "h-8 w-8" />
124136 }
125137 </ ButtonWithTooltip >
126- < ButtonWithTooltip tooltip = { `Restart Animation (${ resetName } )` } onClick = { onRestart } className = "z-10 dark:bg-gray-900 bg-gray-200 px-1 rounded-tr-md pt-1 dark:text-gray-400 text-black hover:text-yellow-400 border-r-2 border-t-2 dark:border-black border-white" >
138+ < ButtonWithTooltip tooltip = { `Restart Animation (${ resetName } )` } onClick = { onRestart } className = "z-10 dark:bg-gray-900 bg-gray-200 px-1 pt-1 dark:text-gray-400 text-black hover:text-yellow-400 border-t-2 dark:border-black border-white" >
127139 < SVGRestart className = "h-6 w-6" />
128140 </ ButtonWithTooltip >
141+ < ButtonWithTooltip tooltip = { `Toggle Looping (${ loopingName } )` } onClick = { toggleLooping }
142+ className = { "z-10 dark:bg-gray-900 bg-gray-200 px-1 rounded-tr-md pt-1 border-r-2 border-t-2 dark:border-black border-white " + ( shouldContinueLooping ? "text-blue-500" : "dark:text-gray-400 text-black" ) } >
143+ < SVGLink className = "h-6 w-6" />
144+ </ ButtonWithTooltip >
129145 < div className = "flex-grow" > </ div >
130146 </ div >
131147 </ div >
0 commit comments