Skip to content

Commit 0983438

Browse files
committed
rustdoc: allow resizing the sidebar
1 parent 3c23df4 commit 0983438

18 files changed

+409
-28
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,7 @@ fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
20002000
map.insert("themeStyle".into(), 1);
20012001
map.insert("settings-menu".into(), 1);
20022002
map.insert("help-button".into(), 1);
2003+
map.insert("sidebar-button".into(), 1);
20032004
map.insert("main-content".into(), 1);
20042005
map.insert("toggle-all-docs".into(), 1);
20052006
map.insert("all-types".into(), 1);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rules.
99
margin-left: 0 !important;
1010
}
1111

12-
#copy-path {
12+
#copy-path, #sidebar-button, .sidebar-resizer {
1313
/* It requires JS to work so no need to display it in this case. */
1414
display: none;
1515
}
@@ -132,6 +132,8 @@ nav.sub {
132132
--scrape-example-help-hover-color: #000;
133133
--scrape-example-code-wrapper-background-start: rgba(255, 255, 255, 1);
134134
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
135+
--sidebar-resizer-hover: hsl(207, 90%, 66%);
136+
--sidebar-resizer-active: hsl(207, 90%, 54%);
135137
}
136138
/* End theme: light */
137139

@@ -238,6 +240,8 @@ nav.sub {
238240
--scrape-example-help-hover-color: #fff;
239241
--scrape-example-code-wrapper-background-start: rgba(53, 53, 53, 1);
240242
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
243+
--sidebar-resizer-hover: hsl(207, 30%, 54%);
244+
--sidebar-resizer-active: hsl(207, 90%, 54%);
241245
}
242246
/* End theme: dark */
243247
}

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

Lines changed: 124 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ img {
383383

384384
.sidebar {
385385
font-size: 0.875rem;
386-
flex: 0 0 200px;
386+
flex: 0 0 var(--desktop-sidebar-width, 200px);
387387
overflow-y: scroll;
388388
overscroll-behavior: contain;
389389
position: sticky;
@@ -401,6 +401,87 @@ img {
401401
z-index: 1;
402402
}
403403

404+
.hide-sidebar .sidebar,
405+
.hide-sidebar .sidebar-resizer {
406+
display: none;
407+
}
408+
409+
.sidebar-resizer {
410+
touch-action: none;
411+
width: 9px;
412+
cursor: col-resize;
413+
z-index: 10;
414+
position: absolute;
415+
height: 100%;
416+
/* make sure there's a 1px gap between the scrollbar and resize handle */
417+
left: calc(var(--desktop-sidebar-width, 200px) + 1px);
418+
}
419+
420+
.rustdoc.src .sidebar-resizer {
421+
/* when closed, place resizer glow on top of the normal src sidebar border (no need to worry
422+
about sidebar) */
423+
left: 49px;
424+
}
425+
426+
.src-sidebar-expanded .rustdoc.src .sidebar-resizer {
427+
/* for src sidebar, gap is already provided by 1px border on sidebar itself, so place resizer
428+
to right of it */
429+
left: var(--src-sidebar-width, 300px);
430+
}
431+
432+
.sidebar-resizing {
433+
-moz-user-select: none;
434+
-webkit-user-select: none;
435+
-ms-user-select: none;
436+
user-select: none;
437+
}
438+
439+
.sidebar-resizing * {
440+
cursor: col-resize !important;
441+
}
442+
443+
.sidebar-resizer:hover,
444+
.sidebar-resizer:active,
445+
.sidebar-resizer:focus,
446+
.sidebar-resizer.active {
447+
width: 10px;
448+
margin: 0;
449+
/* when active or hovered, place resizer glow on top of the sidebar (right next to, or even
450+
on top of, the scrollbar) */
451+
left: var(--desktop-sidebar-width, 200px);
452+
border-left: solid 1px var(--sidebar-resizer-hover);
453+
}
454+
455+
.src-sidebar-expanded .rustdoc.src .sidebar-resizer:hover,
456+
.src-sidebar-expanded .rustdoc.src .sidebar-resizer:active,
457+
.src-sidebar-expanded .rustdoc.src .sidebar-resizer:focus,
458+
.src-sidebar-expanded .rustdoc.src .sidebar-resizer.active {
459+
/* when active or hovered, place resizer glow on top of the normal src sidebar border */
460+
left: calc(var(--src-sidebar-width, 300px) - 1px);
461+
}
462+
463+
@media (pointer: coarse) {
464+
.sidebar-resizer {
465+
/* too easy to hit the resizer while trying to hit the [-] toggle */
466+
display: none !important;
467+
}
468+
}
469+
470+
.sidebar-resizer.active {
471+
/* make the resize tool bigger when actually resizing, to avoid :hover styles on other stuff
472+
while resizing */
473+
padding: 0 140px;
474+
width: 2px;
475+
margin-left: -140px;
476+
border-left: none;
477+
}
478+
.sidebar-resizer.active:before {
479+
border-left: solid 2px var(--sidebar-resizer-active);
480+
display: block;
481+
height: 100%;
482+
content: "";
483+
}
484+
404485
.sidebar, .mobile-topbar, .sidebar-menu-toggle,
405486
#src-sidebar-toggle, #src-sidebar {
406487
background-color: var(--sidebar-background-color);
@@ -416,7 +497,7 @@ img {
416497

417498
.src-sidebar-expanded .src .sidebar {
418499
overflow-y: auto;
419-
flex-basis: 300px;
500+
flex-basis: var(--src-sidebar-width, 300px);
420501
}
421502

422503
.src-sidebar-expanded .src .sidebar > *:not(#src-sidebar-toggle) {
@@ -477,6 +558,7 @@ ul.block, .block li {
477558
display: block;
478559
padding: 0.25rem; /* 4px */
479560
margin-left: -0.25rem;
561+
margin-right: 0.25rem;
480562
}
481563

482564
.sidebar h2 {
@@ -778,7 +860,7 @@ h2.small-section-header > .anchor {
778860
text-decoration: underline;
779861
}
780862

781-
.crate.block a.current { font-weight: 500; }
863+
.crate.block li.current a { font-weight: 500; }
782864

783865
/* In most contexts we use `overflow-wrap: anywhere` to ensure that we can wrap
784866
as much as needed on mobile (see
@@ -1477,7 +1559,20 @@ a.tooltip:hover::after {
14771559
margin-left: 4px;
14781560
display: flex;
14791561
}
1480-
#settings-menu > a, #help-button > a {
1562+
#sidebar-button {
1563+
display: none;
1564+
}
1565+
.hide-sidebar #sidebar-button {
1566+
display: flex;
1567+
margin-right: 4px;
1568+
position: fixed;
1569+
left: 6px;
1570+
height: 34px;
1571+
width: 34px;
1572+
background-color: var(--main-background-color);
1573+
z-index: 1;
1574+
}
1575+
#settings-menu > a, #help-button > a, #sidebar-button > a {
14811576
display: flex;
14821577
align-items: center;
14831578
justify-content: center;
@@ -1492,7 +1587,8 @@ a.tooltip:hover::after {
14921587
}
14931588

14941589
#settings-menu > a:hover, #settings-menu > a:focus,
1495-
#help-button > a:hover, #help-button > a:focus {
1590+
#help-button > a:hover, #help-button > a:focus,
1591+
#sidebar-button > a:hover, #sidebar-button > a:focus {
14961592
border-color: var(--settings-button-border-focus);
14971593
}
14981594

@@ -1721,6 +1817,10 @@ in src-script.js
17211817
scroll-margin-top: 45px;
17221818
}
17231819

1820+
.hide-sidebar #sidebar-button {
1821+
position: static;
1822+
}
1823+
17241824
.rustdoc {
17251825
/* Sidebar should overlay main content, rather than pushing main content to the right.
17261826
Turn off `display: flex` on the body element. */
@@ -1749,7 +1849,8 @@ in src-script.js
17491849
/* Hide the logo and item name from the sidebar. Those are displayed
17501850
in the mobile-topbar instead. */
17511851
.sidebar .logo-container,
1752-
.sidebar .location {
1852+
.sidebar .location,
1853+
.sidebar-resizer {
17531854
display: none;
17541855
}
17551856

@@ -1817,6 +1918,10 @@ in src-script.js
18171918
top: 0;
18181919
}
18191920

1921+
.hide-sidebar .mobile-topbar {
1922+
display: none;
1923+
}
1924+
18201925
.sidebar-menu-toggle {
18211926
width: 45px;
18221927
/* Rare exception to specifying font sizes in rem. Since this is acting
@@ -1826,6 +1931,10 @@ in src-script.js
18261931
color: var(--main-color);
18271932
}
18281933

1934+
.hide-sidebar .sidebar-menu-toggle {
1935+
display: none;
1936+
}
1937+
18291938
.sidebar-elems {
18301939
margin-top: 1em;
18311940
}
@@ -2273,6 +2382,8 @@ in src-script.js
22732382
--scrape-example-help-hover-color: #000;
22742383
--scrape-example-code-wrapper-background-start: rgba(255, 255, 255, 1);
22752384
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
2385+
--sidebar-resizer-hover: hsl(207, 90%, 66%);
2386+
--sidebar-resizer-active: hsl(207, 90%, 54%);
22762387
}
22772388
/* End theme: light */
22782389

@@ -2378,6 +2489,8 @@ in src-script.js
23782489
--scrape-example-help-hover-color: #fff;
23792490
--scrape-example-code-wrapper-background-start: rgba(53, 53, 53, 1);
23802491
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
2492+
--sidebar-resizer-hover: hsl(207, 30%, 54%);
2493+
--sidebar-resizer-active: hsl(207, 90%, 54%);
23812494
}
23822495
/* End theme: dark */
23832496

@@ -2487,6 +2600,8 @@ Original by Dempfi (https://github.com/dempfi/ayu)
24872600
--scrape-example-help-hover-color: #fff;
24882601
--scrape-example-code-wrapper-background-start: rgba(15, 20, 25, 1);
24892602
--scrape-example-code-wrapper-background-end: rgba(15, 20, 25, 0);
2603+
--sidebar-resizer-hover: hsl(34, 50%, 33%);
2604+
--sidebar-resizer-active: hsl(34, 100%, 66%);
24902605
}
24912606

24922607
:root[data-theme="ayu"] h1,
@@ -2518,6 +2633,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
25182633
}
25192634

25202635
:root[data-theme="ayu"] .sidebar .current,
2636+
:root[data-theme="ayu"] .sidebar .current a,
25212637
:root[data-theme="ayu"] .sidebar a:hover,
25222638
:root[data-theme="ayu"] #src-sidebar div.files > a:hover,
25232639
:root[data-theme="ayu"] details.dir-entry summary:hover,
@@ -2568,7 +2684,8 @@ Original by Dempfi (https://github.com/dempfi/ayu)
25682684
border-bottom: 1px solid rgba(242, 151, 24, 0.3);
25692685
}
25702686

2571-
:root[data-theme="ayu"] #settings-menu > a img {
2687+
:root[data-theme="ayu"] #settings-menu > a img,
2688+
:root[data-theme="ayu"] #sidebar-button > a img {
25722689
filter: invert(100);
25732690
}
25742691
/* End theme: ayu */
Lines changed: 15 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)