Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnail make boxes same size #1210

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/main/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ const Thumbnail : React.FC = () => {
<div css={[titleStyle(theme), titleStyleBold(theme)]}>{t('thumbnail.title')}</div>
<ThumbnailTable
inputRefs={inputRefs}
generateRefs={generateRefs}
generate={generate}
upload={upload}
uploadCallback={uploadCallback}
discard={discardThumbnail}
/>
<div css={bottomStyle}>
{/* use maxHeightInPixel to make video players the same size*/}
<VideoPlayers refs={generateRefs} widthInPercent={100} maxHeightInPixel={376}/>
<VideoPlayers refs={generateRefs} widthInPercent={100} maxHeightInPixel={420}/>
<div css={videosStyle(theme)}>
<Timeline
timelineHeight={125}
Expand Down Expand Up @@ -141,16 +142,18 @@ const Thumbnail : React.FC = () => {
*/
const ThumbnailTable : React.FC<{
inputRefs: any,
generateRefs: React.MutableRefObject<any>,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
}> = ({inputRefs, generate, upload, uploadCallback, discard}) => {
}> = ({inputRefs, generateRefs, generate, upload, uploadCallback, discard}) => {

const videoTracks = useSelector(selectVideos)

const thumbnailTableStyle = css({
display: 'flex',
width: '100%',
flexDirection: 'row',
justifyContent: 'center',
...(flexGapReplacementStyle(10, false)),
Expand Down Expand Up @@ -184,6 +187,7 @@ const ThumbnailTable : React.FC<{
track={track}
index={index}
inputRefs={inputRefs}
generateRef={generateRefs.current[index]}
generate={generate}
upload={upload}
uploadCallback={uploadCallback}
Expand All @@ -209,15 +213,19 @@ const ThumbnailTableRow: React.FC<{
track: Track,
index: number,
inputRefs: any,
generateRef: any,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
}> = ({track, index, inputRefs, generate, upload, uploadCallback, discard}) => {
}> = ({track, index, inputRefs, generateRef, generate, upload, uploadCallback, discard}) => {

const { t } = useTranslation()
const theme = useTheme();

// The "+40" comes from padding that is not included in the "getWidth" function
const videoWidth = generateRef ? generateRef.getWidth() + 40 : undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using offsetWidth instead of clientWidth remove the need to add 40 manually?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sad 🤷


const renderPriority = (thumbnailPriority: number) => {
if (isNaN(thumbnailPriority)) {
return ""
Expand All @@ -233,7 +241,7 @@ const ThumbnailTableRow: React.FC<{
}

return (
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle]}>
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle(videoWidth)]}>
<div css={thumbnailTableRowTitleStyle}>
{track.flavor.type + renderPriority(track.thumbnailPriority)}
</div>
Expand Down Expand Up @@ -499,7 +507,7 @@ const ThumbnailTableSingleRow: React.FC<{
const theme = useTheme();

return (
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle]}>
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle(500)]}>
<div css={thumbnailTableRowTitleStyle}>
{t("thumbnailSimple.rowTitle")}
</div>
Expand Down Expand Up @@ -582,9 +590,11 @@ const ThumbnailButtonsSimple : React.FC<{
/**
* CSS shared between multi and simple display mode
*/
const thumbnailTableRowStyle = css({
const thumbnailTableRowStyle = (maxWidth: number) => css({
display: 'flex',
flexDirection: 'column',
width: '100%',
maxWidth: `${maxWidth}px`,
})

const thumbnailTableRowTitleStyle = css({
Expand Down
3 changes: 3 additions & 0 deletions src/main/VideoPlayers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ export const VideoPlayer = React.forwardRef(
canvasContext.drawImage(video, 0, 0);
return canvas.toDataURL('image/png')
}
},
getWidth() {
return (ref.current?.getInternalPlayer() as HTMLVideoElement).clientWidth
}
}));

Expand Down
Loading