|
1 | 1 | package com.demcha.compose.document.templates.cv.v2.widgets; |
2 | 2 |
|
3 | 3 | import com.demcha.compose.document.dsl.SectionBuilder; |
| 4 | +import com.demcha.compose.document.image.DocumentImageData; |
4 | 5 | import com.demcha.compose.document.node.DocumentLinkOptions; |
5 | 6 | import com.demcha.compose.document.node.InlineImageAlignment; |
6 | 7 | import com.demcha.compose.document.node.TextAlign; |
@@ -98,4 +99,49 @@ public static void render(SectionBuilder host, SvgGlyph glyph, |
98 | 99 | }); |
99 | 100 | }); |
100 | 101 | } |
| 102 | + |
| 103 | + /** |
| 104 | + * Renders an icon + text row from a pre-decoded raster glyph. |
| 105 | + * |
| 106 | + * <p>Public API retained for callers that supply their own raster |
| 107 | + * {@link DocumentImageData} icon. The bundled CV presets use the |
| 108 | + * recolorable {@link SvgGlyph} overload above; prefer it for new code.</p> |
| 109 | + * |
| 110 | + * @param host host section the row paragraph is appended to |
| 111 | + * @param icon glyph image payload (already decoded / cached by the |
| 112 | + * caller); when {@code null} the row renders text only |
| 113 | + * @param iconSize icon edge length in points (width == height) |
| 114 | + * @param text label text rendered after the icon |
| 115 | + * @param style text style for the label |
| 116 | + * @param link optional link wrapping the whole row (icon + label); |
| 117 | + * {@code null} renders a non-clickable row |
| 118 | + * @param margin paragraph margin (vertical rhythm between rows) |
| 119 | + */ |
| 120 | + public static void render(SectionBuilder host, DocumentImageData icon, |
| 121 | + double iconSize, String text, |
| 122 | + DocumentTextStyle style, DocumentLinkOptions link, |
| 123 | + DocumentInsets margin) { |
| 124 | + Objects.requireNonNull(host, "host"); |
| 125 | + Objects.requireNonNull(style, "style"); |
| 126 | + String label = text == null ? "" : text; |
| 127 | + DocumentInsets rowMargin = margin == null ? DocumentInsets.zero() : margin; |
| 128 | + |
| 129 | + host.addParagraph(paragraph -> { |
| 130 | + paragraph.textStyle(style) |
| 131 | + .align(TextAlign.LEFT) |
| 132 | + .link(link) |
| 133 | + .margin(rowMargin) |
| 134 | + .rich(rich -> { |
| 135 | + if (icon != null) { |
| 136 | + rich.image(icon, iconSize, iconSize, |
| 137 | + InlineImageAlignment.CENTER, 0.0, link); |
| 138 | + } |
| 139 | + if (link != null) { |
| 140 | + rich.link(GAP + label, link); |
| 141 | + } else { |
| 142 | + rich.style(GAP + label, style); |
| 143 | + } |
| 144 | + }); |
| 145 | + }); |
| 146 | + } |
101 | 147 | } |
0 commit comments