Skip to content

Commit 82110ca

Browse files
Rollup merge of #136950 - notriddle:notriddle/svg-example-buttons, r=GuillaumeGomez
rustdoc: use better, consistent SVG icons for scraped examples ## Screenshots ![](https://github.com/user-attachments/assets/f305fb20-5ded-428a-b0d0-04e8b7762769) ![](https://github.com/user-attachments/assets/5b9bee5e-74b9-447b-a19a-49f32b6bf218) ![image](https://github.com/user-attachments/assets/d855a8c8-dc24-44f9-a067-1e0f0654c28a) ![image](https://github.com/user-attachments/assets/71bca54a-0562-480a-8989-938acc351307) ## Description This continues two ongoing projects - Replacing ascii art with real icons that don't look like syntax, are understandable to people who're familiar with desktop computers and smart devices, and aren't ugly. - Using labels and tooltips to clarify these icons, when the limits of popular iconography hit us. In this case, I've added tooltips, because, unfortunately, there's not room for always-visible labels. r? ``@GuillaumeGomez``
2 parents 9f87de6 + 2c4922c commit 82110ca

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

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

+42-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
4141
--font-family: "Source Serif 4", NanumBarunGothic, serif;
4242
--font-family-code: "Source Code Pro", monospace;
4343
--line-number-padding: 4px;
44+
/* scraped examples icons (34x33px) */
45+
--prev-arrow-image: url('data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" \
46+
enable-background="new 0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path fill="none" \
47+
d="M8,3l-4,5l4,5m-4,-5h10" stroke="black" stroke-width="2"/></svg>');
48+
--next-arrow-image: url('data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" \
49+
enable-background="new 0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path fill="none" \
50+
d="M8,3l4,5l-4,5m4,-5h-10" stroke="black" stroke-width="2"/></svg>');
51+
--expand-arrow-image: url('data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" \
52+
enable-background="new 0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path fill="none" \
53+
d="M3,10l4,4l4,-4m-4,4M3,7l4,-4l4,4" stroke="black" stroke-width="2"/></svg>');
54+
--collapse-arrow-image: url('data:image/svg+xml,<svg width="16" height="16" viewBox="0 0 16 16" \
55+
enable-background="new 0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path fill="none" \
56+
d="M3,8l4,4l4,-4m-4,4M3,4l4,4l4,-4" stroke="black" stroke-width="2"/></svg>');
4457
}
4558

4659
:root.sans-serif {
@@ -1729,7 +1742,10 @@ instead, we check that it's not a "finger" cursor.
17291742
padding: 2px 0 0 4px;
17301743
}
17311744
.example-wrap .button-holder .copy-button::before,
1732-
.example-wrap .test-arrow::before {
1745+
.example-wrap .test-arrow::before,
1746+
.example-wrap .button-holder .prev::before,
1747+
.example-wrap .button-holder .next::before,
1748+
.example-wrap .button-holder .expand::before {
17331749
filter: var(--copy-path-img-filter);
17341750
}
17351751
.example-wrap .button-holder .copy-button::before {
@@ -1744,6 +1760,24 @@ instead, we check that it's not a "finger" cursor.
17441760
padding-right: 5px;
17451761
}
17461762

1763+
.example-wrap .button-holder .prev,
1764+
.example-wrap .button-holder .next,
1765+
.example-wrap .button-holder .expand {
1766+
line-height: 0px;
1767+
}
1768+
.example-wrap .button-holder .prev::before {
1769+
content: var(--prev-arrow-image);
1770+
}
1771+
.example-wrap .button-holder .next::before {
1772+
content: var(--next-arrow-image);
1773+
}
1774+
.example-wrap .button-holder .expand::before {
1775+
content: var(--expand-arrow-image);
1776+
}
1777+
.example-wrap .button-holder .expand.collapse::before {
1778+
content: var(--collapse-arrow-image);
1779+
}
1780+
17471781
.code-attribute {
17481782
font-weight: 300;
17491783
color: var(--code-attribute-color);
@@ -2012,6 +2046,13 @@ button#toggle-all-docs:before {
20122046
filter: var(--settings-menu-filter);
20132047
}
20142048

2049+
button#toggle-all-docs.will-expand:before {
2050+
/* Custom arrow icon */
2051+
content: url('data:image/svg+xml,<svg width="18" height="18" viewBox="0 0 12 12" \
2052+
enable-background="new 0 0 12 12" xmlns="http://www.w3.org/2000/svg">\
2053+
<path d="M2,5l4,-4l4,4M2,7l4,4l4,-4" stroke="black" fill="none" stroke-width="2px"/></svg>');
2054+
}
2055+
20152056
#help-button > a:before {
20162057
/* Question mark with circle */
20172058
content: url('data:image/svg+xml,<svg width="18" height="18" viewBox="0 0 12 12" \

src/librustdoc/html/static/js/scrape-examples.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
function createScrapeButton(parent, className, content) {
4343
const button = document.createElement("button");
4444
button.className = className;
45-
button.innerText = content;
45+
button.title = content;
4646
parent.insertBefore(button, parent.firstChild);
4747
return button;
4848
}
@@ -54,14 +54,14 @@
5454
let expandButton = null;
5555

5656
if (!example.classList.contains("expanded")) {
57-
expandButton = createScrapeButton(buttonHolder, "expand", "");
57+
expandButton = createScrapeButton(buttonHolder, "expand", "Show all");
5858
}
5959
const isHidden = example.parentElement.classList.contains("more-scraped-examples");
6060

6161
const locs = example.locs;
6262
if (locs.length > 1) {
63-
const next = createScrapeButton(buttonHolder, "next", "");
64-
const prev = createScrapeButton(buttonHolder, "prev", "");
63+
const next = createScrapeButton(buttonHolder, "next", "Next usage");
64+
const prev = createScrapeButton(buttonHolder, "prev", "Previous usage");
6565

6666
// Toggle through list of examples in a given file
6767
const onChangeLoc = changeIndex => {
@@ -94,9 +94,13 @@
9494
expandButton.addEventListener("click", () => {
9595
if (hasClass(example, "expanded")) {
9696
removeClass(example, "expanded");
97+
removeClass(expandButton, "collapse");
98+
expandButton.title = "Show all";
9799
scrollToLoc(example, locs[0][0], isHidden);
98100
} else {
99101
addClass(example, "expanded");
102+
addClass(expandButton, "collapse");
103+
expandButton.title = "Show single example";
100104
}
101105
});
102106
}

tests/rustdoc-gui/scrape-examples-button-focus.goml

+26
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,29 @@ press-key: "Enter"
1919
assert-property: (".scraped-example-list > .scraped-example .rust", {
2020
"scrollTop": |initialScrollTop|
2121
}, NEAR)
22+
23+
// Make sure all the buttons are the same size
24+
store-property: (".scraped-example-list > .scraped-example .prev", {
25+
"offsetWidth": buttonWidth,
26+
"offsetHeight": buttonHeight,
27+
})
28+
assert-property: (".scraped-example-list > .scraped-example .prev", {
29+
"offsetWidth": |buttonWidth|,
30+
"offsetHeight": |buttonHeight|,
31+
"title": "Previous usage",
32+
})
33+
assert-property: (".scraped-example-list > .scraped-example .next", {
34+
"offsetWidth": |buttonWidth|,
35+
"offsetHeight": |buttonHeight|,
36+
"title": "Next usage",
37+
})
38+
assert-property: (".scraped-example-list > .scraped-example .expand", {
39+
"offsetWidth": |buttonWidth|,
40+
"offsetHeight": |buttonHeight|,
41+
"title": "Show all",
42+
})
43+
assert-property: (".scraped-example-list > .scraped-example .copy-button", {
44+
"offsetWidth": |buttonWidth|,
45+
"offsetHeight": |buttonHeight|,
46+
"title": "Copy code to clipboard",
47+
})

0 commit comments

Comments
 (0)