diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 66a8a19892886..90aa5904dafe8 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -36,6 +36,8 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\ --button-border-radius: 2px; --toolbar-button-border-radius: 6px; --code-block-border-radius: 6px; + --impl-items-indent: 0.3em; + --docblock-indent: 24px; } /* 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 .docblock h6 { font-size: 0.875rem; } .docblock { - margin-left: 24px; + margin-left: var(--docblock-indent); position: relative; } @@ -982,7 +984,11 @@ div.where { .item-info { display: block; - margin-left: 24px; + margin-left: var(--docblock-indent); +} +.impl-items > .item-info { + /* Margin of docblocks + margin of impl block items. */ + margin-left: calc(var(--docblock-indent) + var(--impl-items-indent)); } .item-info code { @@ -2166,6 +2172,15 @@ details.toggle > summary:not(.hideme)::before { left: -24px; } +/* We indent items of an impl block to have a visual marker that these items are part + of this impl block. */ +.impl-items > *:not(.item-info), +/* We also indent the first top doc comment the same to still keep an indent on the + doc block while aligning it with the impl block items. */ +.implementors-toggle > .docblock { + margin-left: var(--impl-items-indent); +} + details.big-toggle > summary:not(.hideme)::before { left: -34px; top: 9px; @@ -2255,6 +2270,10 @@ If you update this line, then you also need to update the line with the same war in src-script.js and main.js */ @media (max-width: 700px) { + :root { + --impl-items-indent: 0.7em; + } + /* When linking to an item with an `id` (for instance, by clicking a link in the sidebar, or visiting a URL with a fragment like `#method.new`, we don't want the item to be obscured 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 padding-top: 0; } - /* Position of the "[-]" element. */ - details.toggle:not(.top-doc) > summary, .impl-items > section { + details.implementors-toggle:not(.top-doc) > summary { margin-left: 10px; } - .impl-items > details.toggle > summary:not(.hideme)::before, - #main-content > details.toggle:not(.top-doc) > summary::before, - #main-content > div > details.toggle > summary::before { - left: -11px; + + .impl-items > details.toggle > summary:not(.hideme)::before { + left: -20px; } /* Align summary-nested and unnested item-info gizmos. */ + summary > .item-info { + margin-left: 10px; + } .impl-items > .item-info { - margin-left: 34px; + margin-left: calc(var(--impl-items-indent) + 10px); } .src nav.sub { @@ -2500,24 +2520,24 @@ in src-script.js and main.js } @media print { + :root { + --docblock-indent: 0; + } + nav.sidebar, nav.sub, .out-of-band, a.src, #copy-path, details.toggle[open] > summary::before, details.toggle > summary::before, details.toggle.top-doc > summary { display: none; } - .docblock { - margin-left: 0; - } - main { padding: 10px; } } @media (max-width: 464px) { - .docblock { - margin-left: 12px; + :root { + --docblock-indent: 12px; } .docblock code { diff --git a/tests/rustdoc-gui/deref-block.goml b/tests/rustdoc-gui/deref-block.goml index 24f612f8a6fd1..97930b61ef4a5 100644 --- a/tests/rustdoc-gui/deref-block.goml +++ b/tests/rustdoc-gui/deref-block.goml @@ -20,8 +20,12 @@ assert-css: (".big-toggle summary::before", { "left": "-11px", "top": "9px", }) -// It should have the same X position as the other toggles. -compare-elements-position: (".big-toggle summary::before", ".method-toggle summary::before", ["x"]) +// It should have a slightly different X position as the other toggles. +store-position: (".big-toggle summary::before", {"x": big_toggle}) +store-position: (".method-toggle summary::before", {"x": small_toggle}) +assert: |big_toggle| < |small_toggle| +// Margin is 0.5em so around 8 px. +assert: |small_toggle| - |big_toggle| < 10 // But still shouldn't have the same Y position. compare-elements-position-false: ( ".big-toggle summary::before", diff --git a/tests/rustdoc-gui/docblock-table-overflow.goml b/tests/rustdoc-gui/docblock-table-overflow.goml index 1ca919d1eabc3..abfa820ef2708 100644 --- a/tests/rustdoc-gui/docblock-table-overflow.goml +++ b/tests/rustdoc-gui/docblock-table-overflow.goml @@ -16,6 +16,6 @@ compare-elements-property: ( "#implementations-list > details .docblock > p", ["scrollWidth"], ) -assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "816"}) +assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "835"}) // However, since there is overflow in the