MCPcopy Create free account
hub / github.com/HumbleUI/Skija / TextLineScene

Class TextLineScene

examples/scenes/src/TextLineScene.java:10–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import io.github.humbleui.types.*;
9
10public class TextLineScene extends Scene {
11 private Paint fill = new Paint().setColor(0xFFCC3333);
12 private Paint blueFill = new Paint().setColor(0xFF3333CC);
13 private Paint selectionFill = new Paint().setColor(0x80b3d7ff);
14 private Paint stroke = new Paint().setColor(0x803333CC).setMode(PaintMode.STROKE).setStrokeWidth(1);
15 private Paint strokeRed = new Paint().setColor(0x80CC3333).setMode(PaintMode.STROKE).setStrokeWidth(1);
16 private Font inter9 = new Font(inter, 9).setSubpixel(true);
17 private Font inter36 = new Font(inter, 36);
18 private Font jbMono36 = new Font(jbMono, 36);
19 private Font zapfino18;
20 // private Font emoji36 = new Font(FontMgr.getDefault().matchFamilyStyleCharacter(null, FontStyle.NORMAL, null, "🧛".codePointAt(0)), 36);
21 public FontCollection fc = new FontCollection();
22
23 public TextLineScene() {
24 _variants = new String[] { "Set 1", "Set 2", "Set 3 Text Line", "Set 3 Paragraph" };
25 _variantIdx = 2;
26
27 fc.setDefaultFontManager(FontMgr.getDefault());
28 TypefaceFontProvider fm = new TypefaceFontProvider();
29 fm.registerTypeface(inter);
30 fm.registerTypeface(jbMono);
31 fc.setAssetFontManager(fm);
32
33 if ("Mac OS X".equals(System.getProperty("os.name"))) {
34 zapfino18 = new Font(FontMgr.getDefault().matchFamilyStyle("Zapfino", FontStyle.NORMAL), 18);
35 fm.registerTypeface(zapfino18.getTypeface());
36 }
37 }
38
39 public Point drawTable(Canvas canvas, String[] data) {
40 float leftWidth = 0;
41 float leftHeight = 0;
42 for (int i = 0; i < data.length; i += 2) {
43 try (var line = TextLine.make(data[i], inter9); ) {
44 canvas.drawTextLine(line, 0, leftHeight - line.getAscent(), blueFill);
45 leftWidth = Math.max(leftWidth, line.getWidth());
46 leftHeight += line.getHeight();
47 }
48 }
49
50 float rightWidth = 0;
51 float rightHeight = 0;
52 for (int i = 1; i < data.length; i += 2) {
53 try (var line = TextLine.make(data[i], inter9);) {
54 canvas.drawTextLine(line, leftWidth + 5, rightHeight - line.getAscent(), blueFill);
55 rightWidth = Math.max(rightWidth, line.getWidth());
56 rightHeight += line.getHeight();
57 }
58 }
59 return new Point(leftWidth + 5 + rightWidth, Math.max(leftHeight, rightHeight));
60 }
61
62 public float drawLine(Canvas canvas, String text, Font font, Point cursor) {
63 return drawLine(canvas, new String[] { text }, font, cursor);
64 }
65
66 public float drawLine(Canvas canvas, String[] texts, Font font, Point cursor) {
67 float bottom = 0;

Callers

nothing calls this directly

Calls 4

setStrokeWidthMethod · 0.80
setModeMethod · 0.80
setSubpixelMethod · 0.80
setColorMethod · 0.45

Tested by

no test coverage detected