Skip to content

Commit d07ca1d

Browse files
committed
rustdoc: split toolbar when screen is small
1 parent 8ca1590 commit d07ca1d

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
@@ -191,6 +191,18 @@ impl<'tcx> Context<'tcx> {
191191
if !is_module {
192192
title.push_str(it.name.unwrap().as_str());
193193
}
194+
let short_title;
195+
let short_title = if is_module {
196+
let module_name = self.current.last().unwrap();
197+
short_title = if it.is_crate() {
198+
format!("Crate {module_name}")
199+
} else {
200+
format!("Module {module_name}")
201+
};
202+
&short_title[..]
203+
} else {
204+
it.name.as_ref().unwrap().as_str()
205+
};
194206
if !it.is_primitive() && !it.is_keyword() {
195207
if !is_module {
196208
title.push_str(" in ");
@@ -227,6 +239,7 @@ impl<'tcx> Context<'tcx> {
227239
root_path: &self.root_path(),
228240
static_root_path: clone_shared.static_root_path.as_deref(),
229241
title: &title,
242+
short_title,
230243
description: &desc,
231244
resource_suffix: &clone_shared.resource_suffix,
232245
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
@@ -610,6 +623,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
610623
let shared = Rc::clone(&self.shared);
611624
let mut page = layout::Page {
612625
title: "List of all items in this crate",
626+
short_title: "All",
613627
css_class: "mod sys",
614628
root_path: "../",
615629
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
@@ -36,6 +36,7 @@ use crate::html::format::{
3636
print_constness_with_space, print_where_clause, visibility_print_with_space,
3737
};
3838
use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
39+
use crate::html::render::sidebar::filters;
3940
use crate::html::render::{document_full, document_item_info};
4041
use crate::html::url_parts_builder::UrlPartsBuilder;
4142

src/librustdoc/html/render/write_shared.rs

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

src/librustdoc/html/sources.rs

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ impl SourceCollector<'_, '_> {
238238
format!("Source of the Rust file `{}`.", filename.prefer_remapped_unconditionaly());
239239
let page = layout::Page {
240240
title: &title,
241+
short_title: &src_fname.to_string_lossy(),
241242
css_class: "src",
242243
root_path: &root_path,
243244
static_root_path: shared.static_root_path.as_deref(),

0 commit comments

Comments
 (0)