From 8fcb4193b93c2994add4a4ff8eef4247157574ea Mon Sep 17 00:00:00 2001 From: oakes Date: Sat, 11 Jan 2014 14:58:02 -0500 Subject: [PATCH] Add horizontal and vertical groups --- src/play_clj/ui.clj | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/play_clj/ui.clj b/src/play_clj/ui.clj index 17314bb..7f6dd4e 100644 --- a/src/play_clj/ui.clj +++ b/src/play_clj/ui.clj @@ -4,8 +4,9 @@ [com.badlogic.gdx.graphics Color Texture] [com.badlogic.gdx.graphics.g2d BitmapFont TextureRegion] [com.badlogic.gdx.scenes.scene2d Actor Stage] - [com.badlogic.gdx.scenes.scene2d.ui ButtonGroup CheckBox Dialog Image - ImageButton ImageTextButton Label Skin Slider TextButton TextField] + [com.badlogic.gdx.scenes.scene2d.ui ButtonGroup CheckBox Dialog + HorizontalGroup Image ImageButton ImageTextButton Label Skin Slider + TextButton TextField VerticalGroup WidgetGroup] [com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener ChangeListener ClickListener DragListener FocusListener NinePatchDrawable SpriteDrawable TextureRegionDrawable @@ -116,6 +117,33 @@ [text arg & options] `(u/create-entity (u/calls! ^Dialog (dialog* ~text ~arg) ~@options))) +; groups + +(defn add-children + [^WidgetGroup group children] + (doseq [{:keys [object]} children] + (assert (isa? (type object) Actor)) + (.addActor group ^Actor object)) + group) + +(defn horizontal* + [children] + (add-children (HorizontalGroup.) children)) + +(defmacro horizontal + [children & options] + `(u/create-entity (u/calls! ^HorizontalGroup (horizontal* ~children) + ~@options))) + +(defn vertical* + [children] + (add-children (VerticalGroup.) children)) + +(defmacro vertical + [children & options] + `(u/create-entity (u/calls! ^VerticalGroup (vertical* ~children) + ~@options))) + ; listeners (defn ^:private gesture-listener