From 9186cfc2f8da936f4d5c08515e8a2d6b1b1b1f3a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 26 Jul 2021 11:44:06 +0200 Subject: timecode input working more-ish (prevent page scroll on wheel event) --- components/slideprops.tsx | 48 ++++++++++++++++++++++++----------------------- components/timeinput.tsx | 44 +++++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 37 deletions(-) (limited to 'components') diff --git a/components/slideprops.tsx b/components/slideprops.tsx index ca357b3..aba5c07 100644 --- a/components/slideprops.tsx +++ b/components/slideprops.tsx @@ -8,7 +8,7 @@ import TextField from '@material-ui/core/TextField'; import TimecodeInput from '../components/timeinput'; import { globalState, slideAPIprops } from '../pages/editor'; import { TimedVideoPlayer } from '../pages/present'; -import { anySlide, delaySlide, loopSlide } from '../timeline'; +import { anySlide, delaySlide, loopBeginSlide, loopSlide, speedChangeSlide } from '../timeline'; interface SlidePropertiesPropsType { slide: State; @@ -18,33 +18,35 @@ interface SlidePropertiesPropsType { select: (slides: anySlide[]) => void; } -function SlideTimestamp(props: SlidePropertiesPropsType) { - return { - props.slide.frame.set(newValue); - props.api.start({ frame: newValue }); - props.select([props.slide.attach(Downgraded).value]); - props.global.update.refreshLiveTimeline.value(); - }} - player={props.player} - />; -} - export default function SlideProperties(props: SlidePropertiesPropsType) { - function updateProp(key: keyof slideType) { + function updateProp(key: keyof slideType, springKey?: keyof slideAPIprops) { return (newValue: any) => { // TODO: better typing here props.slide[key as keyof State].set(newValue); + var sel = [props.slide.attach(Downgraded).value]; + if (springKey) props.api.start({ [springKey]: newValue }); + if (sel[0].type == 'loop') { + sel.push(new loopBeginSlide(sel[0] as loopSlide)); + sel.reverse(); + } + props.select(sel); props.global.update.refreshLiveTimeline.value(); }; } + function SlideTimestamp() { + return ; + } + return
Properties {{ 'default': <> - + , 'loop': <> ).beginFrame.get()} - update={updateProp('beginFrame')} + update={updateProp('beginFrame', 'begin')} player={props.player} /> ).frame.get()} - update={updateProp('frame')} + update={updateProp('frame', 'frame')} player={props.player} /> , 'delay': <> - +
, 'speedChange': <> - +
}} - value={(props.slide as State).delay.get()} - onChange={event => updateProp('delay')(Number(event.target.value))} + value={(props.slide as State).newFramerate.get()} + onChange={event => updateProp('newFramerate')(Number(event.target.value))} />
0) dir = -1; + } + + var updateVal = mod * dir; + if (updateVal == 0) return; + props.update(props.value + updateVal); + } + + var stopScroll = (e: WheelEvent) => e.preventDefault(); + useEffect(() => { + (ref.current as HTMLDivElement).addEventListener('wheel', stopScroll, { passive: false }); + return () => (ref.current as HTMLDivElement)?.removeEventListener('wheel', stopScroll); + }); + return e.preventDefault()} - onKeyDown={e => { - var mod = 1; - if (e.shiftKey) mod = 10; - - if (e.key == 'ArrowUp') props.update(props.value + mod); - if (e.key == 'ArrowDown') props.update(props.value - mod); - }} - onWheel={e => { - var mod = 1; - if (e.shiftKey) mod = 10; - - if (e.deltaY < 0) props.update(props.value + mod); - if (e.deltaY > 0) props.update(props.value - mod); - }} + onKeyDown={e => handleMod(e.nativeEvent)} + onWheel={e => handleMod(e.nativeEvent)} + ref={ref} />; } -- cgit v1.2.3