Skip to content

Commit 7d1a382

Browse files
authored
Rollup merge of rust-lang#90155 - jsha:outdent-methods, r=GuillaumeGomez,camelid
Fix alignment of method headings for scannability We sometimes use indentation to indicate something is a heading: The section that comes after is indented by 24px relative to the heading. However, the relationship between the "Implementations" section heading, the `impl` headings it contains, and the `pub fn` subheadings within each impl, is awkward. It goes **Implementations**, 15px indent, `impl`, 5px indent, `pub fn`, 4px indent, docblock. I line up `impl` and `pub fn` with the `Implementations` heading, give `impl` a larger font size to indicate it is higher in the hierarchy, and indent the docblock a full 24px relative to their parent, matching the indents we use elsewhere to distinguish section headings. By letting the `pub fn` stick out to the left of the docblock, I think this makes methods significantly more scannable. Related to rust-lang#59829 r? `@camelid` [Old](https://doc.rust-lang.org/nightly/std/string/struct.String.html#implementations): [![image](https://user-images.githubusercontent.com/220205/138380233-9c63a0f2-0f80-40a3-ab3d-a1ee9fb7c5d8.png)](https://doc.rust-lang.org/nightly/std/string/struct.String.html#implementations) [New](https://jacob.hoffman-andrews.com/rust/outdent-methods/std/string/struct.String.html#implementations): [![image](https://user-images.githubusercontent.com/220205/138392479-b45fce3f-bf43-42e0-81ee-c4bb9ac35cda.png)](https://jacob.hoffman-andrews.com/rust/outdent-methods/std/string/struct.String.html#implementations)
2 parents ce73b19 + 542ab2d commit 7d1a382

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

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

+10-18
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,15 @@ h1.fqn > .in-band > a:hover {
152152
h2, h3, h4 {
153153
border-bottom: 1px solid;
154154
}
155-
h3.code-header, h4.code-header {
155+
h3.code-header {
156+
font-size: 1.1em;
157+
}
158+
h4.code-header {
156159
font-size: 1em;
160+
}
161+
h3.code-header, h4.code-header {
157162
font-weight: 600;
158-
border: none;
163+
border-bottom-style: none;
159164
padding: 0;
160165
margin: 0;
161166
}
@@ -174,12 +179,6 @@ h3.code-header, h4.code-header {
174179
margin-bottom: 10px;
175180
position: relative;
176181
}
177-
.impl, .method.trait-impl,
178-
.type.trait-impl,
179-
.associatedconstant.trait-impl,
180-
.associatedtype.trait-impl {
181-
padding-left: 15px;
182-
}
183182

184183
div.impl-items > div {
185184
padding-left: 0;
@@ -674,13 +673,6 @@ nav.sub {
674673
left: -19px;
675674
}
676675

677-
.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant,
678-
.impl-items > .associatedtype, .content .impl-items details > summary > .type,
679-
.impl-items details > summary > .associatedconstant,
680-
.impl-items details > summary > .associatedtype {
681-
margin-left: 20px;
682-
}
683-
684676
.content .impl-items .docblock, .content .impl-items .item-info {
685677
margin-bottom: .6em;
686678
}
@@ -751,7 +743,7 @@ a {
751743
.anchor {
752744
display: none;
753745
position: absolute;
754-
left: 0;
746+
left: -0.5em;
755747
background: none !important;
756748
}
757749
.anchor.field {
@@ -1584,14 +1576,14 @@ details.rustdoc-toggle > summary.hideme::before {
15841576

15851577
details.rustdoc-toggle > summary:not(.hideme)::before {
15861578
position: absolute;
1587-
left: -23px;
1579+
left: -24px;
15881580
top: 3px;
15891581
}
15901582

15911583
.impl-items > details.rustdoc-toggle > summary:not(.hideme)::before,
15921584
.undocumented > details.rustdoc-toggle > summary:not(.hideme)::before {
15931585
position: absolute;
1594-
left: -2px;
1586+
left: -24px;
15951587
}
15961588

15971589
/* When a "hideme" summary is open and the "Expand description" or "Show
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// The `impl Foo` heading underneath `Implementations` has a §
2+
// anchor to its left (used for linking to that heading). The anchor only shows
3+
// up when hovering the `impl Foo`. This test ensures there's no gap between the
4+
// anchor and the `impl Foo`. If there were a gap, this would cause an annoying
5+
// problem: you hover `impl Foo` to see the anchor, then when you move your
6+
// mouse to the left, the anchor disappears before you reach it.
7+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
8+
// We check that ".item-info" is bigger than its content.
9+
move-cursor-to: ".impl"
10+
assert-property: (".impl > a.anchor", {"offsetWidth": "9"})
11+
assert-css: (".impl > a.anchor", {"left": "-8px"})

0 commit comments

Comments
 (0)