Skip to content

Commit

Permalink
rustdoc: use code-header class to format enum variants
Browse files Browse the repository at this point in the history
The font size and weights should be exactly the same after this commit,
but the spacing is changed to be exactly the same as methods.
  • Loading branch information
notriddle committed Nov 17, 2022
1 parent 83356b7 commit 4525eb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
31 changes: 16 additions & 15 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use super::{
collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference,
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre,
render_impl, render_rightside, render_stability_since_raw, AssocItemLink, Context,
ImplRenderingParameters,
render_impl, render_rightside, render_stability_since_raw,
render_stability_since_raw_with_extra, AssocItemLink, Context, ImplRenderingParameters,
};
use crate::clean;
use crate::config::ModuleSorting;
Expand Down Expand Up @@ -1267,30 +1267,30 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
document_non_exhaustive_header(it)
);
document_non_exhaustive(w, it);
write!(w, "<div class=\"variants\">");
for variant in e.variants() {
let id = cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.unwrap()));
write!(
w,
"<h3 id=\"{id}\" class=\"variant small-section-header\">\
<a href=\"#{id}\" class=\"anchor field\"></a>\
<code>{name}",
"<section id=\"{id}\" class=\"variant\">\
<a href=\"#{id}\" class=\"anchor\"></a>",
id = id,
name = variant.name.unwrap()
);
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
w.write_str("(");
print_tuple_struct_fields(w, cx, s);
w.write_str(")");
}
w.write_str("</code>");
render_stability_since_raw(
render_stability_since_raw_with_extra(
w,
variant.stable_since(tcx),
variant.const_stability(tcx),
it.stable_since(tcx),
it.const_stable_since(tcx),
" rightside",
);
w.write_str("</h3>");
write!(w, "<h3 class=\"code-header\">{name}", name = variant.name.unwrap());
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
w.write_str("(");
print_tuple_struct_fields(w, cx, s);
w.write_str(")");
}
w.write_str("</h3></section>");

use crate::clean::Variant;

Expand Down Expand Up @@ -1324,7 +1324,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
write!(
w,
"<div class=\"sub-variant-field\">\
<span id=\"{id}\" class=\"variant small-section-header\">\
<span id=\"{id}\" class=\"small-section-header\">\
<a href=\"#{id}\" class=\"anchor field\"></a>\
<code>{f}:&nbsp;{t}</code>\
</span>",
Expand All @@ -1343,6 +1343,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::

document(w, cx, variant, Some(it), HeadingOffset::H4);
}
write!(w, "</div>");
}
let def_id = it.item_id.expect_def_id();
render_assoc_items(w, cx, it, def_id, AssocItemRender::All);
Expand Down
12 changes: 3 additions & 9 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -709,16 +709,14 @@ a {
}

.small-section-header {
display: flex;
justify-content: space-between;
position: relative;
}

.small-section-header:hover > .anchor {
display: initial;
}

.impl:hover > .anchor, .trait-impl:hover > .anchor {
.impl:hover > .anchor, .trait-impl:hover > .anchor, .variant:hover > .anchor {
display: inline-block;
position: absolute;
}
Expand Down Expand Up @@ -1235,12 +1233,6 @@ a.test-arrow:hover {
font-size: 1.25rem;
}

h3.variant {
font-weight: 600;
font-size: 1.125rem;
margin-bottom: 10px;
}

.sub-variant h4 {
font-size: 1rem;
font-weight: 400;
Expand Down Expand Up @@ -1909,6 +1901,7 @@ in storage.js
}
}

.variant,
.implementors-toggle > summary,
.impl,
#implementors-list > .docblock,
Expand All @@ -1920,6 +1913,7 @@ in storage.js
margin-bottom: 0.75em;
}

.variants > .docblock,
.impl-items > .rustdoc-toggle[open]:not(:last-child),
.methods > .rustdoc-toggle[open]:not(:last-child),
.implementors-toggle[open]:not(:last-child) {
Expand Down

0 comments on commit 4525eb1

Please sign in to comment.