Skip to content

Commit

Permalink
Add descriptions to categories on hover (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhhelgeson authored Mar 4, 2024
1 parent 5424f6f commit 5f11215
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 25 deletions.
22 changes: 21 additions & 1 deletion src/components/SampleCategory.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
.sampleCategory {
display: flex;
margin-top: 5px;
margin-bottom: 5px;
display: inline-block;
}

.sampleCategoryDescription {
position: absolute;
background-color: rgba(255, 255, 255, 0.9);
box-shadow: 0 0 5px 10px rgba(255, 255, 255, 0.9);
border-radius: 10px;
transition: opacity 0.3s ease-in, transform 0.2s ease-out
}

.sampleCategoryDescription[data-active='true'] {
opacity: 1;
transform: translateY(-0.5em);
}

.sampleCategoryDescription[data-active='false'] {
opacity: 0;
pointer-events: none;
transform: translateY(0.25em);
}

li.selected a {
color: #ff0000;
Expand Down
22 changes: 20 additions & 2 deletions src/components/SampleCategory.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styles from './SampleCategory.module.css';
import { useState } from 'react';

import { NextRouter } from 'next/router';
import Link from 'next/link';
Expand All @@ -23,17 +24,34 @@ export const SampleCategory = ({
onClickPageLink,
router,
}: SampleCategoryProps) => {
const [displayDescription, setDisplayDescription] = useState<boolean>(false);
const { title, pages, sampleNames } = category;
return (
<div>
<div className={styles.sampleCategory}>
<div
className={styles.sampleCategory}
onMouseEnter={() => {
setDisplayDescription(true);
}}
onMouseLeave={() => {
setDisplayDescription(false);
}}
>
<h3
style={{
marginTop: '5px',
cursor: 'pointer',
width: 'auto',
}}
>
{title}
</h3>

<p
className={styles.sampleCategoryDescription}
data-active={displayDescription}
>
{category.description}
</p>
</div>
{sampleNames.map((slug) => {
return (
Expand Down
4 changes: 4 additions & 0 deletions src/pages/MainLayout.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
max-height: 0px;
}

.panel[data-expanded='false'] {
overflow: hidden;
}

.panel[data-expanded='false'] .panelContents {
max-height: 0vh;
overflow: hidden;
Expand Down
47 changes: 37 additions & 10 deletions src/pages/samples/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const graphicsBasicsPages: PageComponentType = {
rotatingCube: dynamic(() => import('../../sample/rotatingCube/main')),
twoCubes: dynamic(() => import('../../sample/twoCubes/main')),
texturedCube: dynamic(() => import('../../sample/texturedCube/main')),
samplerParameters: dynamic(
() => import('../../sample/samplerParameters/main')
),
instancedCube: dynamic(() => import('../../sample/instancedCube/main')),
fractalCube: dynamic(() => import('../../sample/fractalCube/main')),
cubemap: dynamic(() => import('../../sample/cubemap/main')),
Expand All @@ -33,9 +36,6 @@ const graphicsBasicsPages: PageComponentType = {
// the primary purpose of 'sampleParameters' is to demonstrate their specific nomenclature and
// functionality within the context of the WebGPU API.
const webGPUFeaturesPages: PageComponentType = {
samplerParameters: dynamic(
() => import('../../sample/samplerParameters/main')
),
reversedZ: dynamic(() => import('../../sample/reversedZ/main')),
renderBundles: dynamic(() => import('../../sample/renderBundles/main')),
};
Expand Down Expand Up @@ -94,28 +94,55 @@ const pages: PageComponentType = {

export interface PageCategory {
title: string;
description?: string;
pages: PageComponentType;
sampleNames: string[];
}

const createPageCategory = (
title: string,
pages: PageComponentType
pages: PageComponentType,
description?: string
): PageCategory => {
return {
title,
description,
pages,
sampleNames: Object.keys(pages),
};
};

export const pageCategories: PageCategory[] = [
createPageCategory('Basic Graphics', graphicsBasicsPages),
createPageCategory('WebGPU Features', webGPUFeaturesPages),
createPageCategory('GPGPU Demos', gpuComputeDemoPages),
createPageCategory('Graphics Techniques', graphicsDemoPages),
createPageCategory('Web Platform Integration', webPlatformPages),
createPageCategory('Benchmarks', benchmarkPages),
createPageCategory(
'Basic Graphics',
graphicsBasicsPages,
'Basic rendering functionality implemented with the WebGPU API.'
),
createPageCategory(
'WebGPU Features',
webGPUFeaturesPages,
'Highlights of important WebGPU features.'
),
createPageCategory(
'GPGPU Demos',
gpuComputeDemoPages,
'Visualizations of parallel GPU compute operations.'
),
createPageCategory(
'Graphics Techniques',
graphicsDemoPages,
'A collection of graphics techniques implemented with WebGPU.'
),
createPageCategory(
'Web Platform Integration',
webPlatformPages,
'Demos integrating WebGPU with other functionalities of the web platform.'
),
createPageCategory(
'Benchmarks',
benchmarkPages,
'WebGPU Performance Benchmarks'
),
];

function Page({ slug }: Props): JSX.Element {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ a:hover {
}

h3 {
margin-bottom: 5px;
margin-top: 5px;
margin-bottom: 0px;
margin-top: 0px;
}

main {
Expand Down
5 changes: 1 addition & 4 deletions src/sample/skinnedMesh/glbUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,8 @@ export class GLTFNode {

export class GLTFScene {
nodes?: number[];
name?: any;
extensions?: any;
extras?: any;
[k: string]: any;
root: GLTFNode;
name?: string;

constructor(
device: GPUDevice,
Expand Down
12 changes: 6 additions & 6 deletions src/sample/skinnedMesh/gltf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface Camera {
orthographic?: CameraOrthographic;
perspective?: CameraPerspective;
type: 'perspective' | 'orthographic' | string;
name?: any;
name?: string;
}

export interface Image {
Expand All @@ -123,13 +123,13 @@ export interface MaterialPbrMetallicRoughness {
metallicRoughnessTexture?: TextureInfo;
}
export interface MaterialNormalTextureInfo {
index?: any;
texCoord?: any;
index?: number;
texCoord?: number;
scale?: number;
}
export interface MaterialOcclusionTextureInfo {
index?: any;
texCoord?: any;
index?: number;
texCoord?: number;
strength?: number;
}

Expand Down Expand Up @@ -187,7 +187,7 @@ export interface Sampler {

export interface Scene {
nodes?: GlTfId[];
name?: any;
name?: string;
root?: GLTFNode;
}
export interface Skin {
Expand Down

0 comments on commit 5f11215

Please sign in to comment.