Skip to content

Commit

Permalink
Change examples page menu on smaller screens (#4958)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone authored Jan 2, 2024
1 parent e26a853 commit aa48558
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Passing an owned value `window` to `Surface` will return a `Surface<'static>`. S
### Examples

- remove winit dependency from hello-compute example by @psvri in [#4699](https://github.com/gfx-rs/wgpu/pull/4699)
- Made the examples page not crash on Chrome on Android, and responsive to screen sizes by @Dinnerbone in [#4958](https://github.com/gfx-rs/wgpu/pull/4958)

## v0.18.1 (2023-11-15)

Expand Down
1 change: 1 addition & 0 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ fn print_examples() {

let item = document.create_element("div").unwrap();
item.append_child(&link).unwrap();
item.set_class_name("example-item");
ul.append_child(&item).unwrap();
}
}
Expand Down
71 changes: 69 additions & 2 deletions examples/static/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
:focus {
Expand All @@ -22,10 +23,21 @@
flex-direction: column;
}

.banner {
#banner {
background: #dee;
padding: 0.5em 0;
border-bottom: 1px solid #abb;

@media only screen and (max-width: 1000px) {
max-height: 0;
transition: max-height 0.15s ease;
overflow: hidden;
padding: 0;
}
}

#banner.visible {
max-height: 100%;
}

.banner-prefix {
Expand All @@ -42,6 +54,10 @@
display: flex;
flex-direction: row;
justify-content: space-evenly;

@media only screen and (max-width: 1000px) {
flex-direction: column;
}
}

.backend-list {
Expand All @@ -57,6 +73,21 @@
flex-wrap: wrap;
align-content: center;
height: 100px;

@media only screen and (max-width: 1000px) {
flex-direction: row;
height: initial;
}
}

.example-item {
@media only screen and (max-width: 1000px) {
width: 33vw;
}

@media only screen and (max-width: 500px) {
width: 50vw;
}
}

.example-link {
Expand All @@ -75,12 +106,36 @@
/* This forces CSS to ignore the width/height of the canvas, this is needed for WebGL */
contain: size;
}


#menu-button {
display: none;

@media only screen and (max-width: 1000px) {
display: block;
width: 30px;
height: 33px;
margin: 0 auto;
}
}

#menu-button span {
display: block;
width: 100%;
height: 3px;
margin: 6px auto;
background-color: #333;
transition: all 0.3s ease-in-out;
}

</style>
</head>

<body>
<div class="root">
<div class="banner">
<div id="menu-button"><span></span><span></span><span></span></div>

<div id="banner">
<div class="banner-prefix">
<p>
<a href="../index.html">
Expand Down Expand Up @@ -116,6 +171,18 @@
`${window.location.href}?backend=webgl2&example=hello_triangle`
);
}

const menuButton = document.getElementById("menu-button");
const banner = document.getElementById("banner");
menuButton.onclick = () => {
if (menuButton.classList.contains("active")) {
menuButton.classList.remove("active");
banner.classList.remove("visible");
} else {
menuButton.classList.add("active");
banner.classList.add("visible");
}
};
</script>
</body>

Expand Down

0 comments on commit aa48558

Please sign in to comment.