diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 94a902a2d0522..4411b7771eda7 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -175,9 +175,45 @@ pub(super) fn write_shared( cx.write_shared(SharedResource::InvocationSpecific { basename: p }, content, &options.emit) }; + fn add_background_image_to_css( + cx: &Context<'_>, + css: &mut String, + rule: &str, + file: &'static str, + ) { + css.push_str(&format!( + "{} {{ background-image: url({}); }}", + rule, + SharedResource::ToolchainSpecific { basename: file } + .path(cx) + .file_name() + .unwrap() + .to_str() + .unwrap() + )) + } + + // Add all the static files. These may already exist, but we just + // overwrite them anyway to make sure that they're fresh and up-to-date. + let mut rustdoc_css = static_files::RUSTDOC_CSS.to_owned(); + add_background_image_to_css( + cx, + &mut rustdoc_css, + "details.undocumented[open] > summary::before, \ + details.rustdoc-toggle[open] > summary::before, \ + details.rustdoc-toggle[open] > summary.hideme::before", + "toggle-minus.svg", + ); + add_background_image_to_css( + cx, + &mut rustdoc_css, + "details.undocumented > summary::before, details.rustdoc-toggle > summary::before", + "toggle-plus.svg", + ); + write_minify("rustdoc.css", &rustdoc_css)?; + // Add all the static files. These may already exist, but we just // overwrite them anyway to make sure that they're fresh and up-to-date. - write_minify("rustdoc.css", static_files::RUSTDOC_CSS)?; write_minify("settings.css", static_files::SETTINGS_CSS)?; write_minify("noscript.css", static_files::NOSCRIPT_CSS)?; @@ -217,6 +253,8 @@ pub(super) fn write_shared( write_toolchain("wheel.svg", static_files::WHEEL_SVG)?; write_toolchain("clipboard.svg", static_files::CLIPBOARD_SVG)?; write_toolchain("down-arrow.svg", static_files::DOWN_ARROW_SVG)?; + write_toolchain("toggle-minus.svg", static_files::TOGGLE_MINUS_PNG)?; + write_toolchain("toggle-plus.svg", static_files::TOGGLE_PLUS_PNG)?; let mut themes: Vec<&String> = themes.iter().collect(); themes.sort(); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 91243a4086ced..4e33eab565006 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1508,11 +1508,35 @@ details.rustdoc-toggle > summary.hideme > span { } details.rustdoc-toggle > summary::before { - content: "[+]"; - font-weight: 300; - font-size: 0.8em; - letter-spacing: 1px; + content: ""; cursor: pointer; + width: 17px; + height: max(17px, 1.1em); + background-repeat: no-repeat; + background-position: top left; + display: inline-block; + vertical-align: middle; + opacity: .5; +} + +/* Screen readers see the text version at the end the line. + Visual readers see the icon at the start of the line, but small and transparent. */ +details.rustdoc-toggle > summary::after { + content: "Expand"; + overflow: hidden; + width: 0; + height: 0; + position: absolute; +} + +details.rustdoc-toggle > summary.hideme::after { + /* "hideme" toggles already have a description when they're contracted */ + content: ""; +} + +details.rustdoc-toggle > summary:focus::before, +details.rustdoc-toggle > summary:hover::before { + opacity: 1; } details.rustdoc-toggle.top-doc > summary, @@ -1560,20 +1584,44 @@ details.rustdoc-toggle[open] > summary.hideme > span { display: none; } -details.rustdoc-toggle[open] > summary::before { - content: "[−]"; - display: inline; +details.rustdoc-toggle[open] > summary::before, +details.rustdoc-toggle[open] > summary.hideme::before { + width: 17px; + height: max(17px, 1.1em); + background-repeat: no-repeat; + background-position: top left; + display: inline-block; + content: ""; +} + +details.rustdoc-toggle[open] > summary::after, +details.rustdoc-toggle[open] > summary.hideme::after { + content: "Collapse"; } details.undocumented > summary::before { - content: "[+] Show hidden undocumented items"; + padding-left: 17px; + height: max(17px, 1.1em); + background-repeat: no-repeat; + background-position: top left; + content: "Show hidden undocumented items"; cursor: pointer; font-size: 16px; font-weight: 300; + opacity: .5; +} + +details.undocumented > summary:focus::before, +details.undocumented > summary:hover::before { + opacity: 1; } details.undocumented[open] > summary::before { - content: "[−] Hide undocumented items"; + padding-left: 17px; + height: max(17px, 1.1em); + background-repeat: no-repeat + background-position: top left; + content: "Hide undocumented items"; } /* Media Queries */ diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index df386fb66a33f..849924ea5501e 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -229,6 +229,11 @@ details.undocumented > summary::before { color: #999; } +details.rustdoc-toggle > summary::before, +details.undocumented > summary::before { + filter: invert(100%); +} + #crate-search { color: #c5c5c5; background-color: #141920; diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index c8a5dbdc66aaf..c26122e4bffb5 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -194,6 +194,11 @@ details.undocumented > summary::before { color: #999; } +details.rustdoc-toggle > summary::before, +details.undocumented > summary::before { + filter: invert(100%); +} + #crate-search { color: #111; background-color: #f0f0f0; diff --git a/src/librustdoc/html/static/images/toggle-minus.svg b/src/librustdoc/html/static/images/toggle-minus.svg new file mode 100644 index 0000000000000..73154788a0e8e --- /dev/null +++ b/src/librustdoc/html/static/images/toggle-minus.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/librustdoc/html/static/images/toggle-plus.svg b/src/librustdoc/html/static/images/toggle-plus.svg new file mode 100644 index 0000000000000..08b17033e164b --- /dev/null +++ b/src/librustdoc/html/static/images/toggle-plus.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 2ec7e66234ddd..6f3d08ea65569 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -47,6 +47,12 @@ crate static CLIPBOARD_SVG: &[u8] = include_bytes!("static/images/clipboard.svg" /// The file contents of `down-arrow.svg`, the icon used for the crate choice combobox. crate static DOWN_ARROW_SVG: &[u8] = include_bytes!("static/images/down-arrow.svg"); +/// The file contents of `toggle-minus.svg`, the icon used for opened toggles. +crate static TOGGLE_MINUS_PNG: &[u8] = include_bytes!("static/images/toggle-minus.svg"); + +/// The file contents of `toggle-plus.svg`, the icon used for closed toggles. +crate static TOGGLE_PLUS_PNG: &[u8] = include_bytes!("static/images/toggle-plus.svg"); + /// The contents of `COPYRIGHT.txt`, the license listing for files distributed with documentation /// output. crate static COPYRIGHT: &[u8] = include_bytes!("static/COPYRIGHT.txt");