protected Group createIface () {
final BoxPointWidget position = new BoxPointWidget("Position");
final BoxPointWidget origin = new BoxPointWidget("Origin");
final Slider width = new Slider(50, 10, 150);
final Slider height = new Slider(50, 10, 150);
Group sizeCtrl = new Group(AxisLayout.horizontal()).add(new Label("Size:"), width, height);
final Group group = new Group(new AbsoluteLayout());
group.layer.add(PlayN.graphics().createImmediateLayer(new ImmediateLayer.Renderer() {
Point pt = new Point();
@Override public void render (Surface surface) {
IDimension size = group.size();
position.point.get().resolve(size, pt);
surface.save();
surface.setFillColor(Colors.BLACK);
surface.fillRect(pt.x - 2, pt.y - 2, 5, 5);
surface.restore();
}
}).setDepth(1));
group.addStyles(Style.BACKGROUND.is(Background.solid(Colors.WHITE)));
final Group widget = new Group(AxisLayout.horizontal()).addStyles(
Style.BACKGROUND.is(Background.solid(Colors.CYAN)));
group.add(widget);
UnitSlot updateConstraint = new UnitSlot() {
@Override public void onEmit () {
widget.setConstraint(new AbsoluteLayout.Constraint(
position.point.get(), origin.point.get(),
new Dimension(width.value.get(), height.value.get())));
}
};
width.value.connect(updateConstraint);
height.value.connect(updateConstraint);
position.point.connect(updateConstraint);
origin.point.connect(updateConstraint);
updateConstraint.onEmit();
return new Group(AxisLayout.vertical().offStretch()).add(
new Label("Move the sliders to play with the constraint"),
new Group(AxisLayout.horizontal()).add(position, origin),
sizeCtrl, group.setConstraint(AxisLayout.stretched()));
}