Skip to content

Commit 3fa98a1

Browse files
committed
rustdoc: add a handle that makes sidebar resizing more obvious
This change is based on some discussion on [lolbinarycat's idea], but with a more "traditional" design. Specifically, this is the closest thing I could find to a consensus across many systems I looked at for inspiration: - In Jira, resizable sidebars have a stack of four dots. - In The GIMP, resizable sidebars have a stack of three dots. - In [old Windows], "panes" are defined to have the same border style as a window, which has a raised appearance. - 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" - In [old Mac], drag handles for things usually had a "grip track" of parallel lines. - [OSX] kept that, but the "Source List" part of the Finder still had the circle grip for a time the same way Workspace did [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
1 parent dcecb99 commit 3fa98a1

File tree

6 files changed

+68
-22
lines changed

6 files changed

+68
-22
lines changed

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

+6
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,8 @@ 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-img-filter: opacity(66%);
140+
--sidebar-resizer-img-hover-filter: none;
138141
}
139142
/* End theme: light */
140143

@@ -149,6 +152,7 @@ nav.sub {
149152
--settings-button-border-focus: #ffb900;
150153
--sidebar-background-color: #505050;
151154
--sidebar-background-color-hover: #676767;
155+
--sidebar-border-color: #2A2A2A;
152156
--code-block-background-color: #2A2A2A;
153157
--scrollbar-track-background-color: #717171;
154158
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
@@ -244,6 +248,8 @@ nav.sub {
244248
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
245249
--sidebar-resizer-hover: hsl(207, 30%, 54%);
246250
--sidebar-resizer-active: hsl(207, 90%, 54%);
251+
--sidebar-resizer-img-filter: opacity(66%);
252+
--sidebar-resizer-img-hover-filter: none;
247253
}
248254
/* End theme: dark */
249255
}

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

+47-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+
/*
2+
// ignore-tidy-filelength
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,32 @@ 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: center;
529+
}
530+
531+
.sidebar-resizer::after {
532+
content: url('data:image/svg+xml,\
533+
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="24" viewBox="0 0 8 24"> \
534+
<linearGradient id="x" x1="0" x2="0" y1="0" y2="1"> \
535+
<stop offset="0.5" stop-color="%23666"/><stop offset="0.5" stop-color="%23ccc"/> \
536+
</linearGradient> \
537+
<circle r="2" fill="none" stroke-width="2" stroke="url(%23x)" cy="21" cx="3"/> \
538+
<circle r="2" fill="none" stroke-width="2" stroke="url(%23x)" cy="15" cx="3"/> \
539+
<circle r="2" fill="none" stroke-width="2" stroke="url(%23x)" cy="9" cx="3"/> \
540+
<circle r="2" fill="none" stroke-width="2" stroke="url(%23x)" cy="3" cx="3"/></svg>');
541+
width: 8px;
542+
height: 24px;
543+
filter: var(--sidebar-resizer-img-filter);
544+
}
545+
.sidebar-resizer:hover::after {
546+
filter: var(--sidebar-resizer-img-hover-filter);
524547
}
525548
526549
.rustdoc.src .sidebar-resizer {
@@ -543,7 +566,7 @@ img {
543566
}
544567
545568
.sidebar-resizing * {
546-
cursor: col-resize !important;
569+
cursor: ew-resize !important;
547570
}
548571
549572
.sidebar-resizing .sidebar {
@@ -561,7 +584,7 @@ img {
561584
margin: 0;
562585
/* when active or hovered, place resizer glow on top of the sidebar (right next to, or even
563586
on top of, the scrollbar) */
564-
left: var(--desktop-sidebar-width);
587+
left: calc(var(--desktop-sidebar-width) - 1px);
565588
border-left: solid 1px var(--sidebar-resizer-hover);
566589
}
567590
@@ -578,6 +601,10 @@ img {
578601
/* too easy to hit the resizer while trying to hit the [-] toggle */
579602
display: none !important;
580603
}
604+
.sidebar {
605+
/* resize indicator: hide this when on touch or mobile */
606+
border-right: none;
607+
}
581608
}
582609
583610
.sidebar-resizer.active {
@@ -590,6 +617,8 @@ img {
590617
}
591618
.sidebar-resizer.active::before {
592619
border-left: solid 2px var(--sidebar-resizer-active);
620+
margin-left: 8px;
621+
padding-left: 1px;
593622
display: block;
594623
height: 100%;
595624
content: "";
@@ -2509,6 +2538,8 @@ in src-script.js and main.js
25092538
/* Reduce height slightly to account for mobile topbar. */
25102539
height: calc(100vh - 45px);
25112540
width: 200px;
2541+
/* resize indicator: hide this when on touch or mobile */
2542+
border-right: none;
25122543
}
25132544

25142545
/* The source view uses a different design for the sidebar toggle, and doesn't have a topbar,
@@ -2897,6 +2928,7 @@ by default.
28972928
--settings-button-border-focus: #717171;
28982929
--sidebar-background-color: #f5f5f5;
28992930
--sidebar-background-color-hover: #e0e0e0;
2931+
--sidebar-border-color: #ddd;
29002932
--code-block-background-color: #f5f5f5;
29012933
--scrollbar-track-background-color: #dcdcdc;
29022934
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
@@ -2989,6 +3021,8 @@ by default.
29893021
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
29903022
--sidebar-resizer-hover: hsl(207, 90%, 66%);
29913023
--sidebar-resizer-active: hsl(207, 90%, 54%);
3024+
--sidebar-resizer-img-filter: opacity(66%);
3025+
--sidebar-resizer-img-hover-filter: none;
29923026
}
29933027
/* End theme: light */
29943028

@@ -3002,6 +3036,7 @@ by default.
30023036
--settings-button-border-focus: #ffb900;
30033037
--sidebar-background-color: #505050;
30043038
--sidebar-background-color-hover: #676767;
3039+
--sidebar-border-color: #2A2A2A;
30053040
--code-block-background-color: #2A2A2A;
30063041
--scrollbar-track-background-color: #717171;
30073042
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
@@ -3097,6 +3132,8 @@ by default.
30973132
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
30983133
--sidebar-resizer-hover: hsl(207, 30%, 54%);
30993134
--sidebar-resizer-active: hsl(207, 90%, 54%);
3135+
--sidebar-resizer-img-filter: opacity(66%);
3136+
--sidebar-resizer-img-hover-filter: none;
31003137
}
31013138
/* End theme: dark */
31023139

@@ -3114,6 +3151,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
31143151
--settings-button-border-focus: #e0e0e0;
31153152
--sidebar-background-color: #14191f;
31163153
--sidebar-background-color-hover: rgba(70, 70, 70, 0.33);
3154+
--sidebar-border-color: #000;
31173155
--code-block-background-color: #191f26;
31183156
--scrollbar-track-background-color: transparent;
31193157
--scrollbar-thumb-background-color: #5c6773;
@@ -3209,6 +3247,8 @@ Original by Dempfi (https://github.com/dempfi/ayu)
32093247
--scrape-example-code-wrapper-background-end: rgba(15, 20, 25, 0);
32103248
--sidebar-resizer-hover: hsl(34, 50%, 33%);
32113249
--sidebar-resizer-active: hsl(34, 100%, 66%);
3250+
--sidebar-resizer-img-filter: opacity(66%);
3251+
--sidebar-resizer-img-hover-filter: none;
32123252
}
32133253

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

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)