Skip to content

Commit f0d88b8

Browse files
authored
Unrolled build for rust-lang#131718
Rollup merge of rust-lang#131718 - GuillaumeGomez:impl-items-indent, r=rustdoc [rustdoc] Change impl items indent Fixes rust-lang#131704. | before | after | |-|-| | ![image](https://github.com/user-attachments/assets/67679827-6aef-4bdb-93dd-e1a4784566b3) | ![image](https://github.com/user-attachments/assets/8a0e9fbc-794a-4b98-abc6-bbbe178736b1) | Can be tested [here](https://rustdoc.crud.net/imperio/impl-items-indent/bar/struct.Bar.html). r? `@notriddle`
2 parents 0c4f3a4 + bf6fcc9 commit f0d88b8

8 files changed

+53
-28
lines changed

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

+35-15
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
3636
--button-border-radius: 2px;
3737
--toolbar-button-border-radius: 6px;
3838
--code-block-border-radius: 6px;
39+
--impl-items-indent: 0.3em;
40+
--docblock-indent: 24px;
3941
}
4042

4143
/* See FiraSans-LICENSE.txt for the Fira Sans license. */
@@ -909,7 +911,7 @@ both the code example and the line numbers, so we need to remove the radius in t
909911
.docblock h6 { font-size: 0.875rem; }
910912

911913
.docblock {
912-
margin-left: 24px;
914+
margin-left: var(--docblock-indent);
913915
position: relative;
914916
}
915917

@@ -982,7 +984,11 @@ div.where {
982984

983985
.item-info {
984986
display: block;
985-
margin-left: 24px;
987+
margin-left: var(--docblock-indent);
988+
}
989+
.impl-items > .item-info {
990+
/* Margin of docblocks + margin of impl block items. */
991+
margin-left: calc(var(--docblock-indent) + var(--impl-items-indent));
986992
}
987993

988994
.item-info code {
@@ -2166,6 +2172,15 @@ details.toggle > summary:not(.hideme)::before {
21662172
left: -24px;
21672173
}
21682174

2175+
/* We indent items of an impl block to have a visual marker that these items are part
2176+
of this impl block. */
2177+
.impl-items > *:not(.item-info),
2178+
/* We also indent the first top doc comment the same to still keep an indent on the
2179+
doc block while aligning it with the impl block items. */
2180+
.implementors-toggle > .docblock {
2181+
margin-left: var(--impl-items-indent);
2182+
}
2183+
21692184
details.big-toggle > summary:not(.hideme)::before {
21702185
left: -34px;
21712186
top: 9px;
@@ -2255,6 +2270,10 @@ If you update this line, then you also need to update the line with the same war
22552270
in src-script.js and main.js
22562271
*/
22572272
@media (max-width: 700px) {
2273+
:root {
2274+
--impl-items-indent: 0.7em;
2275+
}
2276+
22582277
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
22592278
or visiting a URL with a fragment like `#method.new`, we don't want the item to be obscured
22602279
by the topbar. Anything with an `id` gets scroll-margin-top equal to .mobile-topbar's size.
@@ -2454,19 +2473,20 @@ in src-script.js and main.js
24542473
padding-top: 0;
24552474
}
24562475

2457-
/* Position of the "[-]" element. */
2458-
details.toggle:not(.top-doc) > summary, .impl-items > section {
2476+
details.implementors-toggle:not(.top-doc) > summary {
24592477
margin-left: 10px;
24602478
}
2461-
.impl-items > details.toggle > summary:not(.hideme)::before,
2462-
#main-content > details.toggle:not(.top-doc) > summary::before,
2463-
#main-content > div > details.toggle > summary::before {
2464-
left: -11px;
2479+
2480+
.impl-items > details.toggle > summary:not(.hideme)::before {
2481+
left: -20px;
24652482
}
24662483

24672484
/* Align summary-nested and unnested item-info gizmos. */
2485+
summary > .item-info {
2486+
margin-left: 10px;
2487+
}
24682488
.impl-items > .item-info {
2469-
margin-left: 34px;
2489+
margin-left: calc(var(--impl-items-indent) + 10px);
24702490
}
24712491

24722492
.src nav.sub {
@@ -2500,24 +2520,24 @@ in src-script.js and main.js
25002520
}
25012521

25022522
@media print {
2523+
:root {
2524+
--docblock-indent: 0;
2525+
}
2526+
25032527
nav.sidebar, nav.sub, .out-of-band, a.src, #copy-path,
25042528
details.toggle[open] > summary::before, details.toggle > summary::before,
25052529
details.toggle.top-doc > summary {
25062530
display: none;
25072531
}
25082532

2509-
.docblock {
2510-
margin-left: 0;
2511-
}
2512-
25132533
main {
25142534
padding: 10px;
25152535
}
25162536
}
25172537

25182538
@media (max-width: 464px) {
2519-
.docblock {
2520-
margin-left: 12px;
2539+
:root {
2540+
--docblock-indent: 12px;
25212541
}
25222542

25232543
.docblock code {

tests/rustdoc-gui/deref-block.goml

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ assert-css: (".big-toggle summary::before", {
2020
"left": "-11px",
2121
"top": "9px",
2222
})
23-
// It should have the same X position as the other toggles.
24-
compare-elements-position: (".big-toggle summary::before", ".method-toggle summary::before", ["x"])
23+
// It should have a slightly different X position as the other toggles.
24+
store-position: (".big-toggle summary::before", {"x": big_toggle})
25+
store-position: (".method-toggle summary::before", {"x": small_toggle})
26+
assert: |big_toggle| < |small_toggle|
27+
// Margin is 0.5em so around 8 px.
28+
assert: |small_toggle| - |big_toggle| < 10
2529
// But still shouldn't have the same Y position.
2630
compare-elements-position-false: (
2731
".big-toggle summary::before",

tests/rustdoc-gui/docblock-table-overflow.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ compare-elements-property: (
1616
"#implementations-list > details .docblock > p",
1717
["scrollWidth"],
1818
)
19-
assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "816"})
19+
assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "835"})
2020
// However, since there is overflow in the <table>, its scroll width is bigger.
2121
assert-property: ("#implementations-list > details .docblock table", {"scrollWidth": "1572"})

tests/rustdoc-gui/item-info-alignment.goml

+2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ go-to: "file://" + |DOC_PATH| + "/lib2/struct.ItemInfoAlignmentTest.html"
44

55
// First, we try it in "desktop" mode.
66
set-window-size: (1200, 870)
7+
wait-for-size: ("body", {"width": 1200})
78
compare-elements-position: (".impl-items > .item-info", "summary > .item-info", ["x"])
89
// Next, we try it in "mobile" mode (max-width: 700px).
910
set-window-size: (650, 650)
11+
wait-for-size: ("body", {"width": 650})
1012
compare-elements-position: (".impl-items > .item-info", "summary > .item-info", ["x"])

tests/rustdoc-gui/item-info.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ store-position: (
1919
"//*[@class='stab portability']//code[normalize-space()='Win32_System_Diagnostics']",
2020
{"x": second_line_x, "y": second_line_y},
2121
)
22-
assert: |first_line_x| != |second_line_x| && |first_line_x| == 516 && |second_line_x| == 272
22+
assert: |first_line_x| != |second_line_x| && |first_line_x| == 521 && |second_line_x| == 277
2323
assert: |first_line_y| != |second_line_y| && |first_line_y| == 718 && |second_line_y| == 741
2424

2525
// Now we ensure that they're not rendered on the same line.

tests/rustdoc-gui/methods-left-margin.goml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This test is to ensure that methods are correctly aligned on the left side.
22

33
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
4-
54
// First we ensure that we have methods with and without documentation.
65
assert: ".impl-items > details.method-toggle > summary > section.method"
76
assert: ".impl-items > section.method"

tests/rustdoc-gui/notable-trait.goml

+7-7
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ define-function: (
6262
// We start with a wide screen.
6363
set-window-size: (1100, 600)
6464
call-function: ("check-notable-tooltip-position-complete", {
65-
"x": 677,
66-
"i_x": 955,
67-
"popover_x": 463,
65+
"x": 682,
66+
"i_x": 960,
67+
"popover_x": 468,
6868
})
6969

7070
// Now only the `i` should be on the next line.
@@ -78,16 +78,16 @@ compare-elements-position-false: (
7878
// Now both the `i` and the struct name should be on the next line.
7979
set-window-size: (980, 600)
8080
call-function: ("check-notable-tooltip-position", {
81-
"x": 245,
82-
"i_x": 523,
81+
"x": 250,
82+
"i_x": 528,
8383
})
8484

8585
// Checking on mobile now.
8686
set-window-size: (650, 600)
8787
wait-for-size: ("body", {"width": 650})
8888
call-function: ("check-notable-tooltip-position-complete", {
89-
"x": 25,
90-
"i_x": 303,
89+
"x": 26,
90+
"i_x": 305,
9191
"popover_x": 0,
9292
})
9393

tests/rustdoc-gui/toggle-docs-mobile.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ assert-position: ("#implementations-list > details > summary::before", {"x": 4})
1818
// Assert the position of the toggle on a method.
1919
assert-position: (
2020
"#trait-implementations-list .impl-items .method-toggle > summary::before",
21-
{"x": 4},
21+
{"x": 6},
2222
)
2323

2424
// Now we do the same but with a little bigger width

0 commit comments

Comments
 (0)