if (menu != null) {
return menu;
}
String letters = "ABCDEFGHIJ";
menu = new Menu(AxisLayout.horizontal().offStretch(), Style.VALIGN.top);
Group g = new Group(new TableLayout(10));
g.setStylesheet(Stylesheet.builder().add(MenuItem.class, Styles.none().
add(Style.BACKGROUND.is(Background.blank().inset(5, 1))).
addSelected(Style.BACKGROUND.is(Background.solid(Colors.BLACK).inset(5, 1)))).
create());
for (int col = 0; col < 10; col++) {
for (int row = 0; row < 10; row++) {
g.add(new MenuItem(letters.substring(col, col+1) + (row + 1)));
}
}
return menu.add(g);
}
@Override public MenuHost.Pop makePop (Pointer.Event ev) {
return super.makePop(ev).retainMenu();
}
@Override protected void wasRemoved () {
super.wasRemoved();
if (menu != null) {
menu.layer.destroy();
}
}
};
TrackingLabel scrolled = new TrackingLabel(menuHost, "Bits \u25BC") {
@Override public Menu createMenu () {
final Menu menu = new Menu(AxisLayout.vertical().offStretch());
menu.add(new Label("Select a byte").addStyles(Style.COLOR.is(0xFFFFFFFF),
Style.BACKGROUND.is(Background.beveled(0xFF8F8F8F, 0xFF4F4F4F, 0xFFCFCFCF).
inset(4))));
Group items = new Group(AxisLayout.vertical());
Scroller scroller = new Scroller(items);
menu.add(new SizableGroup(AxisLayout.vertical().offStretch(), 0, 200).add(
scroller.setBehavior(Scroller.Behavior.VERTICAL).
setConstraint(AxisLayout.stretched())));
StringBuilder bits = new StringBuilder();
for (int ii = 0; ii < 256; ii++) {
bits.setLength(0);
for (int mask = 128; mask > 0; mask >>= 1) {
bits.append((ii & mask) != 0 ? 1 : 0);
}
items.add(new MenuItem(bits.toString()));
}
return menu;
}
};
TrackingLabel bytes = new TrackingLabel(menuHost, "Bytes \u25BC") {
final String HEX = "0123456789ABCDEF";
@Override public Menu createMenu () {
final PagedMenu menu = new PagedMenu(new TableLayout(2), 16);
menu.add(new Label("Select a byte").addStyles(Style.COLOR.is(0xFFFFFFFF),
Style.BACKGROUND.is(Background.beveled(0xFF8F8F8F, 0xFF4F4F4F, 0xFFCFCFCF).
inset(4))).setConstraint(new TableLayout.Colspan(2)));
final Button prev = new Button("<< Previous").onClick(menu.incrementPage(-1));
final Button next = new Button("Next >>").onClick(menu.incrementPage(1));
menu.add(prev, next);
UnitSlot updateEnabling = new UnitSlot() {
@Override public void onEmit () {
prev.setEnabled(menu.page().get() > 0);
next.setEnabled(menu.page().get() < menu.numPages().get() - 1);
}
};
menu.page().connect(updateEnabling);
menu.numPages().connect(updateEnabling);
int sel = -1;
for (int ii = 0; ii < 256; ii++) {
String hex = new StringBuilder("0x").
append(HEX.charAt((ii>>4)&0xf)).
append(HEX.charAt(ii&0xf)).toString();
if (text.get().startsWith(hex)) sel = ii;
menu.add(new MenuItem(hex));
}
if (sel != -1) menu.setPage(sel / menu.itemsPerPage);
updateEnabling.onEmit();
return menu;
}
};
TrackingLabel colors = new TrackingLabel(menuHost, "Colors \u25BC") {
@Override public Menu createMenu () {
final PagedMenu menu = new PagedMenu(AxisLayout.vertical(), 32);
final Slider slider = new Slider().setIncrement(1);
slider.value.connect(new Slot<Float>() {
@Override public void onEmit (Float val) {
menu.setPage(FloatMath.round(val));
}
});
menu.page().connect(new Slot<Integer>() {
@Override public void onEmit (Integer page) {
slider.value.update(page.floatValue());
}
});
menu.numPages().connect(new Slot<Integer>() {
@Override public void onEmit (Integer numPages) {
slider.range.update(new Slider.Range(0, numPages.intValue() - 1));
slider.setEnabled(numPages > 0);
}
});
Styles itemStyles = Styles.none().add(Style.Mode.SELECTED,
Style.BACKGROUND.is(Background.solid(Colors.BLUE).inset(2))).
add(Style.BACKGROUND.is(Background.blank().inset(2)));
Group colorTable = new Group(new TableLayout(4));
for (int ii = 0; ii < 256; ii++) {
CanvasImage colorImg = PlayN.graphics().createImage(16, 16);
colorImg.canvas().setFillColor(0xFF000000 | (ii << 16));
colorImg.canvas().fillRect(0, 0, 16, 16);
colorTable.add(new MenuItem("", Icons.image(colorImg)).addStyles(itemStyles));