Skip to content

Commit 5b1b2e9

Browse files
committed
rustdoc: make the header show all three buttons
This tweaks it to use less space for the breadcrumbs.
1 parent d05323c commit 5b1b2e9

26 files changed

+154
-102
lines changed

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

+44-27
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,21 @@ h1, h2, h3, h4 {
177177
position: relative;
178178
display: grid;
179179
grid-template-areas:
180+
"main-heading-breadcrumbs main-heading-breadcrumbs"
180181
"main-heading-h1 main-heading-toolbar"
181182
"main-heading-sub-heading main-heading-toolbar";
182183
grid-template-columns: 1fr max-content;
184+
grid-template-rows: 25px min-content min-content;
183185
padding-bottom: 6px;
184186
margin-bottom: 15px;
185187
}
188+
.rustdoc-breadcrumbs {
189+
grid-area: main-heading-breadcrumbs;
190+
height: 25px;
191+
line-height: 1.25;
192+
display: flex;
193+
align-items: end;
194+
}
186195
/* The only headings that get underlines are:
187196
Markdown-generated headings within the top-doc
188197
Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc)
@@ -228,6 +237,7 @@ a.src,
228237
rustdoc-toolbar,
229238
summary.hideme,
230239
.scraped-example-list,
240+
.rustdoc-breadcrumbs,
231241
/* This selector is for the items listed in the "all items" page. */
232242
ul.all-items {
233243
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
@@ -890,9 +900,10 @@ both the code example and the line numbers, so we need to remove the radius in t
890900
}
891901

892902
.sub-heading {
903+
font-size: 1rem;
893904
flex-grow: 0;
894-
font-size: 1.125rem;
895905
grid-area: main-heading-sub-heading;
906+
line-height: 1.25;
896907
}
897908

898909
.main-heading rustdoc-toolbar, .main-heading .out-of-band {
@@ -953,7 +964,7 @@ div.where {
953964
nav.sub {
954965
flex-grow: 1;
955966
flex-flow: row nowrap;
956-
margin: 4px 0 25px 0;
967+
margin: 4px 0 0 0;
957968
display: flex;
958969
align-items: center;
959970
}
@@ -964,7 +975,7 @@ nav.sub {
964975
flex-grow: 1;
965976
}
966977
.src nav.sub {
967-
margin: 0 0 15px 0;
978+
margin: 0 0 -10px 0;
968979
}
969980

970981
.section-header {
@@ -1074,6 +1085,11 @@ table,
10741085
with boxes (i.e. from the flex layout) */
10751086
align-items: baseline;
10761087
}
1088+
.search-results-title + .sub-heading {
1089+
color: var(--main-color);
1090+
display: flex;
1091+
align-items: center;
1092+
}
10771093
#crate-search-div {
10781094
/* ensures that 100% in properties of #crate-search-div:after
10791095
are relative to the size of this div */
@@ -1298,15 +1314,15 @@ so that we can apply CSS-filters to change the arrow color in themes */
12981314
}
12991315

13001316
#settings.popover {
1301-
--popover-arrow-offset: 118px;
1302-
top: 26px;
1317+
--popover-arrow-offset: 202px;
1318+
top: calc(100% - 12px);
13031319
}
13041320

13051321
/* use larger max-width for help popover, but not for help.html */
13061322
#help.popover {
13071323
max-width: 600px;
1308-
--popover-arrow-offset: 36px;
1309-
top: 26px;
1324+
--popover-arrow-offset: 118px;
1325+
top: calc(100% - 12px);
13101326
}
13111327

13121328
#help dt {
@@ -1722,7 +1738,6 @@ a.tooltip:hover::after {
17221738
}
17231739

17241740
#search-tabs {
1725-
grid-area: main-heading-sub-heading;
17261741
margin-top: 0.25rem;
17271742
display: flex;
17281743
flex-direction: row;
@@ -1788,7 +1803,7 @@ a.tooltip:hover::after {
17881803
#settings-menu, #help-button, button#toggle-all-docs {
17891804
margin-left: var(--button-left-margin);
17901805
display: flex;
1791-
line-height: initial;
1806+
line-height: 1.25;
17921807
}
17931808
#sidebar-button {
17941809
display: none;
@@ -1873,7 +1888,8 @@ button#toggle-all-docs:before {
18731888
content: url('data:image/svg+xml,<svg width="18" height="18" viewBox="0 0 12 12" \
18741889
enable-background="new 0 0 12 12" xmlns="http://www.w3.org/2000/svg" fill="none">\
18751890
<circle r="5.25" cx="6" cy="6" stroke-width="1.25" stroke="black"/>\
1876-
<text x="4.25" y="9" style="font:8px sans-serif;font-weight:1000" fill="black">?</text></svg>');
1891+
<text x="6" y="7" style="font:8px sans-serif;font-weight:1000" text-anchor="middle" \
1892+
dominant-baseline="middle" fill="black">?</text></svg>');
18771893
width: 18px;
18781894
height: 18px;
18791895
filter: var(--settings-menu-filter);
@@ -1894,10 +1910,19 @@ button#toggle-all-docs:before,
18941910
}
18951911
}
18961912

1913+
button[disabled]#toggle-all-docs {
1914+
opacity: 0.25;
1915+
border: solid 1px var(--main-background-color);
1916+
background-size: cover;
1917+
}
1918+
1919+
button[disabled]#toggle-all-docs:hover {
1920+
border: solid 1px var(--main-background-color);
1921+
cursor: not-allowed;
1922+
}
1923+
18971924
rustdoc-toolbar span.label {
1898-
font-size: initial;
1899-
font-variant-caps: small-caps;
1900-
text-transform: lowercase;
1925+
font-size: 1rem;
19011926
flex-grow: 1;
19021927
}
19031928

@@ -2155,15 +2180,6 @@ However, it's not needed with smaller screen width because the doc/code block is
21552180
opacity: 0.75;
21562181
}
21572182

2158-
/* help button is mostly for search */
2159-
#help-button:not(.help-open),
2160-
#alternative-display #toggle-all-docs {
2161-
display: none;
2162-
}
2163-
#alternative-display #help-button {
2164-
display: flex;
2165-
}
2166-
21672183
/* Media Queries */
21682184

21692185
/* Make sure all the buttons line wrap at the same time */
@@ -2206,12 +2222,10 @@ in src-script.js and main.js
22062222
width: 33px;
22072223
}
22082224
#settings.popover {
2209-
--popover-arrow-offset: 48px;
2210-
top: calc(100% - 8px);
2225+
--popover-arrow-offset: 86px;
22112226
}
22122227
#help.popover {
2213-
--popover-arrow-offset: 12px;
2214-
top: calc(100% - 8px);
2228+
--popover-arrow-offset: 48px;
22152229
}
22162230

22172231
.rustdoc {
@@ -2257,6 +2271,9 @@ in src-script.js and main.js
22572271
.src .search-form {
22582272
margin-left: 40px;
22592273
}
2274+
.src .main-heading {
2275+
margin-left: 8px;
2276+
}
22602277
.hide-sidebar .search-form {
22612278
margin-left: 32px;
22622279
}
@@ -2394,7 +2411,7 @@ in src-script.js and main.js
23942411
}
23952412

23962413
.src nav.sub {
2397-
margin: 0;
2414+
margin: 0 0 -25px 0;
23982415
padding: var(--nav-sub-mobile-padding);
23992416
}
24002417
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ function resourcePath(basename, extension) {
1919

2020
function hideMain() {
2121
addClass(document.getElementById(MAIN_ID), "hidden");
22+
const toggle = document.getElementById("toggle-all-docs");
23+
if (toggle) {
24+
toggle.setAttribute("disabled", "disabled");
25+
}
2226
}
2327

2428
function showMain() {
@@ -31,6 +35,10 @@ function showMain() {
3135
}
3236
mainHeading.appendChild(searchState.rustdocToolbar);
3337
}
38+
const toggle = document.getElementById("toggle-all-docs");
39+
if (toggle) {
40+
toggle.removeAttribute("disabled");
41+
}
3442
}
3543

3644
window.rootPath = getVar("root-path");

src/librustdoc/html/static/js/search.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3597,16 +3597,16 @@ async function showResults(results, go_to_first, filterCrates) {
35973597

35983598
let crates = "";
35993599
if (rawSearchIndex.size > 1) {
3600-
crates = " in&nbsp;<div id=\"crate-search-div\"><select id=\"crate-search\">" +
3601-
"<option value=\"all crates\">all crates</option>";
3600+
crates = "<div class=\"sub-heading\"> in&nbsp;<div id=\"crate-search-div\">" +
3601+
"<select id=\"crate-search\"><option value=\"all crates\">all crates</option>";
36023602
for (const c of rawSearchIndex.keys()) {
36033603
crates += `<option value="${c}" ${c === filterCrates && "selected"}>${c}</option>`;
36043604
}
3605-
crates += "</select></div>";
3605+
crates += "</select></div></div>";
36063606
}
36073607

36083608
let output = `<div class="main-heading">\
3609-
<h1 class="search-results-title">Results${crates}</h1></div>`;
3609+
<h1 class="search-results-title">Results</h1>${crates}</div>`;
36103610
if (results.query.error !== null) {
36113611
const error = results.query.error;
36123612
error.forEach((value, index) => {

src/librustdoc/html/static/js/storage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ class RustdocToolbarElement extends HTMLElement {
293293
<div id="settings-menu" tabindex="-1">
294294
<a href="${rootPath}settings.html"><span class="label">Settings</span></a>
295295
</div>
296-
<button id="toggle-all-docs"><span class="label">Summary</span></button>
297296
<div id="help-button" tabindex="-1">
298297
<a href="${rootPath}help.html"><span class="label">Help</span></a>
299-
</div>`;
298+
</div>
299+
<button id="toggle-all-docs"><span class="label">Summary</span></button>`;
300300
}
301301
}
302302
window.customElements.define("rustdoc-toolbar", RustdocToolbarElement);

src/librustdoc/html/templates/print_item.html

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<div class="main-heading"> {# #}
2-
<h1>
3-
{{typ}}
4-
{# The breadcrumbs of the item path, like std::string #}
2+
{% if !path_components.is_empty() %}
3+
<span class="rustdoc-breadcrumbs">
54
{% for component in path_components %}
65
<a href="{{component.path|safe}}index.html">{{component.name}}</a>::<wbr>
76
{% endfor %}
8-
<a class="{{item_type}}" href="#">{{name}}</a> {# #}
7+
</span>
8+
{% endif %}
9+
<h1>
10+
{{typ}}
11+
<span{% if item_type != "mod" +%} class="{{item_type}}"{% endif %}>
12+
{{name}}
13+
</span> {# #}
914
<button id="copy-path" title="Copy item path to clipboard"> {# #}
1015
Copy item path {# #}
1116
</button> {# #}

tests/rustdoc-gui/anchors.goml

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ define-function: (
1212
call-function: ("switch-theme", {"theme": |theme|})
1313

1414
assert-css: ("#toggle-all-docs", {"color": |main_color|})
15-
assert-css: (".main-heading h1 a:nth-of-type(1)", {"color": |main_heading_color|})
16-
assert-css: (".main-heading a:nth-of-type(2)", {"color": |main_heading_type_color|})
15+
assert-css: (".main-heading h1 span", {"color": |main_heading_type_color|})
1716
assert-css: (
1817
".rightside a.src",
1918
{"color": |src_link_color|, "text-decoration": "none solid " + |src_link_color|},
@@ -55,7 +54,7 @@ define-function: (
5554
assert-css: ("#top-doc-prose-title", {"color": |title_color|})
5655

5756
assert-css: (".sidebar .block a", {"color": |sidebar_link_color|})
58-
assert-css: (".main-heading h1 a", {"color": |title_color|})
57+
assert-css: (".main-heading h1", {"color": |title_color|})
5958

6059
// We move the cursor over the "Implementations" title so the anchor is displayed.
6160
move-cursor-to: "h2#implementations"

tests/rustdoc-gui/item-info.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ store-position: (
2020
{"x": second_line_x, "y": second_line_y},
2121
)
2222
assert: |first_line_x| != |second_line_x| && |first_line_x| == 516 && |second_line_x| == 272
23-
assert: |first_line_y| != |second_line_y| && |first_line_y| == 715 && |second_line_y| == 738
23+
assert: |first_line_y| != |second_line_y| && |first_line_y| == 710 && |second_line_y| == 733
2424

2525
// Now we ensure that they're not rendered on the same line.
2626
set-window-size: (1100, 800)

tests/rustdoc-gui/scrape-examples-layout.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ click: ".scraped-example .button-holder .expand"
7272
store-value: (offset_y, 4)
7373

7474
// First with desktop
75-
assert-position: (".scraped-example", {"y": 253})
76-
assert-position: (".scraped-example .prev", {"y": 253 + |offset_y|})
75+
assert-position: (".scraped-example", {"y": 248})
76+
assert-position: (".scraped-example .prev", {"y": 248 + |offset_y|})
7777

7878
// Gradient background should be at the top of the code block.
7979
assert-css: (".scraped-example .example-wrap::before", {"top": "0px"})
@@ -82,8 +82,8 @@ assert-css: (".scraped-example .example-wrap::after", {"bottom": "0px"})
8282
// Then with mobile
8383
set-window-size: (600, 600)
8484
store-size: (".scraped-example .scraped-example-title", {"height": title_height})
85-
assert-position: (".scraped-example", {"y": 284})
86-
assert-position: (".scraped-example .prev", {"y": 284 + |offset_y| + |title_height|})
85+
assert-position: (".scraped-example", {"y": 277})
86+
assert-position: (".scraped-example .prev", {"y": 277 + |offset_y| + |title_height|})
8787

8888
define-function: (
8989
"check_title_and_code_position",

tests/rustdoc-gui/search-filter.goml

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ assert-property: ("#crate-search", {"value": "lib2"})
5656
assert-false: "#results .externcrate"
5757

5858
// Checking that the text for the "title" is correct (the "all crates" comes from the "<select>").
59-
assert-text: (".search-results-title", "Results in all crates", STARTS_WITH)
59+
assert-text: (".search-results-title", "Results", STARTS_WITH)
60+
assert-text: (".search-results-title + .sub-heading", " in all crates", STARTS_WITH)
6061

6162
// Checking the display of the crate filter.
6263
// We start with the light theme.
@@ -84,6 +85,6 @@ wait-for-css: ("#crate-search", {
8485
click: "#theme-ayu"
8586
wait-for-css: ("#crate-search", {
8687
"border": "1px solid #5c6773",
87-
"color": "#fff",
88+
"color": "#c5c5c5",
8889
"background-color": "#0f1419",
8990
})

tests/rustdoc-gui/search-result-display.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ compare-elements-size-near: (
5050
set-window-size: (900, 900)
5151

5252
// First we check the current width, height and position.
53-
assert-css: ("#crate-search", {"width": "223px"})
53+
assert-css: ("#crate-search", {"width": "159px"})
5454
store-size: (".search-results-title", {
5555
"height": search_results_title_height,
5656
"width": search_results_title_width,
@@ -64,7 +64,7 @@ set-text: (
6464
)
6565

6666
// Then we compare again to confirm the height didn't change.
67-
assert-size: ("#crate-search", {"width": 760})
67+
assert-size: ("#crate-search", {"width": 509})
6868
assert-size: (".search-results-title", {
6969
"height": |search_results_title_height|,
7070
})

tests/rustdoc-gui/search-result-go-to-first.goml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ assert-css: ("#main-content", {"display": "none"})
1616
// Now we can check that the feature is working as expected!
1717
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo&go_to_first=true"
1818
// Waiting for the page to load...
19-
wait-for-text: (".main-heading h1", "Struct test_docs::FooCopy item path")
19+
wait-for-text: (".main-heading .rustdoc-breadcrumbs", "test_docs::")
20+
wait-for-text: (".main-heading h1", "Struct FooCopy item path")

tests/rustdoc-gui/sidebar-source-code-display.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ click: "#sidebar-button"
141141
wait-for-css: (".src .sidebar > *", {"visibility": "hidden"})
142142
// We scroll to line 117 to change the scroll position.
143143
scroll-to: '//*[@id="117"]'
144-
store-value: (y_offset, "2567")
144+
store-value: (y_offset, "2564")
145145
assert-window-property: {"pageYOffset": |y_offset|}
146146
// Expanding the sidebar...
147147
click: "#sidebar-button"

tests/rustdoc-gui/source-anchor-scroll.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ set-window-size: (600, 800)
88
assert-property: ("html", {"scrollTop": "0"})
99

1010
click: '//a[text() = "barbar" and @href="#5-7"]'
11-
assert-property: ("html", {"scrollTop": "196"})
11+
assert-property: ("html", {"scrollTop": "194"})
1212
click: '//a[text() = "bar" and @href="#28-36"]'
13-
assert-property: ("html", {"scrollTop": "228"})
13+
assert-property: ("html", {"scrollTop": "225"})
1414
click: '//a[normalize-space() = "sub_fn" and @href="#2-4"]'
15-
assert-property: ("html", {"scrollTop": "124"})
15+
assert-property: ("html", {"scrollTop": "122"})
1616

1717
// We now check that clicking on lines doesn't change the scroll
1818
// Extra information: the "sub_fn" function header is on line 1.
1919
click: '//*[@id="6"]'
20-
assert-property: ("html", {"scrollTop": "124"})
20+
assert-property: ("html", {"scrollTop": "122"})

0 commit comments

Comments
 (0)