A Box that draws itself in a particular way, and drags it's children around with them
| 20 | * A Box that draws itself in a particular way, and drags it's children around with them |
| 21 | */ |
| 22 | public class BoxGroup extends Box implements IO.Loaded { |
| 23 | |
| 24 | static public Dict.Prop<Boolean> _collapsed = new Dict.Prop<>("collapsed").type().doc("is this group collapsed?"); |
| 25 | |
| 26 | static { |
| 27 | IO.persist(_collapsed); |
| 28 | } |
| 29 | |
| 30 | public BoxGroup() { |
| 31 | |
| 32 | this.properties.put(Planes.plane, "__always__"); |
| 33 | |
| 34 | this.properties.putToMap(Mouse.onDoubleClick, "doubleClickMe", (e) -> { |
| 35 | if (properties.get(Box.frame).intersects(new Vec2(e.after.mx, e.after.my))) |
| 36 | properties.put(_collapsed, !properties.isTrue(_collapsed, false)); |
| 37 | }); |
| 38 | this.properties.putToMap(Boxes.insideRunLoop, "main.__checkforcollapsed__", () -> { |
| 39 | if (this.properties.isTrue(_collapsed, false) != isCollapsed()) { |
| 40 | if (this.properties.isTrue(_collapsed, false)) collapse(); |
| 41 | else expand(); |
| 42 | } |
| 43 | return true; |
| 44 | }); |
| 45 | |
| 46 | addCachedLine("__outline__", this::drawFrame); |
| 47 | addCachedLine("__outline2__", this::drawName); |
| 48 | addCachedLine("__outline2b__", this::drawNameBottom); |
| 49 | addCachedLine("__outline3a__", this::drawFrameTop); |
| 50 | |
| 51 | |
| 52 | this.properties.putToMap(Commands.command, "Isolate contents of group", (k) -> { |
| 53 | isolateContents(); |
| 54 | return null; |
| 55 | }); |
| 56 | this.properties.putToMap(Commands.commandDoc, "Isolate contents of group", |
| 57 | "Make sure that the contents of this group are not connected to the root of the box graph directly. This will then allow you to collapse and expand this this group. All connections from the contents of the group will go through this group box. "); |
| 58 | |
| 59 | this.properties.putToMap(Commands.commandGuard, "Isolate contents of group", (k) -> !isContentsIsolated()); |
| 60 | |
| 61 | this.properties.putToMap(Commands.command, "Collapse group", (k) -> { |
| 62 | collapse(); |
| 63 | return null; |
| 64 | }); |
| 65 | |
| 66 | |
| 67 | this.properties.putToMap(Commands.command, "Integrate contents of group", (k) -> { |
| 68 | integrateContents(); |
| 69 | return null; |
| 70 | }); |
| 71 | this.properties.putToMap(Commands.commandDoc, "Integrate contents of group", |
| 72 | "Make sure that the contents of this group are also directly connected to the root of the box graph. This means, if you delete the group, the boxes remain connected. "); |
| 73 | |
| 74 | this.properties.putToMap(Commands.commandGuard, "Integrate contents of group", (k) -> isContentsIsolated()); |
| 75 | |
| 76 | this.properties.putToMap(Commands.command, "Collapse group", (k) -> { |
| 77 | collapse(); |
| 78 | return null; |
| 79 | }); |