This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HorizontalCollapsibleWidget support. Close #51.
- Loading branch information
Showing
11 changed files
with
150 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
examples/gdx-lml-vis-tests/assets/templates/examples/vis/horizontalCollapsibleWidget.lml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...hub/czyzby/lml/vis/parser/impl/attribute/collapsible/HorizontalCollapsedLmlAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ain/java/com/github/czyzby/lml/vis/parser/impl/tag/HorizontalCollapsibleWidgetLmlTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ub/czyzby/lml/vis/parser/impl/tag/provider/HorizontalCollapsibleWidgetLmlTagProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |