Skip to content

Commit c4a7df7

Browse files
committed
rustdoc: redesign [+]/[−] controls
This is a continuation of rust-lang#107658 and rust-lang#59851, making the toggles consistent with other buttons, instead of looking like syntax. The tactics to improve the look of these controls: * When the toggle is expanded, the minus sign remains as dark as before, but the border is lighter. The plus sign has a border that's the same color as the label (black, on the default theme). This makes expansion buttons more prominent, easier to tell apart from collapse buttons. * The plus sign is slightly taller than wide, also to make it easier to tell apart from the minus sign. * The use of crispEdges has to get a bit strategic to make this come out right. I've tested it on Firefox, Safari, and Chromium, but it's a bit hard to be sure it works right on all setups. * Does anybody know some trick to do crispEdges on only the X axis, while still allowing antialiasing on the Y? * The "toggle all" button is modeled after the Help and Settings buttons, with a matching border, width, and +/− label.
1 parent 9fa6bdd commit c4a7df7

File tree

9 files changed

+60
-42
lines changed

9 files changed

+60
-42
lines changed

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

+24-19
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ h1, h2, h3, h4 {
138138
margin-top: 0;
139139
}
140140
.main-heading h1 {
141-
margin: 0;
141+
margin: 9px 0 0 0;
142142
padding: 0;
143143
flex-grow: 1;
144144
/* We use overflow-wrap: break-word for Safari, which doesn't recognize
@@ -293,15 +293,6 @@ button {
293293

294294
/* end tweaks for normalize.css 8 */
295295

296-
button#toggle-all-docs {
297-
padding: 0;
298-
background: none;
299-
border: none;
300-
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
301-
-webkit-appearance: none;
302-
opacity: 1;
303-
}
304-
305296
.rustdoc {
306297
display: flex;
307298
flex-direction: row;
@@ -666,7 +657,7 @@ pre, .rustdoc.src .example-wrap {
666657
nav.sub {
667658
flex-grow: 1;
668659
flex-flow: row nowrap;
669-
margin: 4px 0 25px 0;
660+
margin: 4px 0 16px 0;
670661
display: flex;
671662
align-items: center;
672663
}
@@ -1326,11 +1317,11 @@ a.tooltip:hover::after {
13261317
opacity: 1;
13271318
}
13281319

1329-
#settings-menu, #help-button {
1320+
#settings-menu, #help-button, button#toggle-all-docs {
13301321
margin-left: 4px;
13311322
display: flex;
13321323
}
1333-
#settings-menu > a, #help-button > a {
1324+
#settings-menu > a, #help-button > a, button#toggle-all-docs {
13341325
display: flex;
13351326
align-items: center;
13361327
justify-content: center;
@@ -1342,13 +1333,23 @@ a.tooltip:hover::after {
13421333
as an icon, it's okay to specify their sizes in pixels. */
13431334
font-size: 20px;
13441335
width: 33px;
1336+
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
1337+
-webkit-appearance: none;
1338+
opacity: 1;
13451339
}
13461340

13471341
#settings-menu > a:hover, #settings-menu > a:focus,
1348-
#help-button > a:hover, #help-button > a:focus {
1342+
#help-button > a:hover, #help-button > a:focus,
1343+
button#toggle-all-docs:hover, button#toggle-all-docs:focus {
13491344
border-color: var(--settings-button-border-focus);
13501345
}
13511346

1347+
button#toggle-all-docs {
1348+
height: 34px;
1349+
margin-left: 16px;
1350+
float: right;
1351+
}
1352+
13521353
#copy-path {
13531354
color: var(--copy-path-button-color);
13541355
background: var(--main-background-color);
@@ -1448,9 +1449,9 @@ details.toggle > summary.hideme > span {
14481449

14491450
details.toggle > summary::before {
14501451
/* toggle plus */
1451-
background: url('data:image/svg+xml,<svg width="17" height="17" \
1452-
shape-rendering="crispEdges" stroke="black" fill="none" xmlns="http://www.w3.org/2000/svg"><path \
1453-
d="M5 2.5H2.5v12H5m7-12h2.5v12H12M5 8.5h7M8.5 12V8.625v0V5"/></svg>') no-repeat top left;
1452+
background: url('data:image/svg+xml,<svg width="17" height="17" stroke="black" fill="none" \
1453+
xmlns="http://www.w3.org/2000/svg"><path d="M2.5 2.5h12v12h-12v-12.5" \
1454+
shape-rendering="crispEdges"/><path d="M6 8.5h5M8.5 11.5V5.5"/></svg>') no-repeat top left;
14541455
content: "";
14551456
cursor: pointer;
14561457
width: 16px;
@@ -1481,7 +1482,7 @@ details.toggle > summary.hideme::after {
14811482
content: "";
14821483
}
14831484

1484-
details.toggle > summary:focus::before,
1485+
details.toggle > summary:focus-visible::before,
14851486
details.toggle > summary:hover::before {
14861487
opacity: 1;
14871488
}
@@ -1531,7 +1532,7 @@ details.toggle[open] > summary::before {
15311532
/* toggle minus */
15321533
background: url('data:image/svg+xml,<svg width="17" height="17" \
15331534
shape-rendering="crispEdges" stroke="black" fill="none" xmlns="http://www.w3.org/2000/svg"><path \
1534-
d="M5 2.5H2.5v12H5m7-12h2.5v12H12M5 8.5h7"/></svg>') no-repeat top left;
1535+
d="M2.5 2.5h12v12h-12v-12.5" stroke="%23999"/><path d="M6 8.5h5"/></svg>') no-repeat top left;
15351536
}
15361537

15371538
details.toggle[open] > summary::after {
@@ -1582,6 +1583,10 @@ in src-script.js
15821583
flex-direction: column;
15831584
}
15841585

1586+
button#toggle-all-docs {
1587+
margin-top: -8px;
1588+
}
1589+
15851590
.out-of-band {
15861591
text-align: left;
15871592
margin-left: initial;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ function preLoadCss(cssUrl) {
635635
}
636636
});
637637
innerToggle.title = "collapse all docs";
638-
innerToggle.children[0].innerText = "\u2212"; // "\u2212" is "−" minus sign
638+
innerToggle.innerText = "\u2212"; // "\u2212" is "−" minus sign
639639
}
640640

641641
function collapseAllDocs() {
@@ -650,7 +650,7 @@ function preLoadCss(cssUrl) {
650650
}
651651
});
652652
innerToggle.title = "expand all docs";
653-
innerToggle.children[0].innerText = "+";
653+
innerToggle.innerText = "+";
654654
}
655655

656656
function toggleAllDocs() {

src/librustdoc/html/templates/print_item.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ <h1>
1818
{% endif %}
1919
{% match src_href %}
2020
{% when Some with (href) %}
21-
<a class="src" href="{{href|safe}}">source</a> · {#+ #}
21+
<a class="src" href="{{href|safe}}">source</a> {#+ #}
2222
{% else %}
2323
{% endmatch %}
2424
<button id="toggle-all-docs" title="collapse all docs"> {# #}
25-
[<span>&#x2212;</span>] {# #}
25+
&#x2212; {# #}
2626
</button> {# #}
2727
</span> {# #}
2828
</div> {# #}

tests/rustdoc-gui/anchors.goml

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
define-function: (
44
"check-colors",
5-
(theme, main_color, title_color, main_heading_color, main_heading_type_color, src_link_color, sidebar_link_color),
5+
(
6+
theme,
7+
main_color,
8+
title_color,
9+
main_heading_color,
10+
main_heading_type_color,
11+
src_link_color,
12+
sidebar_link_color,
13+
button_color,
14+
),
615
block {
716
go-to: "file://" + |DOC_PATH| + "/staged_api/struct.Foo.html"
817
// This is needed to ensure that the text color is computed.
@@ -13,7 +22,7 @@ define-function: (
1322
// We reload the page so the local storage settings are being used.
1423
reload:
1524

16-
assert-css: ("#toggle-all-docs", {"color": |main_color|})
25+
assert-css: ("#toggle-all-docs", {"color": |button_color|})
1726
assert-css: (".main-heading h1 a:nth-of-type(1)", {"color": |main_heading_color|})
1827
assert-css: (".main-heading a:nth-of-type(2)", {"color": |main_heading_type_color|})
1928
assert-css: (
@@ -81,6 +90,7 @@ call-function: (
8190
"main_heading_type_color": "#ffa0a5",
8291
"src_link_color": "#39afd7",
8392
"sidebar_link_color": "#53b1db",
93+
"button_color": "#fff",
8494
},
8595
)
8696
call-function: (
@@ -93,6 +103,7 @@ call-function: (
93103
"main_heading_type_color": "#2dbfb8",
94104
"src_link_color": "#d2991d",
95105
"sidebar_link_color": "#fdbf35",
106+
"button_color": "#000",
96107
},
97108
)
98109
call-function: (
@@ -105,5 +116,6 @@ call-function: (
105116
"main_heading_type_color": "#ad378a",
106117
"src_link_color": "#3873ad",
107118
"sidebar_link_color": "#356da4",
119+
"button_color": "black",
108120
},
109121
)

tests/rustdoc-gui/shortcuts.goml

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ press-key: "Escape"
1313
assert-css: ("#help-button .popover", {"display": "none"})
1414
// Checking doc collapse and expand.
1515
// It should be displaying a "-":
16-
assert-text: ("#toggle-all-docs", "[−]")
16+
assert-text: ("#toggle-all-docs", "")
1717
press-key: "-"
18-
wait-for-text: ("#toggle-all-docs", "[+]")
18+
wait-for-text: ("#toggle-all-docs", "+")
1919
assert-attribute: ("#toggle-all-docs", {"class": "will-expand"})
2020
// Pressing it again shouldn't do anything.
2121
press-key: "-"
22-
assert-text: ("#toggle-all-docs", "[+]")
22+
assert-text: ("#toggle-all-docs", "+")
2323
assert-attribute: ("#toggle-all-docs", {"class": "will-expand"})
2424
// Expanding now.
2525
press-key: "+"
26-
wait-for-text: ("#toggle-all-docs", "[−]")
26+
wait-for-text: ("#toggle-all-docs", "")
2727
assert-attribute: ("#toggle-all-docs", {"class": ""})
2828
// Pressing it again shouldn't do anything.
2929
press-key: "+"
30-
assert-text: ("#toggle-all-docs", "[−]")
30+
assert-text: ("#toggle-all-docs", "")
3131
assert-attribute: ("#toggle-all-docs", {"class": ""})

tests/rustdoc-gui/sidebar.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ assert-css: ("#modules", {"background-color": "rgb(253, 255, 211)"})
144144

145145
// Finally, assert that the `[+]/[−]` toggle doesn't affect sidebar width.
146146
click: "#toggle-all-docs"
147-
assert-text: ("#toggle-all-docs", "[+]")
147+
assert-text: ("#toggle-all-docs", "+")
148148
assert-property: (".sidebar", {"clientWidth": "200"})
149149
click: "#toggle-all-docs"
150-
assert-text: ("#toggle-all-docs", "[−]")
150+
assert-text: ("#toggle-all-docs", "")
151151
assert-property: (".sidebar", {"clientWidth": "200"})
152152

153153
// Checks that all.html and index.html have their sidebar link in the same place.

tests/rustdoc-gui/toggle-docs.goml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// Checks that the documentation toggles have the correct position, style and work as expected.
22
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
33
assert-attribute: ("#main-content > details.top-doc", {"open": ""})
4-
assert-text: ("#toggle-all-docs", "[−]")
4+
assert-text: ("#toggle-all-docs", "")
55
click: "#toggle-all-docs"
66
wait-for: 50
77
// This is now collapsed so there shouldn't be the "open" attribute on details.
88
assert-attribute-false: ("#main-content > details.top-doc", {"open": ""})
9-
assert-text: ("#toggle-all-docs", "[+]")
9+
assert-text: ("#toggle-all-docs", "+")
1010
assert-css: (
1111
"#main-content > details.top-doc > summary",
1212
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
1313
)
1414
click: "#toggle-all-docs"
1515
// Not collapsed anymore so the "open" attribute should be back.
1616
wait-for-attribute: ("#main-content > details.top-doc", {"open": ""})
17-
assert-text: ("#toggle-all-docs", "[−]")
17+
assert-text: ("#toggle-all-docs", "")
1818

1919
// Check that it works on non-module pages as well.
2020
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
2121
// We first check that everything is visible.
22-
assert-text: ("#toggle-all-docs", "[−]")
22+
assert-text: ("#toggle-all-docs", "")
2323
assert-attribute: ("#implementations-list details.toggle", {"open": ""}, ALL)
2424
assert-attribute: ("#trait-implementations-list details.toggle", {"open": ""}, ALL)
2525
assert-attribute-false: (
@@ -30,7 +30,7 @@ assert-attribute-false: (
3030

3131
// We collapse them all.
3232
click: "#toggle-all-docs"
33-
wait-for-text: ("#toggle-all-docs", "[+]")
33+
wait-for-text: ("#toggle-all-docs", "+")
3434
// We check that all <details> are collapsed (except for the impl block ones).
3535
assert-attribute-false: ("details.toggle:not(.implementors-toggle)", {"open": ""}, ALL)
3636
assert-attribute: ("#implementations-list > details.implementors-toggle", {"open": ""})
@@ -42,7 +42,7 @@ assert-attribute-false: (
4242
)
4343
// We open them all again.
4444
click: "#toggle-all-docs"
45-
wait-for-text: ("#toggle-all-docs", "[−]")
45+
wait-for-text: ("#toggle-all-docs", "")
4646
assert-attribute: ("details.toggle", {"open": ""}, ALL)
4747

4848
// Checking the toggles style.

tests/rustdoc-gui/type-declation-overflow.goml

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ assert-css: (".mobile-topbar h2", {"overflow-x": "hidden"})
4747
// On desktop, they wrap when too big.
4848
set-window-size: (1100, 800)
4949
go-to: "file://" + |DOC_PATH| + "/lib2/too_long/struct.SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName.html"
50-
compare-elements-position-false: (".main-heading h1", ".main-heading .out-of-band", ("y"))
50+
store-position: (".main-heading .out-of-band", {"y": out_of_band_long_y})
5151
go-to: "file://" + |DOC_PATH| + "/lib2/index.html"
52-
compare-elements-position: (".main-heading h1", ".main-heading .out-of-band", ("y"))
52+
store-position: (".main-heading .out-of-band", {"y": out_of_band_lib2_y})
53+
assert: |out_of_band_long_y| > |out_of_band_lib2_y|
5354
// make sure there is a gap between them
5455
compare-elements-position-near-false: (".main-heading h1", ".main-heading .out-of-band", {"x": 550})
5556

tests/rustdoc/source-version-separator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(staged_api)]
44

55
// @has foo/trait.Bar.html
6-
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · '
6+
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source'
77
#[stable(feature = "bar", since = "1.0")]
88
pub trait Bar {
99
// @has - '//*[@id="tymethod.foo"]/*[@class="rightside"]' '3.0 · source'
@@ -14,7 +14,7 @@ pub trait Bar {
1414
// @has - '//div[@id="implementors-list"]//*[@class="rightside"]' '4.0 · source'
1515

1616
// @has foo/struct.Foo.html
17-
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source · '
17+
// @has - '//div[@class="main-heading"]/*[@class="out-of-band"]' '1.0 · source'
1818
#[stable(feature = "baz", since = "1.0")]
1919
pub struct Foo;
2020

0 commit comments

Comments
 (0)