Skip to content

Commit 32af0b8

Browse files
authored
Unrolled build for rust-lang#140135
Rollup merge of rust-lang#140135 - GuillaumeGomez:sidebars-image, r=rustdoc Unify sidebar buttons to use the same image Part of rust-lang#139832. The source sidebar looks like this with the new image: ![image](https://github.com/user-attachments/assets/df4fee52-fb71-4794-91b7-3afc6d2aab70) You can test it [here](https://rustdoc.crud.net/imperio/sidebar-images/src/foo/foo.rs.html). r? `@notriddle`
2 parents f5d3fe2 + f7d8558 commit 32af0b8

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.20.3
1+
0.20.6

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

+22-21
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
5555
--collapse-arrow-image: url('data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" \
5656
enable-background="new 0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path fill="none" \
5757
d="M3,8l4,4l4,-4m-4,4M3,4l4,4l4,-4" stroke="black" stroke-width="2"/></svg>');
58+
--hamburger-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" \
59+
viewBox="0 0 22 22" fill="none" stroke="black">\
60+
<path d="M3,5h16M3,11h16M3,17h16" stroke-width="2.75"/></svg>');
5861
}
5962

6063
:root.sans-serif {
@@ -2001,9 +2004,11 @@ a.tooltip:hover::after {
20012004
display: flex;
20022005
margin-right: 4px;
20032006
position: fixed;
2004-
left: 6px;
20052007
height: 34px;
20062008
width: 34px;
2009+
}
2010+
.hide-sidebar #sidebar-button {
2011+
left: 6px;
20072012
background-color: var(--main-background-color);
20082013
z-index: 1;
20092014
}
@@ -2019,6 +2024,8 @@ a.tooltip:hover::after {
20192024
align-items: center;
20202025
justify-content: center;
20212026
flex-direction: column;
2027+
}
2028+
#settings-menu > a, #help-button > a, button#toggle-all-docs {
20222029
border: 1px solid transparent;
20232030
border-radius: var(--button-border-radius);
20242031
color: var(--main-color);
@@ -2031,14 +2038,15 @@ a.tooltip:hover::after {
20312038
min-width: 0;
20322039
}
20332040
#sidebar-button > a {
2034-
background-color: var(--button-background-color);
2035-
border-color: var(--border-color);
2041+
background-color: var(--sidebar-background-color);
20362042
width: 33px;
20372043
}
2044+
#sidebar-button > a:hover, #sidebar-button > a:focus-visible {
2045+
background-color: var(--main-background-color);
2046+
}
20382047

20392048
#settings-menu > a:hover, #settings-menu > a:focus-visible,
20402049
#help-button > a:hover, #help-button > a:focus-visible,
2041-
#sidebar-button > a:hover, #sidebar-button > a:focus-visible,
20422050
button#toggle-all-docs:hover, button#toggle-all-docs:focus-visible {
20432051
border-color: var(--settings-button-border-focus);
20442052
text-decoration: none;
@@ -2405,28 +2413,16 @@ However, it's not needed with smaller screen width because the doc/code block is
24052413
use hamburger button */
24062414
.src #sidebar-button > a::before, .sidebar-menu-toggle::before {
24072415
/* hamburger button image */
2408-
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" \
2409-
viewBox="0 0 22 22" fill="none" stroke="black">\
2410-
<path d="M3,5h16M3,11h16M3,17h16" stroke-width="2.75"/></svg>');
2416+
content: var(--hamburger-image);
24112417
opacity: 0.75;
2418+
filter: var(--mobile-sidebar-menu-filter);
24122419
}
24132420
.sidebar-menu-toggle:hover::before,
24142421
.sidebar-menu-toggle:active::before,
24152422
.sidebar-menu-toggle:focus::before {
24162423
opacity: 1;
24172424
}
24182425

2419-
/* src sidebar button opens a folder view */
2420-
.src #sidebar-button > a::before {
2421-
/* folder image */
2422-
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" \
2423-
viewBox="0 0 22 22" fill="none" stroke="black">\
2424-
<path d="M16,9v-4h-6v-1l-2,-2h-4l-2,2v16h13L21,9h-15L2,19" stroke-width="1.25"/>\
2425-
<path d="M15,7h-11v3" stroke-width="0.75"/>\
2426-
<path d="M3.75,10v1.25" stroke-width="0.375"/></svg>');
2427-
opacity: 0.75;
2428-
}
2429-
24302426
/* Media Queries */
24312427

24322428
/* Make sure all the buttons line wrap at the same time */
@@ -2611,9 +2607,6 @@ in src-script.js and main.js
26112607
width: 22px;
26122608
height: 22px;
26132609
}
2614-
.sidebar-menu-toggle::before {
2615-
filter: var(--mobile-sidebar-menu-filter);
2616-
}
26172610
.sidebar-menu-toggle:hover {
26182611
background: var(--main-background-color);
26192612
}
@@ -2671,6 +2664,14 @@ in src-script.js and main.js
26712664
margin: 0 0 -25px 0;
26722665
padding: var(--nav-sub-mobile-padding);
26732666
}
2667+
2668+
html:not(.src-sidebar-expanded) .src #sidebar-button > a {
2669+
background-color: var(--main-background-color);
2670+
}
2671+
html:not(.src-sidebar-expanded) .src #sidebar-button > a:hover,
2672+
html:not(.src-sidebar-expanded) .src #sidebar-button > a:focus-visible {
2673+
background-color: var(--sidebar-background-color);
2674+
}
26742675
}
26752676

26762677

tests/rustdoc-gui/sidebar.goml

+36
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,42 @@ assert-position-false: (".sidebar-crate > h2 > a", {"x": -3})
199199
drag-and-drop: ((205, 100), (108, 100))
200200
assert-position: (".sidebar-crate > h2 > a", {"x": -3})
201201

202+
// Check that the mobile sidebar and the source sidebar use the same icon.
203+
store-css: (".mobile-topbar .sidebar-menu-toggle::before", {"content": image_url})
204+
// Then we go to a source page.
205+
click: ".main-heading .src"
206+
assert-css: ("#sidebar-button a::before", {"content": |image_url|})
207+
// Check that hover events work as expected.
208+
store-css: ("#sidebar-button a", {"background-color": sidebar_background})
209+
move-cursor-to: "#sidebar-button a"
210+
store-css: ("#sidebar-button a:hover", {"background-color": sidebar_background_hover})
211+
assert: |sidebar_background| != |sidebar_background_hover|
212+
click: "#sidebar-button a"
213+
wait-for: "html.src-sidebar-expanded"
214+
assert-css: ("#sidebar-button a:hover", {"background-color": |sidebar_background_hover|})
215+
move-cursor-to: "#settings-menu"
216+
assert-css: ("#sidebar-button a:not(:hover)", {"background-color": |sidebar_background|})
217+
// Closing sidebar.
218+
click: "#sidebar-button a"
219+
wait-for: "html:not(.src-sidebar-expanded)"
220+
// Now we check the same when the sidebar button is moved alongside the search.
221+
set-window-size: (500, 500)
222+
store-css: ("#sidebar-button a:hover", {"background-color": not_sidebar_background_hover})
223+
move-cursor-to: "#settings-menu"
224+
store-css: ("#sidebar-button a:not(:hover)", {"background-color": not_sidebar_background})
225+
// The sidebar background is supposed to be the same as the main background.
226+
assert-css: ("body", {"background-color": |not_sidebar_background|})
227+
assert: |not_sidebar_background| != |not_sidebar_background_hover| && |not_sidebar_background| != |sidebar_background|
228+
// The hover background is supposed to be the same as the sidebar background.
229+
assert: |not_sidebar_background_hover| == |sidebar_background|
230+
click: "#sidebar-button a"
231+
wait-for: "html.src-sidebar-expanded"
232+
// And now the background colors are supposed to be the same as the sidebar since the sidebar has
233+
// been open.
234+
assert-css: ("#sidebar-button a:hover", {"background-color": |sidebar_background_hover|})
235+
move-cursor-to: "h2"
236+
assert-css: ("#sidebar-button a:not(:hover)", {"background-color": |sidebar_background|})
237+
202238
// Configuration option to show TOC in sidebar.
203239
set-local-storage: {"rustdoc-hide-toc": "true"}
204240
go-to: "file://" + |DOC_PATH| + "/test_docs/enum.WhoLetTheDogOut.html"

0 commit comments

Comments
 (0)