Skip to content

Commit 579c823

Browse files
committed
rustdoc: redesign toolbar and disclosure widgets
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>, <#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/>, <#90310>, <#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. Additionally, the Help button is only shown on SERPs, not all the time. This is done for two major reasons: * Most of what's in there is search-related. The things that aren't are keyboard commands, and the search box tells you about that anyway. Pressing <kbd>?</kbd> will temporarily show the button and its popover. * I'm trading it off by showing the help button, even on mobile. It's useful since you can use the search engine suggestions there. * The three buttons were causing line wrapping on too many desktop layouts.
1 parent f167efa commit 579c823

33 files changed

+392
-254
lines changed

src/librustdoc/html/sources.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ pub(crate) fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), E
2525

2626
let dst = cx.dst.join("src").join(krate.name(cx.tcx()).as_str());
2727
cx.shared.ensure_dir(&dst)?;
28+
let crate_name = krate.name(cx.tcx());
29+
let crate_name = crate_name.as_str();
2830

29-
let mut collector = SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default() };
31+
let mut collector =
32+
SourceCollector { dst, cx, emitted_local_sources: FxHashSet::default(), crate_name };
3033
collector.visit_crate(krate);
3134
Ok(())
3235
}
@@ -114,6 +117,8 @@ struct SourceCollector<'a, 'tcx> {
114117
/// Root destination to place all HTML output into
115118
dst: PathBuf,
116119
emitted_local_sources: FxHashSet<PathBuf>,
120+
121+
crate_name: &'a str,
117122
}
118123

119124
impl DocVisitor for SourceCollector<'_, '_> {
@@ -209,19 +214,22 @@ impl SourceCollector<'_, '_> {
209214
},
210215
);
211216

217+
let src_fname = p.file_name().expect("source has no filename").to_os_string();
218+
let mut fname = src_fname.clone();
219+
212220
let root_path = PathBuf::from("../../").join(root_path.into_inner());
213221
let mut root_path = root_path.to_string_lossy();
214222
if let Some(c) = root_path.as_bytes().last()
215223
&& *c != b'/'
216224
{
217225
root_path += "/";
218226
}
227+
let mut file_path = Path::new(&self.crate_name).join(&*cur.borrow());
228+
file_path.push(&fname);
229+
fname.push(".html");
219230
let mut cur = self.dst.join(cur.into_inner());
220231
shared.ensure_dir(&cur)?;
221232

222-
let src_fname = p.file_name().expect("source has no filename").to_os_string();
223-
let mut fname = src_fname.clone();
224-
fname.push(".html");
225233
cur.push(&fname);
226234

227235
let title = format!("{} - source", src_fname.to_string_lossy());
@@ -249,7 +257,7 @@ impl SourceCollector<'_, '_> {
249257
cx,
250258
&root_path,
251259
highlight::DecorationInfo::default(),
252-
SourceContext::Standalone,
260+
SourceContext::Standalone { file_path },
253261
)
254262
},
255263
&shared.style_files,
@@ -290,7 +298,7 @@ where
290298
}
291299

292300
pub(crate) enum SourceContext {
293-
Standalone,
301+
Standalone { file_path: PathBuf },
294302
Embedded { offset: usize, needs_expansion: bool },
295303
}
296304

@@ -312,10 +320,11 @@ pub(crate) fn print_src(
312320
needs_expansion: bool,
313321
lines: RangeInclusive<usize>,
314322
code_html: Code,
323+
file_path: Option<(String, String)>,
315324
}
316325
let lines = s.lines().count();
317326
let (embedded, needs_expansion, lines) = match source_context {
318-
SourceContext::Standalone => (false, false, 1..=lines),
327+
SourceContext::Standalone { file_path: _ } => (false, false, 1..=lines),
319328
SourceContext::Embedded { offset, needs_expansion } => {
320329
(true, needs_expansion, (1 + offset)..=(lines + offset))
321330
}
@@ -332,5 +341,20 @@ pub(crate) fn print_src(
332341
);
333342
Ok(())
334343
});
335-
Source { embedded, needs_expansion, lines, code_html: code }.render_into(&mut writer).unwrap();
344+
Source {
345+
embedded,
346+
needs_expansion,
347+
lines,
348+
code_html: code,
349+
file_path: if let SourceContext::Standalone { file_path } = source_context
350+
&& let Some(file_name) = file_path.file_name()
351+
&& let Some(file_path) = file_path.parent()
352+
{
353+
Some((file_path.display().to_string(), file_name.display().to_string()))
354+
} else {
355+
None
356+
},
357+
}
358+
.render_into(&mut writer)
359+
.unwrap();
336360
}

src/librustdoc/html/static/css/noscript.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ nav.sub {
5959
--copy-path-button-color: #999;
6060
--copy-path-img-filter: invert(50%);
6161
--copy-path-img-hover-filter: invert(35%);
62+
--settings-menu-filter: invert(50%);
63+
--settings-menu-hover-filter: invert(35%);
6264
--codeblock-error-hover-color: rgb(255, 0, 0);
6365
--codeblock-error-color: rgba(255, 0, 0, .5);
6466
--codeblock-ignore-hover-color: rgb(255, 142, 0);
@@ -85,7 +87,6 @@ nav.sub {
8587
--search-tab-button-not-selected-background: #e6e6e6;
8688
--search-tab-button-selected-border-top-color: #0089ff;
8789
--search-tab-button-selected-background: #fff;
88-
--settings-menu-filter: none;
8990
--stab-background-color: #fff5d6;
9091
--stab-code-color: #000;
9192
--code-highlight-kw-color: #8959a8;
@@ -188,6 +189,8 @@ nav.sub {
188189
--search-tab-button-not-selected-background: #252525;
189190
--search-tab-button-selected-border-top-color: #0089ff;
190191
--search-tab-button-selected-background: #353535;
192+
--settings-menu-filter: invert(50%);
193+
--settings-menu-hover-filter: invert(65%);
191194
--stab-background-color: #314559;
192195
--stab-code-color: #e6e1cf;
193196
--code-highlight-kw-color: #ab8ac1;

0 commit comments

Comments
 (0)