Skip to content

Commit

Permalink
fix timeline mouse click
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Oct 6, 2024
1 parent 8024884 commit 2f361b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/renderer/src/Timeline.module.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
.time-wrapper {
position: absolute;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
}
.time {
background: rgba(0,0,0,0.4);
border-radius: 3;
padding: 2px 4px;
color: rgba(255, 255, 255, 0.8);
transition: opacity 0.2s;
pointer-events: auto;
}
.time:hover {
opacity: 0.1;
}
14 changes: 11 additions & 3 deletions src/renderer/src/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CommandedTime = memo(({ commandedTimePercent }: { commandedTimePercent: st

const timelineHeight = 36;

const timeWrapperStyle: CSSProperties = { position: 'absolute', height: timelineHeight, left: 0, right: 0, bottom: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', pointerEvents: 'none' };
const timeWrapperStyle: CSSProperties = { height: timelineHeight };

function Timeline({
durationSafe,
Expand Down Expand Up @@ -302,7 +302,15 @@ function Timeline({
window.addEventListener('mousemove', onMouseMove);
}, [getMouseTimelinePos, handleScrub, seekAbs]);

const timeRef = useRef<HTMLDivElement>(null);

const onMouseMove = useCallback<MouseEventHandler<HTMLDivElement>>((e) => {
// need to manually check, because we cannot use css :hover when pointer-events: none
// and we need pointer-events: none on time because we want to be able to click through it to segments behind (and they are not parent)
const rect = timeRef.current?.getBoundingClientRect();
const isInBounds = rect && e.clientX >= rect.left && e.clientX <= rect.right && e.clientY >= rect.top && e.clientY <= rect.bottom;
timeRef.current?.style.setProperty('opacity', isInBounds ? '0.2' : '1');

if (!mouseDownRef.current) { // no button pressed
setHoveringTime(getMouseTimelinePos(e.nativeEvent));
}
Expand Down Expand Up @@ -410,8 +418,8 @@ function Timeline({
</div>
</div>

<div style={timeWrapperStyle} onWheel={onWheel}>
<div className={styles['time']}>
<div style={timeWrapperStyle} className={styles['time-wrapper']}>
<div className={styles['time']} ref={timeRef}>
{formatTimeAndFrames(displayTime)}{isZoomed ? ` ${displayTimePercent}` : ''}
</div>
</div>
Expand Down

0 comments on commit 2f361b4

Please sign in to comment.