Skip to content

Commit

Permalink
rustdoc: redesign toolbar and disclosure widgets
Browse files Browse the repository at this point in the history
This adds labels to the icons and moves them away from the search box.

These changes are made together, because they work together, but are based on
several complaints:

* The [+/-] thing are a Reddit-ism. They don't look like buttons, but look
  like syntax
  <https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/More.20visual.20difference.20for.20the.20.2B.2F-.20.20Icons>,
  <rust-lang#59851>
  (some of these are laundry lists with more suggestions, but they all
  mention [+/-] looking wrong)

* The settings, help, and summary buttons are also too hard to recognize
  <https://lwn.net/Articles/987070/>,
  <rust-lang#90310>,
  <rust-lang#14475 (comment)>,
  <https://internals.rust-lang.org/t/improve-rustdoc-design/12758>
  ("Not all functionality is self-explanatory, for example the [+] button in
  the top right corner, the theme picker or the settings button.")

The toggle-all and toggle-individual buttons both need done at once, since we
want them to look like they go together. This changes them from both being
[+/-] to both being arrows.

Settings and Help are also migrated, so that the whole group can benefit from
being described using actual words.
  • Loading branch information
notriddle committed Aug 25, 2024
1 parent f167efa commit 26c585e
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 137 deletions.
28 changes: 21 additions & 7 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,22 @@ impl SourceCollector<'_, '_> {
},
);

let src_fname = p.file_name().expect("source has no filename").to_os_string();
let mut fname = src_fname.clone();

let root_path = PathBuf::from("../../").join(root_path.into_inner());
let mut root_path = root_path.to_string_lossy();
if let Some(c) = root_path.as_bytes().last()
&& *c != b'/'
{
root_path += "/";
}
let mut file_path = cur.clone().into_inner();
file_path.push(&fname);
fname.push(".html");
let mut cur = self.dst.join(cur.into_inner());
shared.ensure_dir(&cur)?;

let src_fname = p.file_name().expect("source has no filename").to_os_string();
let mut fname = src_fname.clone();
fname.push(".html");
cur.push(&fname);

let title = format!("{} - source", src_fname.to_string_lossy());
Expand Down Expand Up @@ -249,7 +252,7 @@ impl SourceCollector<'_, '_> {
cx,
&root_path,
highlight::DecorationInfo::default(),
SourceContext::Standalone,
SourceContext::Standalone { file_path },
)
},
&shared.style_files,
Expand Down Expand Up @@ -290,7 +293,7 @@ where
}

pub(crate) enum SourceContext {
Standalone,
Standalone { file_path: PathBuf },
Embedded { offset: usize, needs_expansion: bool },
}

Expand All @@ -312,10 +315,11 @@ pub(crate) fn print_src(
needs_expansion: bool,
lines: RangeInclusive<usize>,
code_html: Code,
file_path: Option<String>,
}
let lines = s.lines().count();
let (embedded, needs_expansion, lines) = match source_context {
SourceContext::Standalone => (false, false, 1..=lines),
SourceContext::Standalone { file_path: _ } => (false, false, 1..=lines),
SourceContext::Embedded { offset, needs_expansion } => {
(true, needs_expansion, (1 + offset)..=(lines + offset))
}
Expand All @@ -332,5 +336,15 @@ pub(crate) fn print_src(
);
Ok(())
});
Source { embedded, needs_expansion, lines, code_html: code }.render_into(&mut writer).unwrap();
Source {
embedded,
needs_expansion,
lines,
code_html: code,
file_path: if let SourceContext::Standalone { file_path } = source_context {
Some(file_path.display().to_string())
} else {
None
},
}.render_into(&mut writer).unwrap();
}
5 changes: 4 additions & 1 deletion src/librustdoc/html/static/css/noscript.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ nav.sub {
--copy-path-button-color: #999;
--copy-path-img-filter: invert(50%);
--copy-path-img-hover-filter: invert(35%);
--settings-menu-filter: invert(50%);
--settings-menu-hover-filter: invert(35%);
--codeblock-error-hover-color: rgb(255, 0, 0);
--codeblock-error-color: rgba(255, 0, 0, .5);
--codeblock-ignore-hover-color: rgb(255, 142, 0);
Expand All @@ -85,7 +87,6 @@ nav.sub {
--search-tab-button-not-selected-background: #e6e6e6;
--search-tab-button-selected-border-top-color: #0089ff;
--search-tab-button-selected-background: #fff;
--settings-menu-filter: none;
--stab-background-color: #fff5d6;
--stab-code-color: #000;
--code-highlight-kw-color: #8959a8;
Expand Down Expand Up @@ -188,6 +189,8 @@ nav.sub {
--search-tab-button-not-selected-background: #252525;
--search-tab-button-selected-border-top-color: #0089ff;
--search-tab-button-selected-background: #353535;
--settings-menu-filter: invert(50%);
--settings-menu-hover-filter: invert(65%);
--stab-background-color: #314559;
--stab-code-color: #e6e1cf;
--code-highlight-kw-color: #ab8ac1;
Expand Down
Loading

0 comments on commit 26c585e

Please sign in to comment.