Skip to content

Commit bda659e

Browse files
Rollup merge of rust-lang#98460 - GuillaumeGomez:css-simplification, r=jsha
Use CSS variables to handle theming This is the start for our simplification of theming. Considering how big the diff quickly becomes, I think it's better to do it in multiple parts. (The 3 first commits come from rust-lang#98297 so once it's merged, they'll disappear). Normally they shouldn't be any UI changes. You can check it [here](https://rustdoc.crud.net/imperio/css-simplification/doc/foo/index.html). cc `@notriddle` r? `@jsha`
2 parents 01aa10c + 7f6ce7d commit bda659e

File tree

4 files changed

+73
-216
lines changed

4 files changed

+73
-216
lines changed

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

+55-5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ body {
114114
-webkit-font-feature-settings: "kern", "liga";
115115
-moz-font-feature-settings: "kern", "liga";
116116
font-feature-settings: "kern", "liga";
117+
118+
background-color: var(--main-background-color);
119+
color: var(--main-color);
117120
}
118121

119122
h1 {
@@ -214,6 +217,26 @@ a.srclink,
214217
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
215218
}
216219

220+
h1, h2, h3, h4,
221+
a#toggle-all-docs,
222+
a.anchor,
223+
.small-section-header a,
224+
#source-sidebar a,
225+
pre.rust a,
226+
.sidebar h2 a,
227+
.sidebar h3 a,
228+
.mobile-topbar h2 a,
229+
.in-band a,
230+
.search-results a,
231+
.module-item .stab,
232+
.import-item .stab,
233+
.result-name .primitive > i, .result-name .keyword > i,
234+
.content .method .where,
235+
.content .fn .where,
236+
.content .where.fmt-newline {
237+
color: var(--main-color);
238+
}
239+
217240
ol, ul {
218241
padding-left: 24px;
219242
}
@@ -391,6 +414,14 @@ nav.sub {
391414
display: none;
392415
}
393416

417+
.source .sidebar, #sidebar-toggle, #source-sidebar {
418+
background-color: var(--sidebar-background-color);
419+
}
420+
421+
#sidebar-toggle:hover {
422+
background-color: var(--sidebar-background-color-hover);
423+
}
424+
394425
.source .sidebar > *:not(#sidebar-toggle) {
395426
opacity: 0;
396427
visibility: hidden;
@@ -629,11 +660,6 @@ h2.location a {
629660
display: block;
630661
}
631662

632-
.invisible {
633-
width: 100%;
634-
display: inline-block;
635-
}
636-
637663
.content .in-band {
638664
flex-grow: 1;
639665
margin: 0px;
@@ -1008,6 +1034,11 @@ table,
10081034
top: -5px;
10091035
}
10101036

1037+
.popover, .popover::before {
1038+
background-color: var(--main-background-color);
1039+
color: var(--main-color);
1040+
}
1041+
10111042
#help-button .popover {
10121043
max-width: 600px;
10131044
}
@@ -1428,6 +1459,25 @@ pre.rust {
14281459
animation: rotating 2s linear infinite;
14291460
}
14301461

1462+
.setting-line .radio-line input:checked {
1463+
box-shadow: inset 0 0 0 3px var(--main-background-color);
1464+
background-color: var(--settings-input-color);
1465+
}
1466+
.setting-line .radio-line input:focus {
1467+
box-shadow: 0 0 1px 1px var(--settings-input-color);
1468+
}
1469+
/* In here we combine both `:focus` and `:checked` properties. */
1470+
.setting-line .radio-line input:checked:focus {
1471+
box-shadow: inset 0 0 0 3px var(--main-background-color),
1472+
0 0 2px 2px var(--settings-input-color);
1473+
}
1474+
.setting-line .radio-line input:hover {
1475+
border-color: var(--settings-input-color) !important;
1476+
}
1477+
input:checked + .slider {
1478+
background-color: var(--settings-input-color);
1479+
}
1480+
14311481
#help-button > button {
14321482
font-family: "Fira Sans", Arial, sans-serif;
14331483
text-align: center;

src/librustdoc/html/static/css/themes/ayu.css

+6-61
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,12 @@ Based off of the Ayu theme
33
Original by Dempfi (https://github.com/dempfi/ayu)
44
*/
55

6-
/* General structure and fonts */
7-
8-
body, .popover, .popover::before {
9-
background-color: #0f1419;
10-
color: #c5c5c5;
11-
}
12-
13-
.setting-line .radio-line input {
14-
border-color: #c5c5c5;
15-
}
16-
.setting-line .radio-line input:checked {
17-
box-shadow: inset 0 0 0 3px #0f1419;
18-
background-color: #ffb454;
19-
}
20-
.setting-line .radio-line input:focus {
21-
box-shadow: 0 0 1px 1px #ffb454;
22-
}
23-
/* In here we combine both `:focus` and `:checked` properties. */
24-
.setting-line .radio-line input:checked:focus {
25-
box-shadow: inset 0 0 0 3px 0f1419,
26-
0 0 2px 2px #ffb454;
27-
}
28-
.setting-line .radio-line input:hover {
29-
border-color: #ffb454 !important;
6+
:root {
7+
--main-background-color: #0f1419;
8+
--main-color: #c5c5c5;
9+
--settings-input-color: #ffb454;
10+
--sidebar-background-color: #14191f;
11+
--sidebar-background-color-hover: rgba(70, 70, 70, 0.33);
3012
}
3113

3214
.slider {
@@ -35,9 +17,6 @@ body, .popover, .popover::before {
3517
.slider:before {
3618
background-color: white;
3719
}
38-
input:checked + .slider {
39-
background-color: #ffb454;
40-
}
4120
input:focus + .slider {
4221
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
4322
}
@@ -62,10 +41,6 @@ h4 {
6241
background-color: #0f1419;
6342
}
6443

65-
.invisible {
66-
background: rgba(0, 0, 0, 0);
67-
}
68-
6944
.docblock code {
7045
color: #ffb454;
7146
}
@@ -129,10 +104,6 @@ pre, .rustdoc.source .example-wrap {
129104
color: #ffb44c;
130105
}
131106

132-
.source .sidebar {
133-
background-color: #14191f;
134-
}
135-
136107
.sidebar-elems .location {
137108
color: #ff7733;
138109
}
@@ -153,12 +124,6 @@ pre, .rustdoc.source .example-wrap {
153124
border-color: #5c6773;
154125
}
155126

156-
.content .method .where,
157-
.content .fn .where,
158-
.content .where.fmt-newline {
159-
color: #c5c5c5;
160-
}
161-
162127
.search-results a:hover {
163128
background-color: #777;
164129
}
@@ -233,17 +198,6 @@ a {
233198
color: #39AFD7;
234199
}
235200

236-
a#toggle-all-docs,
237-
a.anchor,
238-
.small-section-header a,
239-
#source-sidebar a,
240-
pre.rust a,
241-
.sidebar h2 a,
242-
.sidebar h3 a,
243-
.mobile-topbar h2 a,
244-
.in-band a {
245-
color: #c5c5c5;
246-
}
247201
.sidebar h2 a,
248202
.sidebar h3 a {
249203
color: white;
@@ -617,15 +571,6 @@ kbd {
617571
color: #999;
618572
}
619573

620-
#sidebar-toggle {
621-
background-color: #14191f;
622-
}
623-
#sidebar-toggle:hover {
624-
background-color: rgba(70, 70, 70, 0.33);
625-
}
626-
#source-sidebar {
627-
background-color: #14191f;
628-
}
629574
#source-sidebar > .title {
630575
color: #fff;
631576
border-bottom-color: #5c6773;

src/librustdoc/html/static/css/themes/dark.css

+6-74
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
body, .popover, .popover::before {
2-
background-color: #353535;
3-
color: #ddd;
4-
}
5-
6-
.setting-line .radio-line input {
7-
border-color: #ddd;
8-
}
9-
.setting-line .radio-line input:checked {
10-
box-shadow: inset 0 0 0 3px #353535;
11-
background-color: #2196f3;
12-
}
13-
.setting-line .radio-line input:focus {
14-
box-shadow: 0 0 1px 1px #2196f3;
15-
}
16-
/* In here we combine both `:focus` and `:checked` properties. */
17-
.setting-line .radio-line input:checked:focus {
18-
box-shadow: inset 0 0 0 3px #353535,
19-
0 0 2px 2px #2196f3;
20-
}
21-
.setting-line .radio-line input:hover {
22-
border-color: #2196f3 !important;
1+
:root {
2+
--main-background-color: #353535;
3+
--main-color: #ddd;
4+
--settings-input-color: #2196f3;
5+
--sidebar-background-color: #565656;
6+
--sidebar-background-color-hover: #676767;
237
}
248

259
.slider {
@@ -28,16 +12,10 @@ body, .popover, .popover::before {
2812
.slider:before {
2913
background-color: white;
3014
}
31-
input:checked + .slider {
32-
background-color: #2196F3;
33-
}
3415
input:focus + .slider {
3516
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
3617
}
3718

38-
h1, h2, h3, h4 {
39-
color: #ddd;
40-
}
4119
h1.fqn {
4220
border-bottom-color: #d2d2d2;
4321
}
@@ -49,10 +27,6 @@ h2, h3, h4 {
4927
background-color: #353535;
5028
}
5129

52-
.invisible {
53-
background: rgba(0, 0, 0, 0);
54-
}
55-
5630
.docblock code, .docblock-short code {
5731
background-color: #2A2A2A;
5832
}
@@ -98,10 +72,6 @@ pre, .rustdoc.source .example-wrap {
9872
background: #444;
9973
}
10074

101-
.source .sidebar {
102-
background-color: #565656;
103-
}
104-
10575
.line-numbers span { color: #3B91E2; }
10676
.line-numbers .line-highlighted {
10777
background-color: #0a042f !important;
@@ -115,12 +85,6 @@ pre, .rustdoc.source .example-wrap {
11585
border-color: #ddd;
11686
}
11787

118-
.content .method .where,
119-
.content .fn .where,
120-
.content .where.fmt-newline {
121-
color: #ddd;
122-
}
123-
12488
.search-results a:hover {
12589
background-color: #777;
12690
}
@@ -214,20 +178,6 @@ a {
214178
color: #D2991D;
215179
}
216180

217-
a#toggle-all-docs,
218-
a.anchor,
219-
.small-section-header a,
220-
#source-sidebar a,
221-
pre.rust a,
222-
.sidebar h2 a,
223-
.sidebar h3 a,
224-
.mobile-topbar h2 a,
225-
.in-band a {
226-
color: #ddd;
227-
}
228-
.search-results a {
229-
color: #ddd;
230-
}
231181
a.test-arrow {
232182
color: #dedede;
233183
}
@@ -261,11 +211,6 @@ details.undocumented > summary::before {
261211
border-color: #008dfd;
262212
}
263213

264-
.module-item .stab,
265-
.import-item .stab {
266-
color: #ddd;
267-
}
268-
269214
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
270215
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
271216
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; }
@@ -291,10 +236,6 @@ details.undocumented > summary::before {
291236
color: grey;
292237
}
293238

294-
.result-name .primitive > i, .result-name .keyword > i {
295-
color: #ddd;
296-
}
297-
298239
.line-numbers :target { background-color: transparent; }
299240

300241
/* Code highlighting */
@@ -488,15 +429,6 @@ kbd {
488429
color: #ccc;
489430
}
490431

491-
#sidebar-toggle {
492-
background-color: #565656;
493-
}
494-
#sidebar-toggle:hover {
495-
background-color: #676767;
496-
}
497-
#source-sidebar {
498-
background-color: #565656;
499-
}
500432
#source-sidebar > .title {
501433
border-bottom-color: #ccc;
502434
}

0 commit comments

Comments
 (0)