Skip to content

Commit 59deae0

Browse files
committed
rustdoc: add "show sidebar" button
1 parent c512955 commit 59deae0

File tree

8 files changed

+47
-6
lines changed

8 files changed

+47
-6
lines changed

src/librustdoc/html/markdown.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,7 @@ fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
15781578
map.insert("themeStyle".into(), 1);
15791579
map.insert("settings-menu".into(), 1);
15801580
map.insert("help-button".into(), 1);
1581+
map.insert("sidebar-button".into(), 1);
15811582
map.insert("main-content".into(), 1);
15821583
map.insert("toggle-all-docs".into(), 1);
15831584
map.insert("all-types".into(), 1);

src/librustdoc/html/static/css/noscript.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rules.
99
margin-left: 0 !important;
1010
}
1111

12-
#copy-path {
12+
#copy-path, #sidebar-button, .sidebar-resizer {
1313
/* It requires JS to work so no need to display it in this case. */
1414
display: none;
1515
}

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,14 @@ a.tooltip:hover::after {
14001400
margin-left: 4px;
14011401
display: flex;
14021402
}
1403-
#settings-menu > a, #help-button > a {
1403+
#sidebar-button {
1404+
display: none;
1405+
}
1406+
.hide-sidebar #sidebar-button {
1407+
display: flex;
1408+
margin-right: 4px;
1409+
}
1410+
#settings-menu > a, #help-button > a, #sidebar-button > a {
14041411
display: flex;
14051412
align-items: center;
14061413
justify-content: center;
@@ -1415,7 +1422,8 @@ a.tooltip:hover::after {
14151422
}
14161423

14171424
#settings-menu > a:hover, #settings-menu > a:focus,
1418-
#help-button > a:hover, #help-button > a:focus {
1425+
#help-button > a:hover, #help-button > a:focus,
1426+
#sidebar-button > a:hover, #sidebar-button > a:focus {
14191427
border-color: var(--settings-button-border-focus);
14201428
}
14211429

src/librustdoc/html/static/css/themes/ayu.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ pre, pre > code,
176176
border-bottom: 1px solid rgba(242, 151, 24, 0.3);
177177
}
178178

179-
#settings-menu > a img {
179+
#settings-menu > a img, #sidebar-button > a img {
180180
filter: invert(100);
181181
}
Loading

src/librustdoc/html/static/js/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,14 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
12311231
}());
12321232

12331233
(function() {
1234+
const sidebarButton = document.getElementById("sidebar-button");
1235+
if (sidebarButton) {
1236+
sidebarButton.addEventListener("click", e => {
1237+
removeClass(document.documentElement, "hide-sidebar");
1238+
updateLocalStorage("hide-sidebar", "false");
1239+
e.preventDefault();
1240+
});
1241+
}
12341242
const resizer = document.getElementsByClassName("sidebar-resizer")[0];
12351243
const sidebar = document.getElementsByClassName("sidebar")[0];
12361244
if (!resizer || !sidebar) {

src/librustdoc/html/static_files.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static_files! {
101101
storage_js => "static/js/storage.js",
102102
scrape_examples_js => "static/js/scrape-examples.js",
103103
wheel_svg => "static/images/wheel.svg",
104+
sidebar_svg => "static/images/sidebar.svg",
104105
clipboard_svg => "static/images/clipboard.svg",
105106
copyright => "static/COPYRIGHT.txt",
106107
license_apache => "static/LICENSE-APACHE.txt",

src/librustdoc/html/templates/page.html

+10-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ <h2></h2> {# #}
125125
{% endif %}
126126
<form class="search-form"> {# #}
127127
<span></span> {# This empty span is a hacky fix for Safari - See #93184 #}
128+
{% if page.css_class != "src" %}
129+
<div id="sidebar-button" tabindex="-1"> {# #}
130+
<a href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}all.html" title="show sidebar"> {# #}
131+
<img width="22" height="22" alt="Show sidebar" {#+ #}
132+
src="{{static_root_path|safe}}{{files.sidebar_svg}}"> {# #}
133+
</a> {# #}
134+
</div> {# #}
135+
{% endif %}
128136
<input {#+ #}
129137
class="search-input" {#+ #}
130138
name="search" {#+ #}
@@ -133,8 +141,8 @@ <h2></h2> {# #}
133141
spellcheck="false" {#+ #}
134142
placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {#+ #}
135143
type="search"> {# #}
136-
<div id="help-button" title="help" tabindex="-1"> {# #}
137-
<a href="{{page.root_path|safe}}help.html">?</a> {# #}
144+
<div id="help-button" tabindex="-1"> {# #}
145+
<a href="{{page.root_path|safe}}help.html" title="help">?</a> {# #}
138146
</div> {# #}
139147
<div id="settings-menu" tabindex="-1"> {# #}
140148
<a href="{{page.root_path|safe}}settings.html" title="settings"> {# #}

0 commit comments

Comments
 (0)