Skip to content

Commit 4729e30

Browse files
authored
Unrolled build for rust-lang#127229
Rollup merge of rust-lang#127229 - notriddle:notriddle/mile-wide-bar, r=GuillaumeGomez rustdoc: click target for sidebar items flush left This change adjusts the clickable area of sidebar links to touch the leftmost edge of the canvas, making them [much easier](https://www.nngroup.com/articles/fitts-law/) to click (when the browser window is maximized or tiled left, but those cases are common enough to matter). [Screencast from 2024-07-15 15-31-07.webm](https://github.com/user-attachments/assets/1e952d3a-e9e7-476b-b211-44a17c190b38) <details><summary>old screencast</summary> [Screencast from 2024-07-01 17-23-34.webm](https://github.com/rust-lang/rust/assets/1593513/dc6f9c2e-5904-403d-b353-d233e6e1afbc) </details>
2 parents fcc325f + 5514906 commit 4729e30

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

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

+51-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
--desktop-sidebar-width: 200px;
1616
--src-sidebar-width: 300px;
1717
--desktop-sidebar-z-index: 100;
18+
--sidebar-elems-left-padding: 24px;
1819
}
1920

2021
/* See FiraSans-LICENSE.txt for the Fira Sans license. */
@@ -559,8 +560,11 @@ ul.block, .block li {
559560
.sidebar > h2 a {
560561
display: block;
561562
padding: 0.25rem; /* 4px */
562-
margin-left: -0.25rem;
563563
margin-right: 0.25rem;
564+
/* extend click target to far edge of screen (mile wide bar) */
565+
border-left: solid var(--sidebar-elems-left-padding) transparent;
566+
margin-left: calc(-0.25rem - var(--sidebar-elems-left-padding));
567+
background-clip: border-box;
564568
}
565569

566570
.sidebar h2 {
@@ -578,7 +582,7 @@ ul.block, .block li {
578582
.sidebar-elems,
579583
.sidebar > .version,
580584
.sidebar > h2 {
581-
padding-left: 24px;
585+
padding-left: var(--sidebar-elems-left-padding);
582586
}
583587

584588
.sidebar a {
@@ -632,13 +636,56 @@ ul.block, .block li {
632636
.sidebar-crate .logo-container {
633637
/* The logo is expected to have 8px "slop" along its edges, so we can optically
634638
center it. */
635-
margin: 0 -16px 0 -16px;
639+
margin: 0 calc(-16px - var(--sidebar-elems-left-padding));
640+
padding: 0 var(--sidebar-elems-left-padding);
636641
text-align: center;
637642
}
638643

644+
.sidebar-crate .logo-container img {
645+
/* When in a horizontal logo lockup, the highlight color of the crate name menu item
646+
extends underneath the actual logo (in a vertical lockup, that background highlight
647+
extends to the left edge of the screen).
648+
649+
To prevent a weird-looking colored band from appearing under the logo, cover it up
650+
with the sidebar's background. Additionally, the crate name extends slightly above
651+
the logo, so that its highlight has a bit of space to let the ascenders breath while
652+
also having those ascenders meet exactly with the top of the logo.
653+
654+
In ANSI art, make it look like this:
655+
| ┌─────┐
656+
| (R) │ std │
657+
| └─────┘
658+
659+
Not like this (which would happen without the z-index):
660+
| ┌────────┐
661+
| (│ std │
662+
| └────────┘
663+
664+
Not like this (which would happen without the background):
665+
| ┌────────┐
666+
| (R) std │
667+
| └────────┘
668+
669+
Nor like this (which would happen without the negative margin):
670+
| ─────────┐
671+
| (R) │ std │
672+
| └─────┘
673+
*/
674+
margin-top: -16px;
675+
border-top: solid 16px transparent;
676+
box-sizing: content-box;
677+
position: relative;
678+
background-color: var(--sidebar-background-color);
679+
background-clip: border-box;
680+
z-index: 1;
681+
}
682+
639683
.sidebar-crate h2 a {
640684
display: block;
641-
margin: 0 calc(-24px + 0.25rem) 0 -0.2rem;
685+
/* extend click target to far edge of screen (mile wide bar) */
686+
border-left: solid var(--sidebar-elems-left-padding) transparent;
687+
background-clip: border-box;
688+
margin: 0 calc(-24px + 0.25rem) 0 calc(-0.2rem - var(--sidebar-elems-left-padding));
642689
/* Align the sidebar crate link with the search bar, which have different
643690
font sizes.
644691

tests/rustdoc-gui/huge-logo.goml

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
go-to: "file://" + |DOC_PATH| + "/huge_logo/index.html"
44

55
set-window-size: (1280, 1024)
6-
// offsetWidth = width of sidebar
7-
assert-property: (".sidebar-crate .logo-container", {"offsetWidth": "48", "offsetHeight": 48})
8-
assert-property: (".sidebar-crate .logo-container img", {"offsetWidth": "48", "offsetHeight": 48})
6+
// offsetWidth = width of sidebar + left and right margins
7+
assert-property: (".sidebar-crate .logo-container", {"offsetWidth": "96", "offsetHeight": 48})
8+
// offsetWidth = width of sidebar, offsetHeight = height + top padding
9+
assert-property: (".sidebar-crate .logo-container img", {"offsetWidth": "48", "offsetHeight": 64})
10+
assert-css: (".sidebar-crate .logo-container img", {"border-top-width": "16px", "margin-top": "-16px"})
911

1012
set-window-size: (400, 600)
1113
// offset = size + margin

tests/rustdoc-gui/sidebar.goml

+15
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,18 @@ assert-property: (".sidebar .sidebar-crate h2 a", {
179179
"offsetTop": |index_sidebar_y|,
180180
"offsetLeft": |index_sidebar_x|,
181181
})
182+
183+
// Check that the sidebar links touch the left side of the box
184+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
185+
assert-position: (".sidebar .block a", {"x": -4})
186+
assert-position: (".sidebar-crate > h2 > a", {"x": -3})
187+
188+
// Check that the main sidebar links touch the left side of the box
189+
// but the crate name doesn't, because the logo takes that space
190+
go-to: "file://" + |DOC_PATH| + "/huge_logo/index.html"
191+
assert-position: (".sidebar .block a", {"x": -4})
192+
// when side-by-side, it's not line wrapped
193+
assert-position-false: (".sidebar-crate > h2 > a", {"x": -3})
194+
// when line-wrapped, see that it becomes flush-left again
195+
drag-and-drop: ((205, 100), (108, 100))
196+
assert-position: (".sidebar-crate > h2 > a", {"x": -3})

0 commit comments

Comments
 (0)