Skip to content

Commit

Permalink
rustdoc: split toolbar when screen is small
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Nov 27, 2024
1 parent 8ca1590 commit d07ca1d
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 167 deletions.
1 change: 1 addition & 0 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) struct Layout {

pub(crate) struct Page<'a> {
pub(crate) title: &'a str,
pub(crate) short_title: &'a str,
pub(crate) css_class: &'a str,
pub(crate) root_path: &'a str,
pub(crate) static_root_path: Option<&'a str>,
Expand Down
14 changes: 14 additions & 0 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ impl<'tcx> Context<'tcx> {
if !is_module {
title.push_str(it.name.unwrap().as_str());
}
let short_title;
let short_title = if is_module {
let module_name = self.current.last().unwrap();
short_title = if it.is_crate() {
format!("Crate {module_name}")
} else {
format!("Module {module_name}")
};
&short_title[..]
} else {
it.name.as_ref().unwrap().as_str()
};
if !it.is_primitive() && !it.is_keyword() {
if !is_module {
title.push_str(" in ");
Expand Down Expand Up @@ -227,6 +239,7 @@ impl<'tcx> Context<'tcx> {
root_path: &self.root_path(),
static_root_path: clone_shared.static_root_path.as_deref(),
title: &title,
short_title,
description: &desc,
resource_suffix: &clone_shared.resource_suffix,
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
Expand Down Expand Up @@ -610,6 +623,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
let shared = Rc::clone(&self.shared);
let mut page = layout::Page {
title: "List of all items in this crate",
short_title: "All",
css_class: "mod sys",
root_path: "../",
static_root_path: shared.static_root_path.as_deref(),
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::html::format::{
print_constness_with_space, print_where_clause, visibility_print_with_space,
};
use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
use crate::html::render::sidebar::filters;
use crate::html::render::{document_full, document_item_info};
use crate::html::url_parts_builder::UrlPartsBuilder;

Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ impl CratesIndexPart {
fn blank(cx: &Context<'_>) -> SortedTemplate<<Self as CciPart>::FileFormat> {
let page = layout::Page {
title: "Index of crates",
short_title: "Crates",
css_class: "mod sys",
root_path: "./",
static_root_path: cx.shared.static_root_path.as_deref(),
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl SourceCollector<'_, '_> {
format!("Source of the Rust file `{}`.", filename.prefer_remapped_unconditionaly());
let page = layout::Page {
title: &title,
short_title: &src_fname.to_string_lossy(),
css_class: "src",
root_path: &root_path,
static_root_path: shared.static_root_path.as_deref(),
Expand Down
Loading

0 comments on commit d07ca1d

Please sign in to comment.