use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle in project libgdx by libgdx.
the class SelectBox method layout.
@Override
public void layout() {
Drawable bg = style.background;
BitmapFont font = style.font;
if (bg != null) {
prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight());
} else
prefHeight = font.getCapHeight() - font.getDescent() * 2;
float maxItemWidth = 0;
Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
GlyphLayout layout = layoutPool.obtain();
for (int i = 0; i < items.size; i++) {
layout.setText(font, toString(items.get(i)));
maxItemWidth = Math.max(layout.width, maxItemWidth);
}
layoutPool.free(layout);
prefWidth = maxItemWidth;
if (bg != null)
prefWidth += bg.getLeftWidth() + bg.getRightWidth();
ListStyle listStyle = style.listStyle;
ScrollPaneStyle scrollStyle = style.scrollStyle;
float listWidth = maxItemWidth + listStyle.selection.getLeftWidth() + listStyle.selection.getRightWidth();
if (scrollStyle.background != null)
listWidth += scrollStyle.background.getLeftWidth() + scrollStyle.background.getRightWidth();
if (selectBoxList == null || !selectBoxList.disableY)
listWidth += Math.max(style.scrollStyle.vScroll != null ? style.scrollStyle.vScroll.getMinWidth() : 0, style.scrollStyle.vScrollKnob != null ? style.scrollStyle.vScrollKnob.getMinWidth() : 0);
prefWidth = Math.max(prefWidth, listWidth);
}
use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle in project skin-composer by raeleus.
the class RootTable method refreshPreview.
public void refreshPreview() {
if (previewTable != null) {
previewTable.clear();
previewTable.setBackground("white");
previewTable.setColor((Color) previewProperties.get("bgcolor"));
for (BitmapFont font : previewFonts) {
font.dispose();
}
if (classSelectBox.getSelectedIndex() >= 0 && classSelectBox.getSelectedIndex() < Main.BASIC_CLASSES.length) {
StyleData styleData = getSelectedStyle();
Class clazz = Main.BASIC_CLASSES[classSelectBox.getSelectedIndex()];
if (!styleData.hasMandatoryFields()) {
Label label;
if (clazz.equals(SelectBox.class)) {
label = new Label("Please fill all mandatory fields\n(Highlighted on the left)\n\nscrollStyle and listStyle\nmust already be defined", getSkin());
} else if (clazz.equals(TextTooltip.class)) {
label = new Label("Please fill all mandatory fields\n(Highlighted on the left)\n\nlabel must already be defined", getSkin());
} else {
label = new Label("Please fill all mandatory fields\n(Highlighted on the left)", getSkin());
}
label.setAlignment(Align.center);
previewTable.add(label);
} else if (styleData.hasAllNullFields()) {
Label label;
label = new Label("All fields are empty!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
label.setAlignment(Align.center);
previewTable.add(label);
} else {
Actor widget = null;
if (clazz.equals(Button.class)) {
Button.ButtonStyle style = createPreviewStyle(Button.ButtonStyle.class, styleData);
widget = new Button(style);
((Button) widget).setDisabled((boolean) previewProperties.get("disabled"));
widget.addListener(main.getHandListener());
} else if (clazz.equals(CheckBox.class)) {
CheckBox.CheckBoxStyle style = createPreviewStyle(CheckBox.CheckBoxStyle.class, styleData);
widget = new CheckBox("", style);
((CheckBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
((CheckBox) widget).setText((String) previewProperties.get("text"));
widget.addListener(main.getHandListener());
} else if (clazz.equals(ImageButton.class)) {
ImageButtonStyle style = createPreviewStyle(ImageButtonStyle.class, styleData);
widget = new ImageButton(style);
((ImageButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
widget.addListener(main.getHandListener());
} else if (clazz.equals(ImageTextButton.class)) {
ImageTextButton.ImageTextButtonStyle style = createPreviewStyle(ImageTextButton.ImageTextButtonStyle.class, styleData);
widget = new ImageTextButton("", style);
((ImageTextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
((ImageTextButton) widget).setText((String) previewProperties.get("text"));
widget.addListener(main.getHandListener());
} else if (clazz.equals(Label.class)) {
LabelStyle style = createPreviewStyle(LabelStyle.class, styleData);
widget = new Label("", style);
((Label) widget).setText((String) previewProperties.get("text"));
} else if (clazz.equals(List.class)) {
ListStyle style = createPreviewStyle(ListStyle.class, styleData);
widget = new List(style);
Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
((List) widget).setItems(items);
widget.addListener(main.getHandListener());
} else if (clazz.equals(ProgressBar.class)) {
ProgressBar.ProgressBarStyle style = createPreviewStyle(ProgressBar.ProgressBarStyle.class, styleData);
widget = new ProgressBar((float) (double) previewProperties.get("minimum"), (float) (double) previewProperties.get("maximum"), (float) (double) previewProperties.get("increment"), (boolean) previewProperties.get("orientation"), style);
((ProgressBar) widget).setValue((float) (double) previewProperties.get("value"));
((ProgressBar) widget).setDisabled((boolean) previewProperties.get("disabled"));
} else if (clazz.equals(ScrollPane.class)) {
ScrollPaneStyle style = createPreviewStyle(ScrollPaneStyle.class, styleData);
Label label = new Label("", getSkin());
widget = new ScrollPane(label, style);
((ScrollPane) widget).setScrollbarsOnTop((boolean) previewProperties.get("scrollbarsOnTop"));
((ScrollPane) widget).setScrollBarPositions((boolean) previewProperties.get("hScrollBarPosition"), (boolean) previewProperties.get("vScrollBarPosition"));
((ScrollPane) widget).setScrollingDisabled((boolean) previewProperties.get("hScrollDisabled"), (boolean) previewProperties.get("vScrollDisabled"));
((ScrollPane) widget).setForceScroll((boolean) previewProperties.get("forceHscroll"), (boolean) previewProperties.get("forceVscroll"));
((ScrollPane) widget).setVariableSizeKnobs((boolean) previewProperties.get("variableSizeKnobs"));
((ScrollPane) widget).setOverscroll((boolean) previewProperties.get("hOverscroll"), (boolean) previewProperties.get("vOverscroll"));
((ScrollPane) widget).setFadeScrollBars((boolean) previewProperties.get("fadeScroll"));
((ScrollPane) widget).setSmoothScrolling((boolean) previewProperties.get("smoothScroll"));
((ScrollPane) widget).setFlickScroll((boolean) previewProperties.get("flickScroll"));
((ScrollPane) widget).setClamp((boolean) previewProperties.get("clamp"));
label.setText((String) previewProperties.get("text"));
} else if (clazz.equals(SelectBox.class)) {
SelectBox.SelectBoxStyle style = createPreviewStyle(SelectBox.SelectBoxStyle.class, styleData);
widget = new SelectBox(style);
((SelectBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
((SelectBox) widget).setItems(items);
widget.addListener(main.getHandListener());
((SelectBox) widget).getList().addListener(main.getHandListener());
} else if (clazz.equals(Slider.class)) {
Slider.SliderStyle style = createPreviewStyle(Slider.SliderStyle.class, styleData);
widget = new Slider((float) (double) previewProperties.get("minimum"), (float) (double) previewProperties.get("maximum"), (float) (double) previewProperties.get("increment"), (boolean) previewProperties.get("orientation"), style);
((Slider) widget).setDisabled((boolean) previewProperties.get("disabled"));
widget.addListener(main.getHandListener());
} else if (clazz.equals(SplitPane.class)) {
SplitPane.SplitPaneStyle style = createPreviewStyle(SplitPane.SplitPaneStyle.class, styleData);
Label label1 = new Label("", getSkin());
Label label2 = new Label("", getSkin());
widget = new SplitPane(label1, label2, (boolean) previewProperties.get("orientation"), style);
label1.setText((String) previewProperties.get("text"));
label2.setText((String) previewProperties.get("text"));
if ((boolean) previewProperties.get("orientation")) {
widget.addListener(vSplitPaneDragListener);
widget.addListener(vSplitPaneInputListener);
} else {
widget.addListener(hSplitPaneDragListener);
widget.addListener(hSplitPaneInputListener);
}
} else if (clazz.equals(TextButton.class)) {
TextButtonStyle style = createPreviewStyle(TextButtonStyle.class, styleData);
widget = new TextButton("", style);
((TextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
((TextButton) widget).setText((String) previewProperties.get("text"));
widget.addListener(main.getHandListener());
} else if (clazz.equals(TextField.class)) {
TextFieldStyle style = createPreviewStyle(TextFieldStyle.class, styleData);
widget = new TextField("", style);
((TextField) widget).setFocusTraversal(false);
((TextField) widget).setDisabled((boolean) previewProperties.get("disabled"));
((TextField) widget).setPasswordMode((boolean) previewProperties.get("passwordMode"));
((TextField) widget).setAlignment((int) previewProperties.get("alignment"));
((TextField) widget).setText((String) previewProperties.get("text"));
((TextField) widget).setMessageText((String) previewProperties.get("message"));
String string = (String) previewProperties.get("password");
if (string.length() > 0) {
((TextField) widget).setPasswordCharacter(string.charAt(0));
}
widget.addListener(main.getIbeamListener());
} else if (clazz.equals(TextTooltip.class)) {
TextTooltip.TextTooltipStyle style = createPreviewStyle(TextTooltip.TextTooltipStyle.class, styleData);
TooltipManager manager = new TooltipManager();
manager.animations = false;
manager.initialTime = 0.0f;
manager.resetTime = 0.0f;
manager.subsequentTime = 0.0f;
manager.hideAll();
manager.instant();
TextTooltip toolTip = new TextTooltip((String) previewProperties.get("text"), manager, style);
widget = new Label("Hover over me", getSkin());
widget.addListener(toolTip);
} else if (clazz.equals(Touchpad.class)) {
Touchpad.TouchpadStyle style = createPreviewStyle(Touchpad.TouchpadStyle.class, styleData);
widget = new Touchpad(0, style);
widget.addListener(main.getHandListener());
} else if (clazz.equals(Tree.class)) {
Tree.TreeStyle style = createPreviewStyle(Tree.TreeStyle.class, styleData);
widget = new Tree(style);
String[] lines = { "this", "is", "a", "test" };
Tree.Node parentNode = null;
for (String line : lines) {
Label label = new Label(line, getSkin());
Tree.Node node = new Tree.Node(label);
if (parentNode == null) {
((Tree) widget).add(node);
} else {
parentNode.add(node);
}
parentNode = node;
}
widget.addListener(main.getHandListener());
} else if (clazz.equals(Window.class)) {
Window.WindowStyle style = createPreviewStyle(Window.WindowStyle.class, styleData);
if (style.stageBackground != null) {
previewTable.setBackground(style.stageBackground);
previewTable.setColor(Color.WHITE);
style.stageBackground = null;
}
Label sampleText = new Label("", getSkin());
sampleText.setText((String) previewProperties.get("text"));
widget = new Window((String) previewProperties.get("title"), style);
((Window) widget).add(sampleText);
}
if (widget != null) {
switch((int) previewProperties.get("size")) {
case (0):
previewTable.add(widget).size(10.0f);
previewSizeSelectBox.setItems(DEFAULT_SIZES);
break;
case (1):
previewTable.add(widget);
previewSizeSelectBox.setItems(DEFAULT_SIZES);
break;
case (2):
previewTable.add(widget).size(200.0f);
previewSizeSelectBox.setItems(DEFAULT_SIZES);
break;
case (3):
previewTable.add(widget).growX();
previewSizeSelectBox.setItems(DEFAULT_SIZES);
break;
case (4):
previewTable.add(widget).growY();
previewSizeSelectBox.setItems(DEFAULT_SIZES);
break;
case (5):
previewTable.add(widget).grow();
previewSizeSelectBox.setItems(DEFAULT_SIZES);
break;
case (6):
Actor addWidget = widget;
TraversalTextField widthField = new TraversalTextField("", getSkin());
TraversalTextField heightField = new TraversalTextField("", getSkin());
widthField.setNextFocus(heightField);
heightField.setNextFocus(widthField);
Dialog dialog = new Dialog("Enter dimensions...", getSkin()) {
@Override
protected void result(Object object) {
if ((boolean) object) {
previewTable.add(addWidget).size(Integer.parseInt(widthField.getText()), Integer.parseInt(heightField.getText()));
Array<String> items = new Array<>(DEFAULT_SIZES);
items.add(widthField.getText() + "x" + heightField.getText());
previewProperties.put("sizeX", Integer.parseInt(widthField.getText()));
previewProperties.put("sizeY", Integer.parseInt(heightField.getText()));
previewSizeSelectBox.setItems(items);
previewSizeSelectBox.setSelectedIndex(7);
} else {
previewSizeSelectBox.setSelectedIndex(1);
}
}
};
dialog.getTitleTable().getCells().first().padLeft(5.0f);
dialog.text("Enter the preview dimensions: ");
dialog.getContentTable().getCells().first().pad(10.0f);
dialog.getContentTable().row();
Table sizeTable = new Table();
sizeTable.add(widthField).padLeft(10.0f);
sizeTable.add(new Label(" x ", getSkin()));
sizeTable.add(heightField).padRight(10.0f);
dialog.getContentTable().add(sizeTable);
dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
dialog.button("OK", true);
dialog.button("Cancel", false);
TextButton okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor();
okButton.setDisabled(true);
okButton.addListener(main.getHandListener());
widthField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
okButton.setDisabled(!widthField.getText().matches("^\\d+$") || !heightField.getText().matches("^\\d+$"));
}
});
heightField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
okButton.setDisabled(!widthField.getText().matches("^\\d+$") || !heightField.getText().matches("^\\d+$"));
}
});
dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
dialog.key(Input.Keys.ESCAPE, false);
dialog.show(stage);
stage.setKeyboardFocus(widthField);
break;
case (7):
previewTable.add(widget).size((int) previewProperties.get("sizeX"), (int) previewProperties.get("sizeY"));
break;
}
}
}
} else {
CustomStyle customStyle = (CustomStyle) styleSelectBox.getSelected();
boolean showMessage = true;
if (customStyle.getProperties().size == 0) {
Label label = new Label("No style properties!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
label.setAlignment(0);
previewTable.add(label);
} else {
for (CustomProperty customProperty : customStyle.getProperties()) {
if (customProperty.getValue() != null && !(customProperty.getValue() instanceof String) || customProperty.getValue() != null && !((String) customProperty.getValue()).equals("")) {
showMessage = false;
break;
}
}
if (showMessage) {
Label label = new Label("All properties are empty!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
label.setAlignment(0);
previewTable.add(label);
}
}
if (!showMessage) {
HorizontalGroup horizontalGroup = new HorizontalGroup();
horizontalGroup.wrap();
// the following causes a crash. LibGDX bug.
// horizontalGroup.space(10.0f);
horizontalGroup.wrapSpace(10.0f);
horizontalGroup.setTouchable(Touchable.disabled);
previewTable.add(horizontalGroup).grow().pad(10.0f);
for (CustomProperty customProperty : customStyle.getProperties()) {
if (customProperty.getValue() != null) {
Container container = new Container();
container.pad(5.0f);
horizontalGroup.addActor(container);
switch(customProperty.getType()) {
case TEXT:
case RAW_TEXT:
Label labelText = new Label((String) customProperty.getValue(), getSkin());
container.setActor(labelText);
break;
case NUMBER:
Label labelNumber = new Label(Double.toString((double) customProperty.getValue()), getSkin());
container.setActor(labelNumber);
break;
case BOOL:
Label labelBoolean = new Label(Boolean.toString((boolean) customProperty.getValue()), getSkin());
container.setActor(labelBoolean);
break;
case COLOR:
ColorData colorData = null;
String colorName = (String) customProperty.getValue();
for (ColorData cd : main.getJsonData().getColors()) {
if (cd.getName().equals(colorName)) {
colorData = cd;
break;
}
}
if (colorData != null) {
Table colorTable = new Table(getSkin());
colorTable.setBackground("white");
colorTable.setColor(colorData.color);
colorTable.add().size(25.0f);
container.setActor(colorTable);
}
break;
case FONT:
BitmapFont font = null;
FontData fontData = null;
String fontName = (String) customProperty.getValue();
for (FontData fd : main.getJsonData().getFonts()) {
if (fd.getName().equals(fontName)) {
fontData = fd;
font = new BitmapFont(fd.file);
previewFonts.add(font);
break;
}
}
if (font != null) {
Label labelFont = new Label(fontData.getName(), new LabelStyle(font, Color.WHITE));
container.setActor(labelFont);
}
FreeTypeFontData freeTypeFontData = null;
for (FreeTypeFontData fd : main.getJsonData().getFreeTypeFonts()) {
if (fd.name.equals(fontName)) {
freeTypeFontData = fd;
break;
}
}
if (freeTypeFontData.bitmapFont != null) {
Label labelFont = new Label(freeTypeFontData.name, new LabelStyle(freeTypeFontData.bitmapFont, Color.WHITE));
container.setActor(labelFont);
}
break;
case DRAWABLE:
DrawableData drawable = null;
String drawableName = (String) customProperty.getValue();
for (DrawableData dd : main.getAtlasData().getDrawables()) {
if (dd.name.equals(drawableName)) {
drawable = dd;
break;
}
}
if (drawable != null) {
Image image = new Image(drawablePairs.get(drawable.name));
container.setActor(image);
}
break;
}
}
}
}
}
}
}
use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle in project skin-composer by raeleus.
the class RootTable method createPreviewStyle.
private <T> T createPreviewStyle(Class<T> clazz, StyleData styleData) {
T returnValue = null;
try {
returnValue = ClassReflection.newInstance(clazz);
Field[] fields = ClassReflection.getFields(clazz);
for (Field field : fields) {
Object value = styleData.properties.get(field.getName()).value;
if (value != null) {
if (field.getType().equals(Drawable.class)) {
field.set(returnValue, drawablePairs.get((String) value));
} else if (field.getType().equals(Color.class)) {
for (ColorData data : main.getProjectData().getJsonData().getColors()) {
if (value.equals(data.getName())) {
field.set(returnValue, data.color);
break;
}
}
} else if (field.getType().equals(BitmapFont.class)) {
for (FontData data : main.getProjectData().getJsonData().getFonts()) {
if (value.equals(data.getName())) {
BitmapFont font = new BitmapFont(data.file);
previewFonts.add(font);
field.set(returnValue, font);
}
}
for (FreeTypeFontData data : main.getJsonData().getFreeTypeFonts()) {
if (value.equals(data.name)) {
field.set(returnValue, data.bitmapFont);
}
}
} else if (field.getType().equals(Float.TYPE)) {
field.set(returnValue, (float) value);
} else if (field.getType().equals(ListStyle.class)) {
Array<StyleData> datas = main.getProjectData().getJsonData().getClassStyleMap().get(List.class);
for (StyleData data : datas) {
if (value.equals(data.name)) {
ListStyle style = createPreviewStyle(ListStyle.class, data);
field.set(returnValue, style);
break;
}
}
} else if (field.getType().equals(ScrollPaneStyle.class)) {
Array<StyleData> datas = main.getProjectData().getJsonData().getClassStyleMap().get(ScrollPane.class);
for (StyleData data : datas) {
if (value.equals(data.name)) {
ScrollPaneStyle style = createPreviewStyle(ScrollPaneStyle.class, data);
field.set(returnValue, style);
break;
}
}
} else if (field.getType().equals(LabelStyle.class)) {
Array<StyleData> datas = main.getProjectData().getJsonData().getClassStyleMap().get(Label.class);
for (StyleData data : datas) {
if (value.equals(data.name)) {
LabelStyle style = createPreviewStyle(LabelStyle.class, data);
field.set(returnValue, style);
break;
}
}
}
}
}
} finally {
return returnValue;
}
}
use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle in project bladecoder-adventure-engine by bladecoder.
the class FilteredSelectBox method layout.
@Override
public void layout() {
Drawable bg = style.background;
BitmapFont font = style.font;
if (bg != null) {
prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight());
} else
prefHeight = font.getCapHeight() - font.getDescent() * 2;
float maxItemWidth = 0;
Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
GlyphLayout layout = layoutPool.obtain();
for (int i = 0; i < items.size; i++) {
layout.setText(font, toString(items.get(i)));
maxItemWidth = Math.max(layout.width, maxItemWidth);
}
layoutPool.free(layout);
prefWidth = maxItemWidth;
if (bg != null)
prefWidth += bg.getLeftWidth() + bg.getRightWidth();
ListStyle listStyle = style.listStyle;
ScrollPaneStyle scrollStyle = style.scrollStyle;
float listWidth = maxItemWidth + listStyle.selection.getLeftWidth() + listStyle.selection.getRightWidth();
if (scrollStyle.background != null)
listWidth += scrollStyle.background.getLeftWidth() + scrollStyle.background.getRightWidth();
if (selectBoxList == null || !selectBoxList.isScrollingDisabledY())
listWidth += Math.max(style.scrollStyle.vScroll != null ? style.scrollStyle.vScroll.getMinWidth() : 0, style.scrollStyle.vScrollKnob != null ? style.scrollStyle.vScrollKnob.getMinWidth() : 0);
prefWidth = Math.max(prefWidth, listWidth);
}
use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle in project var3dframe by Var3D.
the class VGame method getSelectBox.
@SuppressWarnings("rawtypes")
public <T> UI<VSelectBox> getSelectBox(String titlebg) {
UI<VSelectBox> ui = new UI<VSelectBox>(this);
SelectBoxStyle style = new SelectBoxStyle();
style.fontColor = Color.BLACK;
style.background = getDrawable(titlebg);
style.font = getFont();
style.scrollStyle = new ScrollPaneStyle(getRectColorDrawable(1, 1, new Color(0.4f, 0.4f, 0.4f, 0.6f)), null, null, null, null);
style.listStyle = new ListStyle(getFont(), Color.BROWN, Color.WHITE, getRectColorDrawable(1, 1, new Color(1, 1, 0, 0.3f)));
VSelectBox select = new VSelectBox(style);
ui.setActor(select);
return ui;
}
Aggregations