Skip to content

Commit 4fe4db0

Browse files
Rollup merge of rust-lang#139562 - notriddle:notriddle/ew-resize, r=GuillaumeGomez
rustdoc: add a handle that makes sidebar resizing more obvious This aims to make the resizable sidebars more obvious Preview: <https://notriddle.com/rustdoc-html-demo-12/sidebar-resize-handle/std/index.html> ![image](https://github.com/user-attachments/assets/9602380d-ad92-4b41-8070-e16659d7d445) This change is based on some discussion on [lolbinarycat's idea], but with a more "traditional" design. Specifically, while very few systems use exactly this design, most of them use [a skeumorph of "grip notching"](https://ux.stackexchange.com/questions/80463/what-do-the-3-close-horizontal-bars-not-hamburger-menu-represent-and-what-is-t/80591#80591): - In Jira, resizable sidebars have a stack of four dots. <details><img src="https://github.com/user-attachments/assets/13047998-02bf-47e6-b796-16f393f870b0"></details> - In The GIMP, resizable sidebars have a stack of three dots. <details><img src="https://github.com/user-attachments/assets/138f5c21-3069-4bbe-b306-0bb9a4bf0318"></details> - In [old Windows], "panes" are defined to have the same border style as a window, which has a raised appearance. To evoke this, the PR adds a lightweight "shadow" border, darker than the sidebar itself <details><img src="https://github.com/user-attachments/assets/301da4b8-6c48-4131-b741-1689af84670a"></details> - In [NeXT], a drag point usually had an innie, whether the line in a slider or the circle in a scroller; I can also hide and show the favorites bar in Workspace by dragging on a circular "grip spot" <details><img src="https://github.com/user-attachments/assets/b13c2d30-a3a8-4672-90fa-58c1fdf19f42"></details> - In [old Mac], drag handles for things usually had a "grip track" of parallel lines. <details><img src="https://github.com/user-attachments/assets/1fbecc67-ffbc-4ed6-a8c5-a9ff085638db"></details> *This design is far closer to old Mac than anything else*, though they've put it in the bottom corner instead of the middle. - [OSX] kept that, but the "Source List" part of the Finder still had the circle grip for a time the same way Workspace did (resulting in an odd mishmash, if you compare the source list sidebar with the other grip tracks embedded in the scrollbars). <details><img src="https://github.com/user-attachments/assets/551b8f9d-2dd8-4291-917f-dc88741a2b97"></details> [lolbinarycat's idea]: rust-lang#139420 [old Windows]: https://archive.org/details/windowsinterface00micr/page/n9/mode/2up [old Mac]: https://archive.org/details/apple-hig/1996_Human_Interface_Guidelines_for_Mac_OS_8_%28WWDC_Release%29/page/16/mode/2up [NeXT]: https://archive.org/details/apple-hig/1993%20NeXTSTEP%20User%20Interface%20Guidelines%20-%20Release%203/page/145/mode/2up [OSX]: https://dn721903.ca.archive.org/0/items/apple-hig/MacOSX_HIG_2005_09_08.pdf#page=267
2 parents da1e442 + 34c1b25 commit 4fe4db0

File tree

7 files changed

+70
-23
lines changed

7 files changed

+70
-23
lines changed

src/librustdoc/html/static/css/noscript.css

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ nav.sub {
4343
--settings-button-border-focus: #717171;
4444
--sidebar-background-color: #f5f5f5;
4545
--sidebar-background-color-hover: #e0e0e0;
46+
--sidebar-border-color: #ddd;
4647
--code-block-background-color: #f5f5f5;
4748
--scrollbar-track-background-color: #dcdcdc;
4849
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
@@ -135,6 +136,7 @@ nav.sub {
135136
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
136137
--sidebar-resizer-hover: hsl(207, 90%, 66%);
137138
--sidebar-resizer-active: hsl(207, 90%, 54%);
139+
--sidebar-resizer-shadow: #ccc;
138140
}
139141
/* End theme: light */
140142

@@ -149,6 +151,7 @@ nav.sub {
149151
--settings-button-border-focus: #ffb900;
150152
--sidebar-background-color: #505050;
151153
--sidebar-background-color-hover: #676767;
154+
--sidebar-border-color: #2A2A2A;
152155
--code-block-background-color: #2A2A2A;
153156
--scrollbar-track-background-color: #717171;
154157
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
@@ -244,6 +247,7 @@ nav.sub {
244247
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
245248
--sidebar-resizer-hover: hsl(207, 30%, 54%);
246249
--sidebar-resizer-active: hsl(207, 90%, 54%);
250+
--sidebar-resizer-shadow: #000;
247251
}
248252
/* End theme: dark */
249253
}

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

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* When static files are updated, their suffixes need to be updated.
1+
/* ignore-tidy-filelength */
2+
/*
3+
When static files are updated, their suffixes need to be updated.
24
1. In the top directory run:
35
./x.py doc --stage 1 library/core
46
2. Find the directory containing files named with updated suffixes:
@@ -496,12 +498,13 @@ img {
496498
top: 0;
497499
left: 0;
498500
z-index: var(--desktop-sidebar-z-index);
501+
/* resize indicator: hide this when on touch or mobile */
502+
border-right: solid 1px var(--sidebar-border-color);
499503
}
500504

501505
.rustdoc.src .sidebar {
502506
flex-basis: 50px;
503507
width: 50px;
504-
border-right: 1px solid;
505508
overflow-x: hidden;
506509
/* The sidebar is by default hidden */
507510
overflow-y: hidden;
@@ -515,12 +518,40 @@ img {
515518
.sidebar-resizer {
516519
touch-action: none;
517520
width: 9px;
518-
cursor: col-resize;
521+
cursor: ew-resize;
519522
z-index: calc(var(--desktop-sidebar-z-index) + 1);
520523
position: fixed;
521524
height: 100%;
522-
/* make sure there's a 1px gap between the scrollbar and resize handle */
523-
left: calc(var(--desktop-sidebar-width) + 1px);
525+
left: var(--desktop-sidebar-width);
526+
display: flex;
527+
align-items: center;
528+
justify-content: flex-start;
529+
}
530+
.sidebar-resizer::after {
531+
content: "";
532+
background: linear-gradient(
533+
0.25turn,
534+
transparent 0px,
535+
transparent 2px,
536+
var(--sidebar-border-color) 2px,
537+
var(--sidebar-border-color) 3px,
538+
var(--sidebar-resizer-shadow) 3px,
539+
var(--sidebar-resizer-shadow) 4px,
540+
transparent 4px,
541+
transparent 6px,
542+
var(--sidebar-border-color) 6px,
543+
var(--sidebar-border-color) 7px,
544+
var(--sidebar-resizer-shadow) 7px,
545+
var(--sidebar-resizer-shadow) 8px,
546+
transparent 8px
547+
);
548+
border: solid 1px var(--sidebar-border-color);
549+
border-left: none;
550+
border-right: solid 1px var(--sidebar-resizer-shadow);
551+
border-bottom: solid 1px var(--sidebar-resizer-shadow);
552+
width: 8px;
553+
height: 24px;
554+
image-rendering: crisp-edges;
524555
}
525556

526557
.rustdoc.src .sidebar-resizer {
@@ -543,7 +574,7 @@ img {
543574
}
544575

545576
.sidebar-resizing * {
546-
cursor: col-resize !important;
577+
cursor: ew-resize !important;
547578
}
548579

549580
.sidebar-resizing .sidebar {
@@ -561,7 +592,7 @@ img {
561592
margin: 0;
562593
/* when active or hovered, place resizer glow on top of the sidebar (right next to, or even
563594
on top of, the scrollbar) */
564-
left: var(--desktop-sidebar-width);
595+
left: calc(var(--desktop-sidebar-width) - 1px);
565596
border-left: solid 1px var(--sidebar-resizer-hover);
566597
}
567598

@@ -578,6 +609,10 @@ img {
578609
/* too easy to hit the resizer while trying to hit the [-] toggle */
579610
display: none !important;
580611
}
612+
.sidebar {
613+
/* resize indicator: hide this when on touch or mobile */
614+
border-right: none;
615+
}
581616
}
582617

583618
.sidebar-resizer.active {
@@ -2509,6 +2544,8 @@ in src-script.js and main.js
25092544
/* Reduce height slightly to account for mobile topbar. */
25102545
height: calc(100vh - 45px);
25112546
width: 200px;
2547+
/* resize indicator: hide this when on touch or mobile */
2548+
border-right: none;
25122549
}
25132550

25142551
/* The source view uses a different design for the sidebar toggle, and doesn't have a topbar,
@@ -2897,6 +2934,7 @@ by default.
28972934
--settings-button-border-focus: #717171;
28982935
--sidebar-background-color: #f5f5f5;
28992936
--sidebar-background-color-hover: #e0e0e0;
2937+
--sidebar-border-color: #ddd;
29002938
--code-block-background-color: #f5f5f5;
29012939
--scrollbar-track-background-color: #dcdcdc;
29022940
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
@@ -2989,6 +3027,7 @@ by default.
29893027
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
29903028
--sidebar-resizer-hover: hsl(207, 90%, 66%);
29913029
--sidebar-resizer-active: hsl(207, 90%, 54%);
3030+
--sidebar-resizer-shadow: #ccc;
29923031
}
29933032
/* End theme: light */
29943033

@@ -3002,6 +3041,7 @@ by default.
30023041
--settings-button-border-focus: #ffb900;
30033042
--sidebar-background-color: #505050;
30043043
--sidebar-background-color-hover: #676767;
3044+
--sidebar-border-color: #999;
30053045
--code-block-background-color: #2A2A2A;
30063046
--scrollbar-track-background-color: #717171;
30073047
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
@@ -3097,6 +3137,7 @@ by default.
30973137
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
30983138
--sidebar-resizer-hover: hsl(207, 30%, 54%);
30993139
--sidebar-resizer-active: hsl(207, 90%, 54%);
3140+
--sidebar-resizer-shadow: #000;
31003141
}
31013142
/* End theme: dark */
31023143

@@ -3114,6 +3155,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
31143155
--settings-button-border-focus: #e0e0e0;
31153156
--sidebar-background-color: #14191f;
31163157
--sidebar-background-color-hover: rgba(70, 70, 70, 0.33);
3158+
--sidebar-border-color: #5c6773;
31173159
--code-block-background-color: #191f26;
31183160
--scrollbar-track-background-color: transparent;
31193161
--scrollbar-thumb-background-color: #5c6773;
@@ -3209,6 +3251,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
32093251
--scrape-example-code-wrapper-background-end: rgba(15, 20, 25, 0);
32103252
--sidebar-resizer-hover: hsl(34, 50%, 33%);
32113253
--sidebar-resizer-active: hsl(34, 100%, 66%);
3254+
--sidebar-resizer-shadow: #000;
32123255
}
32133256

32143257
:root[data-theme="ayu"] h1,

src/librustdoc/html/templates/page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ <h2>Files</h2> {# #}
114114
{% endif %}
115115
{{ sidebar|safe }}
116116
</nav> {# #}
117-
<div class="sidebar-resizer"></div> {# #}
117+
<div class="sidebar-resizer" title="Drag to resize sidebar"></div> {# #}
118118
<main>
119119
{% if page.css_class != "src" %}<div class="width-limiter">{% endif %}
120120
{# defined in storage.js to avoid duplicating complex UI across every page #}

tests/rustdoc-gui/sidebar-resize-close-popover.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Checks sidebar resizing close the Settings popover
22
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
3-
assert-property: (".sidebar", {"clientWidth": "200"})
3+
assert-property: (".sidebar", {"clientWidth": "199"})
44
show-text: true
55
click: "#settings-menu"
66
wait-for: "#settings"
77
assert-css: ("#settings", {"display": "block"})
88
// normal resizing
99
drag-and-drop: ((205, 100), (185, 100))
10-
assert-property: (".sidebar", {"clientWidth": "182"})
10+
assert-property: (".sidebar", {"clientWidth": "181"})
1111
assert-css: ("#settings", {"display": "none"})
1212

1313
// Now same thing, but for source code

tests/rustdoc-gui/sidebar-resize-setting.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Checks sidebar resizing stays synced with the setting
22
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
3-
assert-property: (".sidebar", {"clientWidth": "200"})
3+
assert-property: (".sidebar", {"clientWidth": "199"})
44
show-text: true
55

66
// Verify that the "hide" option is unchecked

tests/rustdoc-gui/sidebar-resize.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Checks sidebar resizing
22
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
3-
assert-property: (".sidebar", {"clientWidth": "200"})
3+
assert-property: (".sidebar", {"clientWidth": "199"})
44
show-text: true
55
// normal resizing
66
drag-and-drop: ((205, 100), (185, 100))
7-
assert-property: (".sidebar", {"clientWidth": "182"})
7+
assert-property: (".sidebar", {"clientWidth": "181"})
88
// resize past maximum (don't grow past 500)
99
drag-and-drop: ((185, 100), (600, 100))
10-
assert-property: (".sidebar", {"clientWidth": "500"})
10+
assert-property: (".sidebar", {"clientWidth": "499"})
1111
// resize past minimum (hide sidebar)
1212
drag-and-drop: ((501, 100), (5, 100))
1313
assert-property: (".sidebar", {"clientWidth": "0"})

tests/rustdoc-gui/sidebar.goml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Checks multiple things on the sidebar display (width of its elements, colors, etc).
22
include: "utils.goml"
33
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
4-
assert-property: (".sidebar", {"clientWidth": "200"})
4+
assert-property: (".sidebar", {"clientWidth": "199"})
55
show-text: true
66

77
// First, check the sidebar colors.
@@ -84,13 +84,13 @@ assert-property: ("html", {"scrollTop": "0"})
8484

8585
// We now go back to the crate page to click on the "lib2" crate link.
8686
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
87-
assert-property: (".sidebar", {"clientWidth": "200"})
87+
assert-property: (".sidebar", {"clientWidth": "199"})
8888
assert-css: (".sidebar-elems ul.crate > li:first-child > a", {"color": "#356da4"})
8989
click: ".sidebar-elems ul.crate > li:first-child > a"
9090

9191
// PAGE: lib2/index.html
9292
go-to: "file://" + |DOC_PATH| + "/lib2/index.html"
93-
assert-property: (".sidebar", {"clientWidth": "200"})
93+
assert-property: (".sidebar", {"clientWidth": "199"})
9494
assert-text: (".sidebar > .sidebar-crate > h2 > a", "lib2")
9595
assert-count: (".sidebar .location", 0)
9696
// We check that we have the crates list and that the "current" on is now "lib2".
@@ -116,7 +116,7 @@ assert-text: (".sidebar-elems ul.block > li.current > a", "foobar")
116116
assert-false: ".sidebar-elems > .crate"
117117

118118
go-to: "./module/index.html"
119-
assert-property: (".sidebar", {"clientWidth": "200"})
119+
assert-property: (".sidebar", {"clientWidth": "199"})
120120
assert-text: (".sidebar > .sidebar-crate > h2 > a", "lib2")
121121
assert-text: (".sidebar .location", "Module module")
122122
assert-count: (".sidebar .location", 1)
@@ -134,7 +134,7 @@ assert-property: (".sidebar > .sidebar-elems > #rustdoc-modnav > h2 > a", {
134134
assert-false: ".sidebar-elems > .crate"
135135

136136
go-to: "./sub_module/sub_sub_module/index.html"
137-
assert-property: (".sidebar", {"clientWidth": "200"})
137+
assert-property: (".sidebar", {"clientWidth": "199"})
138138
assert-text: (".sidebar > .sidebar-crate > h2 > a", "lib2")
139139
assert-text: (".sidebar .location", "Module sub_sub_module")
140140
assert-text: (".sidebar > .sidebar-elems > #rustdoc-modnav > h2", "In lib2::module::sub_module")
@@ -149,24 +149,24 @@ assert-text: ("#functions + .item-table dt > a", "foo")
149149

150150
// Links to trait implementations in the sidebar should not wrap even if they are long.
151151
go-to: "file://" + |DOC_PATH| + "/lib2/struct.HasALongTraitWithParams.html"
152-
assert-property: (".sidebar", {"clientWidth": "200"})
152+
assert-property: (".sidebar", {"clientWidth": "199"})
153153
assert-property: (".sidebar-elems section .block li > a", {"offsetHeight": 29})
154154

155155
// Test that clicking on of the "In <module>" headings in the sidebar links to the
156156
// appropriate anchor in index.html.
157157
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
158-
assert-property: (".sidebar", {"clientWidth": "200"})
158+
assert-property: (".sidebar", {"clientWidth": "199"})
159159
click: "//ul[@class='block mod']/preceding-sibling::h3/a"
160160
// PAGE: index.html
161161
assert-css: ("#modules", {"background-color": "#fdffd3"})
162162

163163
// Finally, assert that the Summary toggle doesn't affect sidebar width.
164164
click: "#toggle-all-docs"
165165
assert-text: ("#toggle-all-docs", "Show all")
166-
assert-property: (".sidebar", {"clientWidth": "200"})
166+
assert-property: (".sidebar", {"clientWidth": "199"})
167167
click: "#toggle-all-docs"
168168
assert-text: ("#toggle-all-docs", "Summary")
169-
assert-property: (".sidebar", {"clientWidth": "200"})
169+
assert-property: (".sidebar", {"clientWidth": "199"})
170170

171171
// Checks that all.html and index.html have their sidebar link in the same place.
172172
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"

0 commit comments

Comments
 (0)