Skip to content

Commit 6020c79

Browse files
committed
Implement Desktop and Mobile version with gridlayout
* implement sans-serif rust-lang#85621
1 parent 456a032 commit 6020c79

File tree

7 files changed

+61
-31
lines changed

7 files changed

+61
-31
lines changed

src/librustdoc/html/render/print_item.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
263263
curty = myty;
264264
} else if myty != curty {
265265
if curty.is_some() {
266-
w.write_str("</table>");
266+
w.write_str("</item-table>");
267267
}
268268
curty = myty;
269269
let (short, name) = item_ty_to_strs(myty.unwrap());
270270
write!(
271271
w,
272272
"<h2 id=\"{id}\" class=\"section-header\">\
273-
<a href=\"#{id}\">{name}</a></h2>\n<table>",
273+
<a href=\"#{id}\">{name}</a></h2>\n<item-table>",
274274
id = cx.derive_id(short.to_owned()),
275275
name = name
276276
);
@@ -283,14 +283,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
283283
match *src {
284284
Some(ref src) => write!(
285285
w,
286-
"<tr><td><code>{}extern crate {} as {};",
286+
"<item-left><code>{}extern crate {} as {};",
287287
myitem.visibility.print_with_space(myitem.def_id, cx),
288288
anchor(myitem.def_id.expect_real(), &*src.as_str(), cx),
289289
myitem.name.as_ref().unwrap(),
290290
),
291291
None => write!(
292292
w,
293-
"<tr><td><code>{}extern crate {};",
293+
"<item-left><code>{}extern crate {};",
294294
myitem.visibility.print_with_space(myitem.def_id, cx),
295295
anchor(
296296
myitem.def_id.expect_real(),
@@ -299,7 +299,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
299299
),
300300
),
301301
}
302-
w.write_str("</code></td></tr>");
302+
w.write_str("</code></item-left>\n");
303303
}
304304

305305
clean::ImportItem(ref import) => {
@@ -326,10 +326,10 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
326326

327327
write!(
328328
w,
329-
"<tr class=\"{stab}{add}import-item\">\
330-
<td><code>{vis}{imp}</code></td>\
331-
<td class=\"docblock-short\">{stab_tags}</td>\
332-
</tr>",
329+
"<item-left class=\"{stab}{add}import-item\">\
330+
<code>{vis}{imp}</code>\
331+
</item-left>\
332+
<item-right class=\"docblock-short\">{stab_tags}</item-right>\n",
333333
stab = stab.unwrap_or_default(),
334334
add = add,
335335
vis = myitem.visibility.print_with_space(myitem.def_id, cx),
@@ -358,11 +358,10 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
358358
let doc_value = myitem.doc_value().unwrap_or_default();
359359
write!(
360360
w,
361-
"<tr class=\"{stab}{add}module-item\">\
362-
<td><a class=\"{class}\" href=\"{href}\" \
363-
title=\"{title}\">{name}</a>{unsafety_flag}</td>\
364-
<td class=\"docblock-short\">{stab_tags}{docs}</td>\
365-
</tr>",
361+
"<item-left class=\"{stab}{add}module-item\">\
362+
<a class=\"{class}\" href=\"{href}\" \
363+
title=\"{title}\">{name}</a>{unsafety_flag}</item-left>\
364+
<item-right class=\"docblock-short\">{stab_tags}{docs}</item-right>\n",
366365
name = *myitem.name.as_ref().unwrap(),
367366
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
368367
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
@@ -382,7 +381,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
382381
}
383382

384383
if curty.is_some() {
385-
w.write_str("</table>");
384+
w.write_str("</item-table>\n");
386385
}
387386
}
388387

src/librustdoc/html/static/rustdoc.css

+32-1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ div.impl-items > div {
169169
h1, h2, h3, h4,
170170
.sidebar, a.source, .search-input, .search-results .result-name,
171171
.content table td:first-child > a,
172+
item-left > a,
172173
div.item-list .out-of-band, span.since,
173174
#source-sidebar, #sidebar-toggle,
174175
details.rustdoc-toggle > summary::before,
@@ -710,6 +711,25 @@ a {
710711

711712
.block a.current.crate { font-weight: 500; }
712713

714+
item-table {
715+
display: grid;
716+
column-gap: 1.2rem;
717+
row-gap: 0.0rem;
718+
grid-template-columns: auto 1fr;
719+
/* align content left */
720+
justify-items: start;
721+
}
722+
723+
item-left, item-right {
724+
display: block;
725+
}
726+
item-left {
727+
grid-column: 1;
728+
}
729+
item-right {
730+
grid-column: 2;
731+
}
732+
713733
.search-container {
714734
position: relative;
715735
}
@@ -1737,6 +1757,16 @@ details.undocumented[open] > summary::before {
17371757
#help-button {
17381758
display: none;
17391759
}
1760+
1761+
/* Display an alternating layout on tablets and phones */
1762+
item-table {
1763+
display: flex;
1764+
flex-flow: column wrap;
1765+
}
1766+
item-left, item-right {
1767+
width: 100%;
1768+
}
1769+
17401770
.search-container > div {
17411771
width: calc(100% - 32px);
17421772
}
@@ -1749,7 +1779,8 @@ details.undocumented[open] > summary::before {
17491779
.search-results .result-name, .search-results div.desc, .search-results .result-description {
17501780
width: 100%;
17511781
}
1752-
.search-results div.desc, .search-results .result-description {
1782+
/* Display second row of staggered layouts */
1783+
.search-results div.desc, .search-results .result-description, item-right {
17531784
padding-left: 2em;
17541785
}
17551786
}

src/test/rustdoc/doc-cfg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Portable;
1212
// @has doc_cfg/unix_only/index.html \
1313
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
1414
// 'This is supported on Unix only.'
15-
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AARM\Z'
15+
// @matches - '//*[@class="docblock-short"]//*[@class="stab portability"]' '\AARM\Z'
1616
// @count - '//*[@class="stab portability"]' 2
1717
#[doc(cfg(unix))]
1818
pub mod unix_only {
@@ -42,7 +42,7 @@ pub mod unix_only {
4242
// @has doc_cfg/wasi_only/index.html \
4343
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
4444
// 'This is supported on WASI only.'
45-
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AWebAssembly\Z'
45+
// @matches - '//*[@class="docblock-short"]//*[@class="stab portability"]' '\AWebAssembly\Z'
4646
// @count - '//*[@class="stab portability"]' 2
4747
#[doc(cfg(target_os = "wasi"))]
4848
pub mod wasi_only {
@@ -74,7 +74,7 @@ pub mod wasi_only {
7474

7575
// the portability header is different on the module view versus the full view
7676
// @has doc_cfg/index.html
77-
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\Aavx\Z'
77+
// @matches - '//*[@class="docblock-short"]//*[@class="stab portability"]' '\Aavx\Z'
7878

7979
// @has doc_cfg/fn.uses_target_feature.html
8080
// @has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \

src/test/rustdoc/duplicate-cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#![feature(doc_cfg)]
33

44
// @has 'foo/index.html'
5-
// @matches '-' '//*[@class="module-item"]//*[@class="stab portability"]' '^sync$'
6-
// @has '-' '//*[@class="module-item"]//*[@class="stab portability"]/@title' 'This is supported on crate feature `sync` only'
5+
// @matches '-' '//*[@class="docblock-short"]//*[@class="stab portability"]' '^sync$'
6+
// @has '-' '//*[@class="docblock-short"]//*[@class="stab portability"]/@title' 'This is supported on crate feature `sync` only'
77

88
// @has 'foo/struct.Foo.html'
99
// @has '-' '//*[@class="stab portability"]' 'sync'

src/test/rustdoc/issue-55364.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub mod subone {
2929
// @has - '//section[@id="main"]/details/div[@class="docblock"]//a[@href="../fn.foo.html"]' 'foo'
3030
// @has - '//section[@id="main"]/details/div[@class="docblock"]//a[@href="../fn.bar.html"]' 'bar'
3131
// Though there should be such links later
32-
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td/a[@class="fn"][@href="fn.foo.html"]' 'foo'
33-
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td/a[@class="fn"][@href="fn.bar.html"]' 'bar'
32+
// @has - '//section[@id="main"]/item-table//item-left[@class="module-item"]/a[@class="fn"][@href="fn.foo.html"]' 'foo'
33+
// @has - '//section[@id="main"]/item-table//item-left[@class="module-item"]/a[@class="fn"][@href="fn.bar.html"]' 'bar'
3434
/// See either [foo] or [bar].
3535
pub mod subtwo {
3636

@@ -68,8 +68,8 @@ pub mod subthree {
6868
// Next we go *deeper* - In order to ensure it's not just "this or parent"
6969
// we test `crate::` and a `super::super::...` chain
7070
// @has issue_55364/subfour/subfive/subsix/subseven/subeight/index.html
71-
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td[@class="docblock-short"]//a[@href="../../../../../subone/fn.foo.html"]' 'other foo'
72-
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td[@class="docblock-short"]//a[@href="../../../../../subtwo/fn.bar.html"]' 'other bar'
71+
// @has - '//section[@id="main"]/item-table//item-right[@class="docblock-short"]//a[@href="../../../../../subone/fn.foo.html"]' 'other foo'
72+
// @has - '//section[@id="main"]/item-table//item-right[@class="docblock-short"]//a[@href="../../../../../subtwo/fn.bar.html"]' 'other bar'
7373
pub mod subfour {
7474
pub mod subfive {
7575
pub mod subsix {

src/test/rustdoc/reexport-check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
extern crate reexport_check;
55

66
// @!has 'foo/index.html' '//code' 'pub use self::i32;'
7-
// @has 'foo/index.html' '//tr[@class="deprecated module-item"]' 'i32'
7+
// @has 'foo/index.html' '//item-left[@class="deprecated module-item"]' 'i32'
88
// @has 'foo/i32/index.html'
99
#[allow(deprecated, deprecated_in_future)]
1010
pub use std::i32;
1111
// @!has 'foo/index.html' '//code' 'pub use self::string::String;'
12-
// @has 'foo/index.html' '//tr[@class="module-item"]' 'String'
12+
// @has 'foo/index.html' '//item-left[@class="module-item"]' 'String'
1313
pub use std::string::String;
1414

15-
// @has 'foo/index.html' '//td[@class="docblock-short"]' 'Docs in original'
15+
// @has 'foo/index.html' '//item-right[@class="docblock-short"]' 'Docs in original'
1616
// this is a no-op, but shows what happens if there's an attribute that isn't a doc-comment
1717
#[doc(inline)]
1818
pub use reexport_check::S;

src/test/rustdoc/short-docblock-codeblock.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![crate_name = "foo"]
22

3-
// @has foo/index.html '//*[@class="module-item"]//td[@class="docblock-short"]' ""
4-
// @!has foo/index.html '//*[@id="module-item"]//td[@class="docblock-short"]' "Some text."
5-
// @!has foo/index.html '//*[@id="module-item"]//td[@class="docblock-short"]' "let x = 12;"
3+
// @has foo/index.html '//*[@class="module-item"]//following-sibling::item-right[@class="docblock-short"]' ""
4+
// @!has foo/index.html '//*[@id="module-item"]//following-sibling::item-right[@class="docblock-short"]' "Some text."
5+
// @!has foo/index.html '//*[@id="module-item"]//following-sibling::item-right[@class="docblock-short"]' "let x = 12;"
66

77
/// ```
88
/// let x = 12;

0 commit comments

Comments
 (0)