Skip to content

Commit c013962

Browse files
authored
Rollup merge of #103990 - notriddle:notriddle/logo-container, r=GuillaumeGomez
rustdoc: clean up `.logo-container` layout CSS This commit should result in no appearance changes. To make the logo container exactly the desired height, you want to get rid of the part of the box used for typographic descenders (you know, the part of g, y, and j that descends below the baseline). After all, it contains no text, but the space is still left open in the layout by default, because `<img>` is `display:inline`. The CSS used to employ three different tricks to accomplish this: * By making `.sidebar .logo-container` a flex container, the image becomes a flex item and is [blockified], without synthesizing any inline boxes. No inline boxes means no descenders. * By giving `.mobile-topbar .logo-container` a max-height exactly the same as the height of the image plus the padding, the descender area gets cut off. * By setting `.sub-logo-container { line-height: 0 }`, we ensure that the only box that contributes to the height of the line box is the image itself, and not any zero-content text boxes that neighbor it. See the [logical height algorithm]. This commit gets rid of the first two hacks, leaving only the third, since it requires only one line of code to accomplish and doesn't require setting the value based on math. [blockified]: https://drafts.csswg.org/css-flexbox-1/#flex-items [logical height algorithm]: https://www.w3.org/TR/css-inline-3/#inline-height
2 parents 131ef95 + 2189480 commit c013962

File tree

8 files changed

+60
-9
lines changed

8 files changed

+60
-9
lines changed

src/librustdoc/html/static/css/rustdoc.css

+3-7
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ img {
367367
overflow: visible;
368368
}
369369

370-
.sub-logo-container {
370+
.sub-logo-container, .logo-container {
371+
/* zero text boxes so that computed line height = image height exactly */
371372
line-height: 0;
372373
}
373374

@@ -465,10 +466,9 @@ img {
465466
}
466467

467468
.sidebar .logo-container {
468-
display: flex;
469469
margin-top: 10px;
470470
margin-bottom: 10px;
471-
justify-content: center;
471+
text-align: center;
472472
}
473473

474474
.version {
@@ -1755,10 +1755,6 @@ in storage.js
17551755
white-space: nowrap;
17561756
}
17571757

1758-
.mobile-topbar .logo-container {
1759-
max-height: 45px;
1760-
}
1761-
17621758
.mobile-topbar .logo-container > img {
17631759
max-width: 35px;
17641760
max-height: 35px;

src/test/rustdoc-gui/huge-logo.goml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// huge_logo crate has a custom 712x860 logo
2+
// test to ensure the maximum size in the layout works correctly
3+
goto: "file://" + |DOC_PATH| + "/huge_logo/index.html"
4+
5+
size: (1280, 1024)
6+
// offsetWidth = width of sidebar
7+
assert-property: (".sidebar .logo-container", {"offsetWidth": "200", "offsetHeight": 100})
8+
assert-property: (".sidebar .logo-container img", {"offsetWidth": "100", "offsetHeight": 100})
9+
10+
size: (400, 600)
11+
// offset = size + margin
12+
assert-property: (".mobile-topbar .logo-container", {"offsetWidth": "55", "offsetHeight": 45})
13+
assert-property: (".mobile-topbar .logo-container img", {"offsetWidth": "35", "offsetHeight": 35})
14+
15+
goto: "file://" + |DOC_PATH| + "/src/huge_logo/lib.rs.html"
16+
17+
size: (1280, 1024)
18+
assert-property: (".sub-logo-container", {"offsetWidth": "60", "offsetHeight": 60})
19+
20+
size: (400, 600)
21+
assert-property: (".sub-logo-container", {"offsetWidth": "35", "offsetHeight": 35})

src/test/rustdoc-gui/search-filter.goml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ click: "#crate-search"
1414
// We select "lib2" option then press enter to change the filter.
1515
press-key: "ArrowDown"
1616
press-key: "ArrowDown"
17+
press-key: "ArrowDown"
1718
press-key: "Enter"
1819
// Waiting for the search results to appear...
1920
wait-for: "#titles"
@@ -37,6 +38,7 @@ assert-property: ("#crate-search", {"value": "lib2"})
3738
click: "#crate-search"
3839
press-key: "ArrowUp"
3940
press-key: "ArrowUp"
41+
press-key: "ArrowUp"
4042
press-key: "Enter"
4143
// Waiting for the search results to appear...
4244
wait-for: "#titles"

src/test/rustdoc-gui/sidebar-source-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
2828
// Only "another_folder" should be "open" in "lib2".
2929
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
3030
// All other trees should be collapsed.
31-
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 5)
31+
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 6)
3232

3333
// We now switch to mobile mode.
3434
size: (600, 600)

src/test/rustdoc-gui/source-code-page.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ assert: ".source-sidebar-expanded"
7878

7979
// We check that the first entry of the sidebar is collapsed
8080
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
81-
assert-text: ("#source-sidebar details:first-of-type > summary", "implementors")
81+
assert-text: ("#source-sidebar details:first-of-type > summary", "huge_logo")
8282
// We now click on it.
8383
click: "#source-sidebar details:first-of-type > summary"
8484
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "huge_logo"
7+
version = "0.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "huge_logo"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

src/test/rustdoc-gui/src/huge_logo/src/lib.rs

+17
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)