Skip to content

Commit 2bce1ad

Browse files
authored
Rollup merge of #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/d4d70982-8045-4fed-818a-982108b0d3b3) ![image](https://github.com/user-attachments/assets/4aaa3663-19f3-4e04-89c6-53db0ddb72ed) ![image](https://github.com/user-attachments/assets/3f612c5b-6be1-4383-801a-067c87425eb9) 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](https://ux.stackexchange.com/questions/80463/what-do-the-3-close-horizontal-bars-not-hamburger-menu-represent-and-what-is-t/80591#80591) of a grip texture: - This design is similar to the one used in the Rust Playground, and almost identical to UX StackExchange: <details><img src="https://github.com/user-attachments/assets/39a6bb69-4895-4fd0-87da-b87913bc7309"></details> <details><img src="https://github.com/user-attachments/assets/a41942e1-651b-410b-b855-2aafe8fe54f4"></details> - In Jira, resizable sidebars have a stack of four dots, but only in one row. <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]: #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 c6b9253 + e6e5206 commit 2bce1ad

File tree

7 files changed

+56
-30
lines changed

7 files changed

+56
-30
lines changed

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

+2
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);
@@ -149,6 +150,7 @@ nav.sub {
149150
--settings-button-border-focus: #ffb900;
150151
--sidebar-background-color: #505050;
151152
--sidebar-background-color-hover: #676767;
153+
--sidebar-border-color: #2A2A2A;
152154
--code-block-background-color: #2A2A2A;
153155
--scrollbar-track-background-color: #717171;
154156
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);

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

+38-14
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,27 @@ 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+
color: var(--right-side-color);
530+
}
531+
.sidebar-resizer::before {
532+
content: "";
533+
border-right: dotted 2px currentColor;
534+
width: 2px;
535+
height: 12px;
536+
}
537+
.sidebar-resizer::after {
538+
content: "";
539+
border-right: dotted 2px currentColor;
540+
width: 2px;
541+
height: 16px;
524542
}
525543

526544
.rustdoc.src .sidebar-resizer {
@@ -543,11 +561,12 @@ img {
543561
}
544562

545563
.sidebar-resizing * {
546-
cursor: col-resize !important;
564+
cursor: ew-resize !important;
547565
}
548566

549567
.sidebar-resizing .sidebar {
550568
position: fixed;
569+
border-right: solid 2px var(--sidebar-resizer-active);
551570
}
552571
.sidebar-resizing > body {
553572
padding-left: var(--resizing-sidebar-width);
@@ -561,8 +580,9 @@ img {
561580
margin: 0;
562581
/* when active or hovered, place resizer glow on top of the sidebar (right next to, or even
563582
on top of, the scrollbar) */
564-
left: var(--desktop-sidebar-width);
583+
left: calc(var(--desktop-sidebar-width) - 1px);
565584
border-left: solid 1px var(--sidebar-resizer-hover);
585+
color: var(--sidebar-resizer-hover);
566586
}
567587

568588
.src-sidebar-expanded .rustdoc.src .sidebar-resizer:hover,
@@ -578,21 +598,20 @@ img {
578598
/* too easy to hit the resizer while trying to hit the [-] toggle */
579599
display: none !important;
580600
}
601+
.sidebar {
602+
/* resize indicator: hide this when on touch or mobile */
603+
border-right: none;
604+
}
581605
}
582606

583607
.sidebar-resizer.active {
584608
/* make the resize tool bigger when actually resizing, to avoid :hover styles on other stuff
585609
while resizing */
586610
padding: 0 140px;
587-
width: 2px;
611+
width: calc(140px + 140px + 9px + 2px);
588612
margin-left: -140px;
589613
border-left: none;
590-
}
591-
.sidebar-resizer.active::before {
592-
border-left: solid 2px var(--sidebar-resizer-active);
593-
display: block;
594-
height: 100%;
595-
content: "";
614+
color: var(--sidebar-resizer-active);
596615
}
597616

598617
.sidebar, .mobile-topbar, .sidebar-menu-toggle,
@@ -2509,6 +2528,8 @@ in src-script.js and main.js
25092528
/* Reduce height slightly to account for mobile topbar. */
25102529
height: calc(100vh - 45px);
25112530
width: 200px;
2531+
/* resize indicator: hide this when on touch or mobile */
2532+
border-right: none;
25122533
}
25132534

25142535
/* The source view uses a different design for the sidebar toggle, and doesn't have a topbar,
@@ -2897,6 +2918,7 @@ by default.
28972918
--settings-button-border-focus: #717171;
28982919
--sidebar-background-color: #f5f5f5;
28992920
--sidebar-background-color-hover: #e0e0e0;
2921+
--sidebar-border-color: #ddd;
29002922
--code-block-background-color: #f5f5f5;
29012923
--scrollbar-track-background-color: #dcdcdc;
29022924
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
@@ -3002,6 +3024,7 @@ by default.
30023024
--settings-button-border-focus: #ffb900;
30033025
--sidebar-background-color: #505050;
30043026
--sidebar-background-color-hover: #676767;
3027+
--sidebar-border-color: #999;
30053028
--code-block-background-color: #2A2A2A;
30063029
--scrollbar-track-background-color: #717171;
30073030
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
@@ -3114,6 +3137,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
31143137
--settings-button-border-focus: #e0e0e0;
31153138
--sidebar-background-color: #14191f;
31163139
--sidebar-background-color-hover: rgba(70, 70, 70, 0.33);
3140+
--sidebar-border-color: #5c6773;
31173141
--code-block-background-color: #191f26;
31183142
--scrollbar-track-background-color: transparent;
31193143
--scrollbar-thumb-background-color: #5c6773;

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)