Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Added HorizontalCollapsibleWidget support. Close #51.
Browse files Browse the repository at this point in the history
  • Loading branch information
czyzby committed Apr 2, 2017
1 parent 0fc9ae3 commit 91b5a87
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/gdx-lml-tests/assets/i18n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# main.lml
mainTitle=LML tests
mainSubtitle=by MJ, 2015-2016
mainSubtitle=by MJ, 2015-2017
textAreaPrompt=Enter LML text to parse or select an example.
parsingButton=Parse {0} document
toggleHighlight=Toggle syntax highlighting (might slow down templates rendering)
Expand Down
3 changes: 2 additions & 1 deletion examples/gdx-lml-vis-tests/assets/i18n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# main.lml
mainTitle=LML tests
mainSubtitle=by MJ & Kotcrab, 2015-2016
mainSubtitle=by MJ & Kotcrab, 2015-2017
textAreaPrompt=Enter LML text to parse or select an example.
parsingButton=Parse {0} document
toggleHighlight=Toggle syntax highlighting (might slow down templates rendering)
Expand Down Expand Up @@ -108,6 +108,7 @@ vis/formValidator=Vis: formValidator
vis/floatingGroup=Vis: floatingGroup
vis/gridGroup=Vis: gridGroup
vis/highlightTextArea=Vis: highlightTextArea
vis/horizontalCollapsibleWidget=Vis: horizontalCollapsible
vis/horizontalFlow=Vis: horizontalFlow
vis/linkLabel=Vis: linkLabel
vis/listView=Vis: listView
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- You can wrap any actor in horizontal collapsible
widget. -->

<textButton onChange="uncollapseAll">Show all.</textButton>

<horizontalCollapsible onClick="collapseHorizontal">
<textButton tablePad="24">Collapse me.</textButton>
</horizontalCollapsible>

<horizontalCollapsible onClick="collapseHorizontal" collapsed="true">
<container size="128">
<image style="icon-trash" />
</container>
</horizontalCollapsible>

<horizontalCollapsibleWidget onClick="collapseHorizontal">
Converted to label.
</horizontalCollapsibleWidget>

<!-- Collapsed status needs to be managed manually, but
since you can get a reference to collapsible widget
by its ID, you can easily modify it in Java. -->

<!-- Collapsible widgets can have only 1 child. -->
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ public class Main extends AbstractApplicationListener {
// Vis unique tags:
"vis/basicColorPicker", "vis/busyBar", "vis/collapsibleWidget", "vis/colorPicker", "vis/draggable",
"vis/dragPane", "vis/fixedSizeGridGroup", "vis/floatingGroup", "vis/formValidator", "vis/gridGroup",
"vis/highlightTextArea", "vis/horizontalFlow", "vis/linkLabel", "vis/listView", "vis/menu",
"vis/multiSplitPane", "vis/radioButton", "vis/scrollableTextArea", "vis/separator", "vis/spinner",
"vis/tabbedPane", "vis/toast", "vis/tooltip", "vis/validatableTextField", "vis/verticalFlow");
"vis/highlightTextArea", "vis/horizontalCollapsibleWidget", "vis/horizontalFlow", "vis/linkLabel",
"vis/listView", "vis/menu", "vis/multiSplitPane", "vis/radioButton", "vis/scrollableTextArea",
"vis/separator", "vis/spinner", "vis/tabbedPane", "vis/toast", "vis/tooltip", "vis/validatableTextField",
"vis/verticalFlow");
private static final String MAIN_VIEW_TEMPLATE = "templates/main.lml";

private MainView view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,19 @@ public void showAllCollapsedWidgets() {
for (final Actor actor : resultTable.getChildren()) {
if (actor instanceof CollapsibleWidget) {
((CollapsibleWidget) actor).setCollapsed(false);
} else if (actor instanceof HorizontalCollapsibleWidget) {
((HorizontalCollapsibleWidget) actor).setCollapsed(false);
}
}
}

/* templates/examples/vis/horizontalCollapsibleWidget.lml */

@LmlAction("collapseHorizontal")
public void toggleCollapsedStatus(final HorizontalCollapsibleWidget collapsibleWidget) {
collapsibleWidget.setCollapsed(!collapsibleWidget.isCollapsed());
}

/* templates/examples/vis/colorPicker.lml */

/** @param result result of a color picker dialog. Will become an actor's color. */
Expand Down
2 changes: 2 additions & 0 deletions lml-vis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Make sure to check `gdx-lml` changes as well!

- `showSelectionCheckboxes` attribute added to `FileChooser` tag.
- `disabled` attribute added to `Spinner` tag.
- `verticalCollapsible` alias added for `CollapsibleWidget` tag.
- `HorizontalCollapsibleWidget` tag support. Aliases: `horizontalCollapsible`, `horizontalCollapsibleWidget`, attributes: `collapse`, `collapsed` (boolean).

1.7 -> 1.8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.github.czyzby.lml.vis.parser.impl.attribute.button.ImageButtonGenerateDisabledLmlAttribute;
import com.github.czyzby.lml.vis.parser.impl.attribute.button.TextButtonImageLmlAttribute;
import com.github.czyzby.lml.vis.parser.impl.attribute.collapsible.CollapsedLmlAttribute;
import com.github.czyzby.lml.vis.parser.impl.attribute.collapsible.HorizontalCollapsedLmlAttribute;
import com.github.czyzby.lml.vis.parser.impl.attribute.draggable.BlockInputLmlAttribute;
import com.github.czyzby.lml.vis.parser.impl.attribute.draggable.DeadzoneRadiusLmlAttribute;
import com.github.czyzby.lml.vis.parser.impl.attribute.draggable.DragListenerLmlAttribute;
Expand Down Expand Up @@ -231,7 +232,8 @@ protected void registerActorTags() {
// Vis unique actors:
addTagProvider(new BasicColorPickerLmlTagProvider(), "basicColorPicker", "basicPicker");
addTagProvider(new BusyBarLmlTagProvider(), "busyBar");
addTagProvider(new CollapsibleWidgetLmlTagProvider(), "collapsible", "collapsibleWidget");
addTagProvider(new CollapsibleWidgetLmlTagProvider(), "collapsible", "verticalCollapsible",
"collapsibleWidget");
addTagProvider(new ColorPickerLmlTagProvider(), "colorPicker");
addTagProvider(new DraggableLmlTagProvider(), "drag", "draggable");
addTagProvider(new DragPaneLmlTagProvider(), "dragPane");
Expand All @@ -240,6 +242,8 @@ protected void registerActorTags() {
addTagProvider(new FormValidatorLmlTagProvider(), "form", "formValidator", "formTable");
addTagProvider(new GridGroupLmlTagProvider(), "gridGroup", "grid");
addTagProvider(new HighlightTextAreaLmlTagProvider(), "highlightTextArea");
addTagProvider(new HorizontalCollapsibleWidgetLmlTagProvider(), "horizontalCollapsible",
"horizontalCollapsibleWidget");
addTagProvider(new HorizontalFlowGroupLmlTagProvider(), "horizontalFlow", "horizontalFlowGroup");
addTagProvider(new LinkLabelLmlTagProvider(), "linkLabel", "link");
addTagProvider(new ListViewLmlTagProvider(), "listView");
Expand Down Expand Up @@ -426,6 +430,7 @@ protected void registerWindowAttributes() {
/** CollapsibleWidget attributes. */
protected void registerCollapsibleWidgetAttributes() {
addAttributeProcessor(new CollapsedLmlAttribute(), "collapse", "collapsed");
addAttributeProcessor(new HorizontalCollapsedLmlAttribute(), "collapse", "collapsed");
}

/** ColorPicker attributes. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.czyzby.lml.vis.parser.impl.attribute.collapsible;

import com.github.czyzby.lml.parser.LmlParser;
import com.github.czyzby.lml.parser.tag.LmlAttribute;
import com.github.czyzby.lml.parser.tag.LmlTag;
import com.kotcrab.vis.ui.widget.HorizontalCollapsibleWidget;

/** See {@link HorizontalCollapsibleWidget#setCollapsed(boolean, boolean)}. Invoked without collapsing animation.
* Mapped to "collapse", "collapsed".
*
* @author MJ */
public class HorizontalCollapsedLmlAttribute implements LmlAttribute<HorizontalCollapsibleWidget> {
@Override
public Class<HorizontalCollapsibleWidget> getHandledType() {
return HorizontalCollapsibleWidget.class;
}

@Override
public void process(final LmlParser parser, final LmlTag tag, final HorizontalCollapsibleWidget actor,
final String rawAttributeData) {
actor.setCollapsed(parser.parseBoolean(rawAttributeData, actor), false); // false - no animation.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/** Handles {@link CollapsibleWidget} actor. Can be used to manage one child. Converts text to a {@link Table} with a
* label child. If the child is not a table, will create an empty table and put the child actor in it. Mapped to
* "collapsible", "collapsibleWidget".
* "collapsible", "verticalCollapsible", "collapsibleWidget".
*
* @author MJ */
public class CollapsibleWidgetLmlTag extends AbstractActorLmlTag {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.github.czyzby.lml.vis.parser.impl.tag;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.github.czyzby.kiwi.util.gdx.collection.GdxArrays;
import com.github.czyzby.lml.parser.LmlParser;
import com.github.czyzby.lml.parser.impl.tag.AbstractActorLmlTag;
import com.github.czyzby.lml.parser.tag.LmlActorBuilder;
import com.github.czyzby.lml.parser.tag.LmlTag;
import com.kotcrab.vis.ui.widget.HorizontalCollapsibleWidget;
import com.kotcrab.vis.ui.widget.VisTable;

/** Handles {@link HorizontalCollapsibleWidget} actor. Can be used to manage one child. Converts text to a {@link Table}
* with a label child. If the child is not a table, will create an empty table and put the child actor in it. Mapped to
* "horizontalCollapsible", "horizontalCollapsibleWidget".
*
* @author MJ */
public class HorizontalCollapsibleWidgetLmlTag extends AbstractActorLmlTag {
public HorizontalCollapsibleWidgetLmlTag(final LmlParser parser, final LmlTag parentTag, final StringBuilder rawTagData) {
super(parser, parentTag, rawTagData);
}

@Override
protected Actor getNewInstanceOfActor(final LmlActorBuilder builder) {
return new HorizontalCollapsibleWidget();
}

@Override
protected void handlePlainTextLine(final String plainTextLine) {
addChild(wrapWithTable(toLabel(plainTextLine)));
}

/** @param actor will be put a table.
* @return a new table with 1 child. */
protected Table wrapWithTable(final Actor actor) {
final Table table = new VisTable();
table.add(actor);
return table;
}

@Override
protected void handleValidChild(final LmlTag childTag) {
if (childTag.getActor() instanceof Table) {
addChild((Table) childTag.getActor());
} else {
addChild(wrapWithTable(childTag.getActor()));
}
}

/** @param child will be set as collapsible's child. */
protected void addChild(final Table child) {
final HorizontalCollapsibleWidget container = getHorizontalCollapsibleWidget();
if (GdxArrays.isNotEmpty(container.getChildren())) {
getParser().throwErrorIfStrict("Horizontal collapsible widget can manage only one child.");
}
container.setTable(child);
}

/** @return casted actor. */
protected HorizontalCollapsibleWidget getHorizontalCollapsibleWidget() {
return (HorizontalCollapsibleWidget) getActor();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.czyzby.lml.vis.parser.impl.tag.provider;

import com.github.czyzby.lml.parser.LmlParser;
import com.github.czyzby.lml.parser.tag.LmlTag;
import com.github.czyzby.lml.parser.tag.LmlTagProvider;
import com.github.czyzby.lml.vis.parser.impl.tag.HorizontalCollapsibleWidgetLmlTag;

/** Provides Vis horizontal collapsible widget tags.
*
* @author MJ */
public class HorizontalCollapsibleWidgetLmlTagProvider implements LmlTagProvider {
@Override public LmlTag create(final LmlParser parser, final LmlTag parentTag, final StringBuilder rawTagData) {
return new HorizontalCollapsibleWidgetLmlTag(parser, parentTag, rawTagData);
}
}

0 comments on commit 91b5a87

Please sign in to comment.