MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / Typing

Method Typing

src/main/java/fieldbox/boxes/plugins/Typing.java:30–129  ·  view source on GitHub ↗
(Box root)

Source from the content-addressed store, hash-verified

28 boolean listening = false;
29
30 public Typing(Box root) {
31 this.root = root;
32 this.properties.put(FLineDrawing.layer, "glass2");
33 this.properties.putToMap(FLineDrawing.frameDrawing, "__currenttext__", new Cached<Box, Object, FLine>((b, was) -> {
34 FLine f = new FLine();
35
36 if (ct == null) return f;
37 if (!listening) return f;
38
39 Optional<Rect> v = getViewRect();
40 if (!v.isPresent()) return f;
41
42 Rect r = v.get();
43
44 f.attributes.put(StandardFLineDrawing.font, "source-code-pro-regular-92.fnt");
45 f.attributes.put(FLineDrawing.layer, "glass2");
46 f.attributes.put(StandardFLineDrawing.hasText, true);
47 f.moveTo(r.x + r.w / 2, r.y + r.h / 2 + 14);
48 f.last().attributes.put(StandardFLineDrawing.textScale, 8f);
49 f.attributes.put(StandardFLineDrawing.fillColor, new Vec4(1, 1, 1, 1));
50 f.last().attributes.put(StandardFLineDrawing.text, ">"+ct);
51
52 return f;
53 }, b -> {
54 return new Pair<>(listening+ct, getViewRect());
55 }));
56
57 this.properties.putToMap(FLineDrawing.frameDrawing, "__currenttextBack__", new Cached<Box, Object, FLine>((b, was) -> {
58 FLine f = new FLine();
59
60 if (ct == null) return f;
61 if (!listening) return f;
62
63 Optional<Rect> v = getViewRect();
64 if (!v.isPresent()) return f;
65
66 Rect r = v.get();
67
68 f.attributes.put(FLineDrawing.layer, "glass2");
69 f.rect(r.x + r.w / 2 - 20, r.y + r.h / 2 + 14 - 20, 40, 40);
70 f.attributes.put(StandardFLineDrawing.fillColor, new Vec4(0,0,0,0.2));
71 f.attributes.put(StandardFLineDrawing.filled, true);
72 f.attributes.put(StandardFLineDrawing.stroked, true);
73
74 return f;
75 }, b -> {
76 return new Pair<>(listening+ct, getViewRect());
77 }));
78
79 this.properties.putToMap(Keyboard.onCharTyped, "__typing__", (e, v) -> {
80
81 if (e.properties.isTrue(Window.consumed, false)) return;
82
83 if (listening) {
84 ct += v;
85 Drawing.dirty(this);
86 e.properties.put(Window.consumed, true);
87 } else {

Callers

nothing calls this directly

Calls 12

getViewRectMethod · 0.95
moveToMethod · 0.95
lastMethod · 0.95
rectMethod · 0.95
dirtyMethod · 0.95
goMethod · 0.95
putToMapMethod · 0.80
isPresentMethod · 0.80
isTrueMethod · 0.80
getMethod · 0.65
putMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected