Skip to content

Commit dc2c972

Browse files
cynecxGuillaumeGomez
authored andcommitted
rustdoc: rework source sidebar
1 parent 501b3d2 commit dc2c972

File tree

2 files changed

+57
-47
lines changed

2 files changed

+57
-47
lines changed

src/librustdoc/html/static/css/rustdoc.css

+48-31
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ nav.sub {
334334
}
335335

336336
.source .sidebar {
337-
width: 0px;
337+
width: 50px;
338338
min-width: 0px;
339339
max-width: 300px;
340340
flex-grow: 0;
@@ -343,6 +343,24 @@ nav.sub {
343343
border-right: 1px solid;
344344
transition: width .5s;
345345
overflow-x: hidden;
346+
/* The sidebar is by default hidden */
347+
overflow-y: hidden;
348+
}
349+
350+
.source .sidebar > *:not(:first-child) {
351+
transition: opacity 0.5s, visibility 0.2s;
352+
opacity: 0;
353+
visibility: hidden;
354+
}
355+
356+
.source .sidebar.expanded {
357+
overflow-y: auto;
358+
width: 300px !important;
359+
}
360+
361+
.source .sidebar.expanded > * {
362+
opacity: 1;
363+
visibility: visible;
346364
}
347365

348366
/* Improve the scrollbar display on firefox */
@@ -375,23 +393,15 @@ nav.sub {
375393
}
376394

377395
.logo-container {
378-
height: 100px;
379-
width: 100px;
380-
position: relative;
381-
margin: 20px auto;
382-
display: block;
396+
display: flex;
383397
margin-top: 10px;
398+
margin-bottom: 10px;
399+
justify-content: center;
384400
}
385401

386402
.logo-container > img {
387-
max-width: 100px;
388-
max-height: 100px;
389-
height: 100%;
390-
position: absolute;
391-
left: 50%;
392-
top: 50%;
393-
transform: translate(-50%, -50%);
394-
display: block;
403+
height: 100px;
404+
width: 100px;
395405
}
396406

397407
.sidebar .location {
@@ -1347,19 +1357,18 @@ pre.rust {
13471357
}
13481358

13491359
#sidebar-toggle {
1350-
position: fixed;
1351-
top: 30px;
1352-
left: 300px;
1353-
z-index: 10;
1354-
padding: 3px;
1355-
border-top-right-radius: 3px;
1356-
border-bottom-right-radius: 3px;
1360+
position: sticky;
1361+
top: 0;
1362+
left: 0;
13571363
cursor: pointer;
13581364
font-weight: bold;
1359-
transition: left .5s;
13601365
font-size: 1.2em;
1361-
border: 1px solid;
1362-
border-left: 0;
1366+
border-bottom: 1px solid;
1367+
display: flex;
1368+
height: 40px;
1369+
justify-content: center;
1370+
align-items: center;
1371+
z-index: 10;
13631372
}
13641373
#source-sidebar {
13651374
width: 300px;
@@ -1700,6 +1709,7 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17001709
left: 0;
17011710
margin: 0;
17021711
z-index: 11;
1712+
width: 0;
17031713
}
17041714

17051715
.sidebar.mobile {
@@ -1726,12 +1736,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17261736
padding: 0;
17271737
}
17281738

1729-
.rustdoc.source .sidebar .logo-container {
1730-
width: 100%;
1731-
height: 45px;
1732-
margin: 0 auto;
1733-
}
1734-
17351739
.rustdoc:not(.source) .sidebar .logo-container {
17361740
width: 35px;
17371741
height: 35px;
@@ -1892,12 +1896,25 @@ details.rustdoc-toggle[open] > summary.hideme::after {
18921896
margin: 10px;
18931897
}
18941898

1895-
#sidebar-toggle {
1899+
.sidebar.expanded #sidebar-toggle {
1900+
font-size: 1.5rem;
1901+
}
1902+
1903+
.sidebar:not(.expanded) #sidebar-toggle {
1904+
position: fixed;
1905+
left: 1px;
18961906
top: 100px;
18971907
width: 30px;
18981908
font-size: 1.5rem;
18991909
text-align: center;
19001910
padding: 0;
1911+
z-index: 10;
1912+
border-top-right-radius: 3px;
1913+
border-bottom-right-radius: 3px;
1914+
cursor: pointer;
1915+
font-weight: bold;
1916+
border: 1px solid;
1917+
border-left: 0;
19011918
}
19021919

19031920
#source-sidebar {

src/librustdoc/html/static/js/source-script.js

+9-16
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
7878

7979
function toggleSidebar() {
8080
var sidebar = document.querySelector("nav.sidebar");
81-
var child = this.children[0].children[0];
81+
var child = this.children[0];
8282
if (child.innerText === ">") {
83-
sidebar.style.width = "300px";
84-
this.style.left = "";
83+
sidebar.classList.add("expanded");
8584
child.innerText = "<";
8685
updateLocalStorage("rustdoc-source-sidebar-show", "true");
8786
} else {
88-
sidebar.style.width = "0";
89-
this.style.left = "0";
87+
sidebar.classList.remove("expanded");
9088
child.innerText = ">";
9189
updateLocalStorage("rustdoc-source-sidebar-show", "false");
9290
}
@@ -97,20 +95,15 @@ function createSidebarToggle() {
9795
sidebarToggle.id = "sidebar-toggle";
9896
sidebarToggle.onclick = toggleSidebar;
9997

100-
var inner1 = document.createElement("div");
101-
inner1.style.position = "relative";
98+
var inner = document.createElement("div");
10299

103-
var inner2 = document.createElement("div");
104-
inner2.style.paddingTop = "3px";
105100
if (getCurrentValue("rustdoc-source-sidebar-show") === "true") {
106-
inner2.innerText = "<";
101+
inner.innerText = "<";
107102
} else {
108-
inner2.innerText = ">";
109-
sidebarToggle.style.left = "0";
103+
inner.innerText = ">";
110104
}
111105

112-
inner1.appendChild(inner2);
113-
sidebarToggle.appendChild(inner1);
106+
sidebarToggle.appendChild(inner);
114107
return sidebarToggle;
115108
}
116109

@@ -128,9 +121,9 @@ function createSourceSidebar() {
128121
var sidebar = document.createElement("div");
129122
sidebar.id = "source-sidebar";
130123
if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") {
131-
main.style.width = "0px";
124+
main.classList.remove("expanded");
132125
} else {
133-
main.style.width = "300px";
126+
main.classList.add("expanded");
134127
}
135128

136129
var currentFile = getCurrentFilePath();

0 commit comments

Comments
 (0)