Skip to content

Commit 93ca4f0

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 793d5ea commit 93ca4f0

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
}
@@ -1410,11 +1401,11 @@ a.tooltip:hover::after {
14101401
opacity: 1;
14111402
}
14121403

1413-
#settings-menu, #help-button {
1404+
#settings-menu, #help-button, button#toggle-all-docs {
14141405
margin-left: 4px;
14151406
display: flex;
14161407
}
1417-
#settings-menu > a, #help-button > a {
1408+
#settings-menu > a, #help-button > a, button#toggle-all-docs {
14181409
display: flex;
14191410
align-items: center;
14201411
justify-content: center;
@@ -1426,13 +1417,23 @@ a.tooltip:hover::after {
14261417
as an icon, it's okay to specify their sizes in pixels. */
14271418
font-size: 20px;
14281419
width: 33px;
1420+
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
1421+
-webkit-appearance: none;
1422+
opacity: 1;
14291423
}
14301424

14311425
#settings-menu > a:hover, #settings-menu > a:focus,
1432-
#help-button > a:hover, #help-button > a:focus {
1426+
#help-button > a:hover, #help-button > a:focus,
1427+
button#toggle-all-docs:hover, button#toggle-all-docs:focus {
14331428
border-color: var(--settings-button-border-focus);
14341429
}
14351430

1431+
button#toggle-all-docs {
1432+
height: 34px;
1433+
margin-left: 16px;
1434+
float: right;
1435+
}
1436+
14361437
#copy-path {
14371438
color: var(--copy-path-button-color);
14381439
background: var(--main-background-color);
@@ -1532,9 +1533,9 @@ details.toggle > summary.hideme > span {
15321533

15331534
details.toggle > summary::before {
15341535
/* toggle plus */
1535-
background: url('data:image/svg+xml,<svg width="17" height="17" \
1536-
shape-rendering="crispEdges" stroke="black" fill="none" xmlns="http://www.w3.org/2000/svg"><path \
1537-
d="M5 2.5H2.5v12H5m7-12h2.5v12H12M5 8.5h7M8.5 12V8.625v0V5"/></svg>') no-repeat top left;
1536+
background: url('data:image/svg+xml,<svg width="17" height="17" stroke="black" fill="none" \
1537+
xmlns="http://www.w3.org/2000/svg"><path d="M2.5 2.5h12v12h-12v-12.5" \
1538+
shape-rendering="crispEdges"/><path d="M6 8.5h5M8.5 11.5V5.5"/></svg>') no-repeat top left;
15381539
content: "";
15391540
cursor: pointer;
15401541
width: 16px;
@@ -1565,7 +1566,7 @@ details.toggle > summary.hideme::after {
15651566
content: "";
15661567
}
15671568

1568-
details.toggle > summary:focus::before,
1569+
details.toggle > summary:focus-visible::before,
15691570
details.toggle > summary:hover::before {
15701571
opacity: 1;
15711572
}
@@ -1615,7 +1616,7 @@ details.toggle[open] > summary::before {
16151616
/* toggle minus */
16161617
background: url('data:image/svg+xml,<svg width="17" height="17" \
16171618
shape-rendering="crispEdges" stroke="black" fill="none" xmlns="http://www.w3.org/2000/svg"><path \
1618-
d="M5 2.5H2.5v12H5m7-12h2.5v12H12M5 8.5h7"/></svg>') no-repeat top left;
1619+
d="M2.5 2.5h12v12h-12v-12.5" stroke="%23999"/><path d="M6 8.5h5"/></svg>') no-repeat top left;
16191620
}
16201621

16211622
details.toggle[open] > summary::after {
@@ -1666,6 +1667,10 @@ in src-script.js
16661667
flex-direction: column;
16671668
}
16681669

1670+
button#toggle-all-docs {
1671+
margin-top: -8px;
1672+
}
1673+
16691674
.out-of-band {
16701675
text-align: left;
16711676
margin-left: initial;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ function preLoadCss(cssUrl) {
626626
}
627627
});
628628
innerToggle.title = "collapse all docs";
629-
innerToggle.children[0].innerText = "\u2212"; // "\u2212" is "−" minus sign
629+
innerToggle.innerText = "\u2212"; // "\u2212" is "−" minus sign
630630
}
631631

632632
function collapseAllDocs() {
@@ -641,7 +641,7 @@ function preLoadCss(cssUrl) {
641641
}
642642
});
643643
innerToggle.title = "expand all docs";
644-
innerToggle.children[0].innerText = "+";
644+
innerToggle.innerText = "+";
645645
}
646646

647647
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": "#fdffd3"})
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)