Skip to content

Commit 07e3f99

Browse files
cynecxGuillaumeGomez
authored andcommittedNov 29, 2021
rustdoc: merge source sidebar into main sidebar
1 parent 1e98fb1 commit 07e3f99

File tree

4 files changed

+41
-51
lines changed

4 files changed

+41
-51
lines changed
 

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

+31-32
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ li {
311311
}
312312

313313
.source .content {
314-
margin-top: 50px;
315314
max-width: none;
316315
overflow: visible;
317316
margin-left: 0px;
@@ -335,7 +334,15 @@ nav.sub {
335334
}
336335

337336
.source .sidebar {
338-
display: none;
337+
width: unset;
338+
min-width: 0px;
339+
max-width: 300px;
340+
flex-grow: 0;
341+
flex-shrink: 0;
342+
flex-basis: auto;
343+
border-right: 1px solid;
344+
transition: width .5s;
345+
overflow-x: hidden;
339346
}
340347

341348
/* Improve the scrollbar display on firefox */
@@ -367,18 +374,6 @@ nav.sub {
367374
display: none !important;
368375
}
369376

370-
.logo-source {
371-
display: none;
372-
}
373-
374-
.source .logo-source {
375-
display: block;
376-
position: absolute;
377-
top: 0;
378-
left: 0;
379-
width: 200px;
380-
}
381-
382377
.logo-container {
383378
height: 100px;
384379
width: 100px;
@@ -742,7 +737,7 @@ nav:not(.sidebar) {
742737
margin-bottom: 25px;
743738
}
744739
.source nav:not(.sidebar).sub {
745-
margin-left: 230px;
740+
margin-left: 32px;
746741
}
747742
nav.main {
748743
padding: 20px 0;
@@ -1367,15 +1362,9 @@ pre.rust {
13671362
border-left: 0;
13681363
}
13691364
#source-sidebar {
1370-
position: fixed;
1371-
top: 0;
1372-
bottom: 0;
1373-
left: 0;
13741365
width: 300px;
13751366
z-index: 1;
13761367
overflow: auto;
1377-
transition: left .5s;
1378-
border-right: 1px solid;
13791368
}
13801369
#source-sidebar > .title {
13811370
font-size: 1.5em;
@@ -1696,7 +1685,7 @@ details.rustdoc-toggle[open] > summary.hideme::after {
16961685
flex-direction: column;
16971686
}
16981687

1699-
.rustdoc > .sidebar {
1688+
.rustdoc:not(.source) > .sidebar {
17001689
width: 100%;
17011690
height: 45px;
17021691
min-height: 40px;
@@ -1707,6 +1696,14 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17071696
z-index: 11;
17081697
}
17091698

1699+
.rustdoc.source > .sidebar {
1700+
position: fixed;
1701+
top: 0;
1702+
left: 0;
1703+
margin: 0;
1704+
z-index: 11;
1705+
}
1706+
17101707
.sidebar > .location {
17111708
float: right;
17121709
margin: 0px;
@@ -1722,13 +1719,19 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17221719
padding: 0;
17231720
}
17241721

1725-
.sidebar .logo-container {
1722+
.rustdoc.source .sidebar .logo-container {
1723+
width: 100%;
1724+
height: 45px;
1725+
margin: 0 auto;
1726+
}
1727+
1728+
.rustdoc:not(.source) .sidebar .logo-container {
17261729
width: 35px;
1727-
height: 35px;
1728-
margin-top: 5px;
1729-
margin-bottom: 5px;
1730-
float: left;
1731-
margin-left: 50px;
1730+
height: 35px;
1731+
margin-top: 5px;
1732+
margin-bottom: 5px;
1733+
float: left;
1734+
margin-left: 50px;
17321735
}
17331736

17341737
.sidebar .logo-container > img {
@@ -1944,10 +1947,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
19441947
.search-results div.desc, .search-results .result-description, .item-right {
19451948
padding-left: 2em;
19461949
}
1947-
1948-
.source .logo-source {
1949-
display: none;
1950-
}
19511950
}
19521951

19531952
@media print {

‎src/librustdoc/html/static/css/themes/dark.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pre, .rustdoc.source .example-wrap {
6666
}
6767

6868
.source .sidebar {
69-
background-color: #353535;
69+
background-color: #565656;
7070
}
7171

7272
.sidebar .location {

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
7777
}
7878

7979
function toggleSidebar() {
80-
var sidebar = document.getElementById("source-sidebar");
80+
var sidebar = document.querySelector("nav.sidebar");
8181
var child = this.children[0].children[0];
8282
if (child.innerText === ">") {
83-
sidebar.style.left = "";
83+
sidebar.style.width = "300px";
8484
this.style.left = "";
8585
child.innerText = "<";
8686
updateLocalStorage("rustdoc-source-sidebar-show", "true");
8787
} else {
88-
sidebar.style.left = "-300px";
88+
sidebar.style.width = "0";
8989
this.style.left = "0";
9090
child.innerText = ">";
9191
updateLocalStorage("rustdoc-source-sidebar-show", "false");
@@ -120,15 +120,17 @@ function createSourceSidebar() {
120120
if (!window.rootPath.endsWith("/")) {
121121
window.rootPath += "/";
122122
}
123-
var main = document.getElementById("main");
123+
var main = document.querySelector("nav.sidebar");
124124

125125
var sidebarToggle = createSidebarToggle();
126126
main.insertBefore(sidebarToggle, main.firstChild);
127127

128128
var sidebar = document.createElement("div");
129129
sidebar.id = "source-sidebar";
130130
if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") {
131-
sidebar.style.left = "-300px";
131+
main.style.width = "0px";
132+
} else {
133+
main.style.width = "300px";
132134
}
133135

134136
var currentFile = getCurrentFilePath();
@@ -144,7 +146,7 @@ function createSourceSidebar() {
144146
currentFile, hasFoundFile);
145147
});
146148

147-
main.insertBefore(sidebar, main.firstChild);
149+
main.insertBefore(sidebar, document.querySelector(".sidebar-logo").nextSibling);
148150
// Focus on the current file in the source files sidebar.
149151
var selected_elem = sidebar.getElementsByClassName("selected")[0];
150152
if (typeof selected_elem !== "undefined") {

‎src/librustdoc/html/templates/page.html

+1-12
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
{{- layout.external_html.before_content | safe -}}
6969
<nav class="sidebar"> {#- -#}
7070
<div class="sidebar-menu" role="button">&#9776;</div> {#- -#}
71-
<a href='{{page.root_path | safe}}{{krate_with_trailing_slash | safe}}index.html'> {#- -#}
71+
<a class="sidebar-logo" href='{{page.root_path | safe}}{{krate_with_trailing_slash | safe}}index.html'> {#- -#}
7272
<div class='logo-container rust-logo'> {#- -#}
7373
<img src='
7474
{%- if layout.logo -%}
@@ -83,17 +83,6 @@
8383
</nav> {#- -#}
8484
<main> {#- -#}
8585
<div class="main-inner"> {#- -#}
86-
<a class="logo-source" href='{{page.root_path | safe}}{{krate_with_trailing_slash | safe}}index.html'> {#- -#}
87-
<div class='logo-container rust-logo'> {#- -#}
88-
<img src='
89-
{%- if layout.logo -%}
90-
{{layout.logo}}
91-
{%- else -%}
92-
{{static_root_path | safe}}rust-logo{{page.resource_suffix}}.png
93-
{%- endif -%}
94-
' alt='logo'> {#- -#}
95-
</div> {#- -#}
96-
</a> {#- -#}
9786
<nav class="sub"> {#- -#}
9887
<div class="theme-picker"> {#- -#}
9988
<button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"> {#- -#}

0 commit comments

Comments
 (0)