Skip to content

Commit ec768e4

Browse files
committed
rustdoc: split toolbar when screen is small
1 parent 552e979 commit ec768e4

File tree

11 files changed

+261
-167
lines changed

11 files changed

+261
-167
lines changed

src/librustdoc/html/layout.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(crate) struct Layout {
2525

2626
pub(crate) struct Page<'a> {
2727
pub(crate) title: &'a str,
28+
pub(crate) short_title: &'a str,
2829
pub(crate) css_class: &'a str,
2930
pub(crate) root_path: &'a str,
3031
pub(crate) static_root_path: Option<&'a str>,

src/librustdoc/html/render/context.rs

+14
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ impl<'tcx> Context<'tcx> {
205205
if !is_module {
206206
title.push_str(it.name.unwrap().as_str());
207207
}
208+
let short_title;
209+
let short_title = if is_module {
210+
let module_name = self.current.last().unwrap();
211+
short_title = if it.is_crate() {
212+
format!("Crate {module_name}")
213+
} else {
214+
format!("Module {module_name}")
215+
};
216+
&short_title[..]
217+
} else {
218+
it.name.as_ref().unwrap().as_str()
219+
};
208220
if !it.is_primitive() && !it.is_keyword() {
209221
if !is_module {
210222
title.push_str(" in ");
@@ -242,6 +254,7 @@ impl<'tcx> Context<'tcx> {
242254
root_path: &self.root_path(),
243255
static_root_path: self.shared.static_root_path.as_deref(),
244256
title: &title,
257+
short_title,
245258
description: &desc,
246259
resource_suffix: &self.shared.resource_suffix,
247260
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
@@ -619,6 +632,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
619632
let shared = &self.shared;
620633
let mut page = layout::Page {
621634
title: "List of all items in this crate",
635+
short_title: "All",
622636
css_class: "mod sys",
623637
root_path: "../",
624638
static_root_path: shared.static_root_path.as_deref(),

src/librustdoc/html/render/print_item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use crate::html::format::{
3434
print_constness_with_space, print_where_clause, visibility_print_with_space,
3535
};
3636
use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
37+
use crate::html::render::sidebar::filters;
3738
use crate::html::render::{document_full, document_item_info};
3839
use crate::html::url_parts_builder::UrlPartsBuilder;
3940

src/librustdoc/html/render/write_shared.rs

+1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl CratesIndexPart {
425425
fn blank(cx: &Context<'_>) -> SortedTemplate<<Self as CciPart>::FileFormat> {
426426
let page = layout::Page {
427427
title: "Index of crates",
428+
short_title: "Crates",
428429
css_class: "mod sys",
429430
root_path: "./",
430431
static_root_path: cx.shared.static_root_path.as_deref(),

src/librustdoc/html/sources.rs

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ impl SourceCollector<'_, '_> {
231231
);
232232
let page = layout::Page {
233233
title: &title,
234+
short_title: &src_fname.to_string_lossy(),
234235
css_class: "src",
235236
root_path: &root_path,
236237
static_root_path: shared.static_root_path.as_deref(),

0 commit comments

Comments
 (0)