Created by marc on 8/8/14.
| 18 | * Created by marc on 8/8/14. |
| 19 | */ |
| 20 | public class StatusBar extends Box { |
| 21 | |
| 22 | static public Dict.Prop<StatusBar> statusBar = new Dict.Prop<StatusBar>("statusBar").type() |
| 23 | .toCanon() |
| 24 | .doc("The status-bar plugin"); |
| 25 | static public Dict.Prop<IdempotencyMap<Supplier<String>>> statuses = new Dict.Prop<>("statuses").type() |
| 26 | .toCanon() |
| 27 | .autoConstructs(() -> new IdempotencyMap<>(Supplier.class)) |
| 28 | .doc("Add things here to the status bar, and call `_.statusBar.update()` to update/repaint"); |
| 29 | int insetW = 0; |
| 30 | int insetH = 0; |
| 31 | int height = 25; |
| 32 | |
| 33 | public StatusBar(Box b) { |
| 34 | |
| 35 | this.properties.put(Planes.plane, "__always__"); |
| 36 | this.properties.put(statusBar, this); |
| 37 | |
| 38 | this.properties.putToMap(Boxes.insideRunLoop, "main.__updateStatusBarWidth__", () -> { |
| 39 | |
| 40 | Optional<FieldBoxWindow> window = find(Boxes.window, both()).findFirst(); |
| 41 | if (window.isPresent()) { |
| 42 | this.properties.put(frame, new Rect(0, window.get().getHeight() - height, window.get().getWidth(), height)); |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | }); |
| 48 | |
| 49 | this.properties.put(Drawing.windowSpace, new Vec2(0, 1)); |
| 50 | this.properties.put(Drawing.windowScale, new Vec2(1, 1)); |
| 51 | |
| 52 | this.properties.put(Box.frame, new Rect(0, 0, 10, height)); |
| 53 | |
| 54 | this.properties.putToMap(FLineDrawing.frameDrawing, "__name__", new Cached<Box, Object, FLine>((box, previously) -> { |
| 55 | Rect rect = box.properties.get(frame); |
| 56 | if (rect == null) return null; |
| 57 | |
| 58 | FLine f = new FLine(); |
| 59 | f.moveTo(rect.x + rect.w / 2, rect.y + rect.h / 2 + 25 / 5.0f); |
| 60 | |
| 61 | f.attributes.put(hasText, true); |
| 62 | f.attributes.put(color, new Vec4(1, 1, 1, 0.25f)); |
| 63 | List<String> spans = Arrays.asList(statusText().split(" ")); |
| 64 | f.nodes.get(f.nodes.size() - 1).attributes.put(textSpans, spans); |
| 65 | List<Vec4> colors = new ArrayList<>(); |
| 66 | for (int i = 0; i < spans.size(); i++) { |
| 67 | if (i % 2 == 0) |
| 68 | colors.add(new Vec4(1, 0.9, 0.8, 0.3f)); |
| 69 | else |
| 70 | colors.add(new Vec4(1, 0.9, 0.8, 0.4f)); |
| 71 | } |
| 72 | f.nodes.get(f.nodes.size() - 1).attributes.put(textColorSpans, colors); |
| 73 | return f; |
| 74 | }, (box) -> new Pair(box.properties.get(frame), statusText()))); |
| 75 | |
| 76 | this.properties.putToMap(FLineDrawing.frameDrawing, "__background", new Cached<Box, Object, FLine>((box, previously) -> { |
| 77 | Rect rect = box.properties.get(frame); |
nothing calls this directly
no test coverage detected