@Override protected String title () {
return "UI: Scroller";
}
@Override protected Group createIface () {
final Slider width = new Slider(100, 100, 5000);
final Slider height = new Slider(100, 100, 5000);
final Slider xpos = new Slider(0, 0, 1);
final Slider ypos = new Slider(0, 0, 1);
final Content content = new Content();
final Scroller scroll = new Scroller(content);
final Label click = new Label();
// updates the size of the content
final UnitSlot updateSize = new UnitSlot() {
@Override public void onEmit () {
((Content)scroll.content).preferredSize.update(
width.value.get(), height.value.get());
}
};
width.value.connect(updateSize);
height.value.connect(updateSize);
// updates the scroll offset
UnitSlot updatePos = new UnitSlot() {
@Override public void onEmit () {
float x = xpos.value.get() * scroll.hrange.max();
float y = ypos.value.get() * scroll.vrange.max();
scroll.scroll(x, y);
}
};
xpos.value.connect(updatePos);
ypos.value.connect(updatePos);
Button beh = new Button(Behavior.BOTH.name()).onClick(new Slot<Button>() {
@Override public void onEmit (Button source) {
Behavior[] behs = Behavior.values();
Behavior beh = Behavior.valueOf(source.text.get());
beh = behs[(beh.ordinal() + 1) % behs.length];
scroll.setBehavior(beh);
source.text.update(beh.name());
xpos.setVisible(beh.hasHorizontal());
ypos.setVisible(beh.hasVertical());
updateSize.onEmit();
}
});
scroll.contentClicked().connect(new Slot<Pointer.Event>() {