badge_maker/render/renderers/styles/
flat.rs1use crate::badge::Badge;
2
3use crate::render::base::BaseConfig;
4use crate::render::font::Font;
5use crate::render::renderers::{render_badge, RenderBadgeConfig};
6use crate::render::{BadgeRenderer, FONT_FAMILY};
7
8pub struct Flat {}
9
10impl BadgeRenderer for Flat {
11 fn font_family(&self) -> &'static str {
12 FONT_FAMILY
13 }
14
15 fn font(&self) -> Font {
16 Font::Verdana11Px
17 }
18
19 fn height(&self) -> usize {
20 20
21 }
22
23 fn vertical_margin(&self) -> isize {
24 0
25 }
26
27 fn shadow(&self) -> bool {
28 true
29 }
30
31 fn render(badge: &Badge) -> String {
32 let renderer = Self {};
33
34 let config = BaseConfig::new(badge, &renderer);
35
36 let body = format!(
37 r##"<linearGradient id="{s}" x2="0" y2="100%">
38 <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
39 <stop offset="1" stop-opacity=".1"/>
40 </linearGradient>
41 <clipPath id="{r}">
42 <rect width="{width}" height="{height}" rx="3" fill="#fff"/>
43 </clipPath>
44 <g clip-path="url(#{r})">
45 <rect width="{left_width}" height="{height}" fill="{label_color}"/>
46 <rect x="{left_width}" width="{right_width}" height="{height}" fill="{color}"/>
47 <rect width="{width}" height="{height}" fill="url(#{s})"/>
48 </g>
49 <g fill="#fff" text-anchor="middle" {font_family} text-rendering="geometricPrecision" font-size="110">
50 {rendered_logo}{rendered_label}{rendered_message}
51 </g>"##,
52 left_width = config.left_width,
53 right_width = config.right_width,
54 width = config.width,
55 rendered_label = config.rendered_label,
56 rendered_message = config.rendered_message,
57 font_family = renderer.font_family(),
58 height = renderer.height(),
59 label_color = config.label_color,
60 color = config.color,
61 rendered_logo = config.rendered_logo,
62 s = badge.ids(),
63 r = badge.idr()
64 );
65 render_badge(
66 RenderBadgeConfig {
67 left_width: config.left_width,
68 right_width: config.right_width,
69 height: renderer.height(),
70 accessible_text: &config.accessible_text,
71 links: &config.links,
72 },
73 &body,
74 )
75 }
76}