Skip to content

rustdoc: design change to separate methods better and improve scanning #86283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ fn render_assoc_item(
w.reserve(header_len + "<a href=\"\" class=\"fnname\">{".len() + "</a>".len());
write!(
w,
"{}{}{}{}{}{}{}fn <a href=\"{href}\" class=\"fnname\">{name}</a>\
"<span class=\"fnqualifiers\">{}{}{}{}{}{}{}fn</span> <a href=\"{href}\" class=\"fnname\">{name}</a>\
{generics}{decl}{notable_traits}{where_clause}",
indent_str,
vis,
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ function hideThemeButtonState() {
while (elem) {
if (elem.tagName === "DETAILS") {
elem.open = true;
addClass(elem, "used");
}
elem = elem.parentNode;
}
Expand Down Expand Up @@ -862,6 +863,13 @@ function hideThemeButtonState() {
displayHelp(true, ev);
});

onEachLazy(document.getElementsByTagName("summary"), function(el) {
el.addEventListener("click", function() {
addClass(el, "used");
addClass(el.parentElement, "used");
});
});

onEachLazy(document.getElementsByTagName("a"), function(el) {
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
Expand Down
60 changes: 32 additions & 28 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ h2, h3, h4 {
margin-bottom: 10px;
position: relative;
}
.impl, .method.trait-impl,
.type.trait-impl,
.associatedconstant.trait-impl,
.associatedtype.trait-impl {
padding-left: 15px;

.fnqualifiers {
font-weight: 400;
font-size: 0.8em; /* match with "where" clauses */
}

div.impl-items > div {
Expand Down Expand Up @@ -553,6 +552,7 @@ nav.sub {
.content .where.fmt-newline {
display: block;
font-size: 0.8em;
font-weight: 400;
}

.content .methods > div:not(.notable-traits):not(.method) {
Expand Down Expand Up @@ -580,29 +580,13 @@ nav.sub {

.content .item-info {
position: relative;
margin-left: 33px;
margin-top: -13px;
margin-left: 24px; /* same as .docblock */
}

.sub-variant > div > .item-info {
margin-top: initial;
}

.content .item-info::before {
content: '⬑';
font-size: 25px;
position: absolute;
top: -6px;
left: -19px;
}

.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant,
.impl-items > .associatedtype, .content .impl-items details > summary > .type,
.impl-items details > summary > .associatedconstant,
.impl-items details > summary > .associatedtype {
margin-left: 20px;
}

.content .impl-items .docblock, .content .impl-items .item-info {
margin-bottom: .6em;
}
Expand Down Expand Up @@ -927,7 +911,6 @@ body.blur > :not(#help) {
display: flex;
flex-basis: 100%;
font-size: 16px;
margin-bottom: 12px;
/* Push the src link out to the right edge consistently */
justify-content: space-between;
}
Expand Down Expand Up @@ -1458,16 +1441,26 @@ details.rustdoc-toggle > summary.hideme::before {
position: relative;
}

details.rustdoc-toggle[open].used > summary:not(.hideme)::before,
details.rustdoc-toggle > summary:not(.hideme)::before {
position: absolute;
left: -23px;
top: 3px;
}

.impl-items > details.rustdoc-toggle > summary:not(.hideme)::before,
.undocumented > details.rustdoc-toggle > summary:not(.hideme)::before {
position: absolute;
left: -2px;
details.rustdoc-toggle[open] {
margin-left: 0px;
}

.impl-items .method {
padding: 2px 6px;
margin-bottom: 6px;
}

.fnname {
border-top-width: 2px;
border-top-style: solid;
padding-top: 3px;
}

/* When a "hideme" summary is open and the "Expand description" or "Show
Expand All @@ -1481,17 +1474,28 @@ details.rustdoc-toggle[open] > summary.hideme {

details.rustdoc-toggle, details.undocumented {
position: relative;
margin: 12px 0px;
}

details.rustdoc-toggle[open] > summary.hideme > span {
display: none;
}

details.rustdoc-toggle[open] > summary::before {
/* If a toggle has been used to open a section, we should make sure */
/* there's a [-] so it can be closed again. But if a toggle is open */
/* and has never been used, don't show it. This minimizes clutter on */
/* the page while still supporting the "auto hide <X>" settings and */
/* the expand/collapse all functionality. */
details.rustdoc-toggle[open].used > summary::before {
content: "[−]";
display: inline;
}

details.rustdoc-toggle[open] > summary::before {
content: "";
display: inline;
}

details.undocumented > summary::before {
content: "[+] Show hidden undocumented items";
cursor: pointer;
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/html/static/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ pre, .rustdoc.source .example-wrap {
color: #c5c5c5;
}

.content .item-info::before { color: #ccc; }

.content span.foreigntype, .content a.foreigntype { color: #ef57ff; }
.content span.union, .content a.union { color: #98a01c; }
.content span.constant, .content a.constant,
Expand Down
14 changes: 10 additions & 4 deletions src/librustdoc/html/static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pre, .rustdoc.source .example-wrap {
background-color: #2A2A2A;
}

details.method-toggle .method {
background-color: #2A2A2A;
border-top: 2px solid #bb7410;
}

.sidebar {
background-color: #505050;
}
Expand Down Expand Up @@ -138,8 +143,6 @@ a.result-static:focus { background-color: #0063cc; }
a.result-primitive:focus { background-color: #00708a; }
a.result-keyword:focus { background-color: #884719; }

.content .item-info::before { color: #ccc; }

.content span.enum, .content a.enum, .block a.current.enum { color: #82b089; }
.content span.struct, .content a.struct, .block a.current.struct { color: #2dbfb8; }
.content span.type, .content a.type, .block a.current.type { color: #ff7f00; }
Expand All @@ -158,7 +161,10 @@ a.result-keyword:focus { background-color: #884719; }
.content span.fn, .content a.fn, .block a.current.fn,
.content span.method, .content a.method, .block a.current.method,
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
.content .fnname{ color: #2BAB63; }
.content .fnname{
color: #2BAB63;
border-color: #2BAB63;
}
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }

pre.rust .comment { color: #8d8d8b; }
Expand Down Expand Up @@ -282,7 +288,7 @@ a.test-arrow:hover{
color: #999;
}

:target > code, :target > .in-band {
:target, :target > .in-band {
background-color: #494a3d;
border-right: 3px solid #bb7410;
}
Expand Down
14 changes: 10 additions & 4 deletions src/librustdoc/html/static/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pre, .rustdoc.source .example-wrap {
background-color: #F5F5F5;
}

details.method-toggle .method {
background-color: #F5F5F5;
border-top: 2px solid #ffb44c;
}

.sidebar {
background-color: #F1F1F1;
}
Expand Down Expand Up @@ -136,8 +141,6 @@ a.result-static:focus { background-color: #c3e0ff; }
a.result-primitive:focus { background-color: #9aecff; }
a.result-keyword:focus { background-color: #f99650; }

.content .item-info::before { color: #ccc; }

.content span.enum, .content a.enum, .block a.current.enum { color: #508157; }
.content span.struct, .content a.struct, .block a.current.struct { color: #ad448e; }
.content span.type, .content a.type, .block a.current.type { color: #ba5d00; }
Expand All @@ -156,7 +159,10 @@ a.result-keyword:focus { background-color: #f99650; }
.content span.fn, .content a.fn, .block a.current.fn,
.content span.method, .content a.method, .block a.current.method,
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
.content .fnname { color: #9a6e31; }
.content .fnname {
color: #9a6e31;
border-color: #9a6e31;
}
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }

pre.rust .comment { color: #8E908C; }
Expand Down Expand Up @@ -275,7 +281,7 @@ a.test-arrow:hover{
color: #999;
}

:target > code, :target > .in-band {
:target, :target > .in-band {
background: #FDFFD3;
border-right: 3px solid #ffb44c;
}
Expand Down