Skip to content

Commit a7dce51

Browse files
committed
use css classes for colors, number down to 6
1 parent 88c202c commit a7dce51

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/librustdoc/html/render/print_item.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ struct NotableTraitBadgeVars {
5858
full_path: String,
5959
/// Relative URL to the trait page, or `None` when not linkable.
6060
href: Option<String>,
61-
/// Pre-rendered `style="..."` attribute.
62-
style_attr: String,
61+
/// Index of the `.notable-trait-badge-{n}` color class.
62+
color_index: u64,
6363
}
6464

6565
#[derive(Template)]
@@ -132,15 +132,13 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item) -> impl fmt::Disp
132132
// This won't be stable between releases though.
133133
let mut h = DefaultHasher::new();
134134
info.full_path.hash(&mut h);
135-
// Evenly-spaced OKLCH hues at fixed light/chroma.
136-
const BADGE_HUES: u64 = 8;
137-
let hue = (h.finish() % BADGE_HUES) * 360 / BADGE_HUES;
138-
let style_attr = format!("style=\"background: oklch(0.55 0.21 {hue})\"");
135+
const BADGE_COLORS: u64 = 6;
136+
let color_index = h.finish() % BADGE_COLORS;
139137
NotableTraitBadgeVars {
140138
name: info.name,
141139
full_path: info.full_path,
142140
href: info.href,
143-
style_attr,
141+
color_index,
144142
}
145143
})
146144
.collect();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,13 @@ so that we can apply CSS-filters to change the arrow color in themes */
16671667
color: white;
16681668
}
16691669

1670+
.notable-trait-badge-0 { background: oklch(0.55 0.21 0); }
1671+
.notable-trait-badge-1 { background: oklch(0.55 0.21 60); }
1672+
.notable-trait-badge-2 { background: oklch(0.55 0.21 120); }
1673+
.notable-trait-badge-3 { background: oklch(0.55 0.21 180); }
1674+
.notable-trait-badge-4 { background: oklch(0.55 0.21 240); }
1675+
.notable-trait-badge-5 { background: oklch(0.55 0.21 300); }
1676+
16701677
.rightside {
16711678
padding-left: 12px;
16721679
float: right;

src/librustdoc/html/templates/print_item.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ <h1>
2323
{% if !notable_trait_badges.is_empty() %}
2424
<div class="notable-trait-badge-container">
2525
{% for badge in notable_trait_badges.iter() %}
26-
<a class="notable-trait-badge" {# #} {% if let Some(href) = badge.href
27-
%}href="{{href|safe}}" {% endif %} {#+ #} title="{{badge.full_path}}" {#+ #}
28-
{{badge.style_attr|safe}}>{{badge.name}}</a>
26+
<a class="notable-trait-badge notable-trait-badge-{{badge.color_index}}" {# #}
27+
{% if let Some(href) = badge.href %}href="{{href|safe}}" {% endif %} {#+ #}
28+
title="{{badge.full_path}}">{{badge.name}}</a>
2929
{% endfor %}
3030
</div>
3131
{% endif %}

0 commit comments

Comments
 (0)