Class MenuItem

  • All Implemented Interfaces:
    com.badlogic.gdx.scenes.scene2d.utils.Cullable, com.badlogic.gdx.scenes.scene2d.utils.Disableable, com.badlogic.gdx.scenes.scene2d.utils.Layout

    public class MenuItem
    extends com.badlogic.gdx.scenes.scene2d.ui.Button
    MenuItem contains text or text with icon. Best icon size is 22px. MenuItem can also have a hotkey text.

    When listening for menu item press ChangeListener should be always preferred (instead of ClickListener). ClickListener does not support disabling menu item and will still report item clicks.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  MenuItem.MenuItemStyle  
      • Nested classes/interfaces inherited from class com.badlogic.gdx.scenes.scene2d.ui.Button

        com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle
      • Nested classes/interfaces inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

        com.badlogic.gdx.scenes.scene2d.ui.Table.Debug, com.badlogic.gdx.scenes.scene2d.ui.Table.DebugRect
    • Field Summary

      • Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

        backgroundBottom, backgroundLeft, backgroundRight, backgroundTop, debugActorColor, debugCellColor, debugTableColor
    • Constructor Summary

      Constructors 
      Constructor Description
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.ui.Image image)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.ui.Image image, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener changeListener)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.ui.Image image, MenuItem.MenuItemStyle style)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.ui.Image image, java.lang.String styleName)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener changeListener)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener changeListener)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable, MenuItem.MenuItemStyle style)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable, java.lang.String styleName)  
      MenuItem​(java.lang.String text, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, java.lang.String styleName)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)  
      com.badlogic.gdx.scenes.scene2d.ui.Image getImage()  
      com.badlogic.gdx.scenes.scene2d.ui.Cell<?> getImageCell()  
      com.badlogic.gdx.scenes.scene2d.ui.Label getLabel()  
      com.badlogic.gdx.scenes.scene2d.ui.Cell<?> getLabelCell()  
      java.lang.CharSequence getShortcut()  
      com.badlogic.gdx.scenes.scene2d.ui.Cell<com.badlogic.gdx.scenes.scene2d.ui.Label> getShortcutCell()  
      MenuItem.MenuItemStyle getStyle()  
      ContextMenu getSubMenu()  
      com.badlogic.gdx.scenes.scene2d.ui.Cell<com.badlogic.gdx.scenes.scene2d.ui.Image> getSubMenuIconCell()  
      java.lang.CharSequence getText()  
      boolean isGenerateDisabledImage()  
      boolean isOver()  
      void setGenerateDisabledImage​(boolean generateDisabledImage)
      Changes generateDisabledImage property, when true that function is enabled.
      protected void setParent​(com.badlogic.gdx.scenes.scene2d.Group parent)  
      MenuItem setShortcut​(int keycode)
      Set shortcuts text displayed in this menu item.
      MenuItem setShortcut​(int... keycodes)
      Creates platform dependant shortcut text.
      MenuItem setShortcut​(java.lang.String text)
      Set shortcuts text displayed in this menu item.
      protected void setStage​(com.badlogic.gdx.scenes.scene2d.Stage stage)  
      void setStyle​(com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle style)  
      void setSubMenu​(ContextMenu subMenu)  
      void setText​(java.lang.CharSequence text)  
      • Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Button

        getButtonGroup, getClickListener, getMinHeight, getMinWidth, getPrefHeight, getPrefWidth, isChecked, isDisabled, isPressed, setChecked, setDisabled, setProgrammaticChangeEvents, toggle
      • Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

        add, add, add, add, add, add, add, align, background, background, bottom, center, clearChildren, columnDefaults, debug, debug, debugActor, debugAll, debugCell, debugTable, defaults, drawBackground, drawDebug, drawDebugBounds, getAlign, getBackground, getCell, getCells, getClip, getColumnMinWidth, getColumnPrefWidth, getColumns, getColumnWidth, getPadBottom, getPadBottomValue, getPadLeft, getPadLeftValue, getPadRight, getPadRightValue, getPadTop, getPadTopValue, getPadX, getPadY, getRow, getRowHeight, getRowMinHeight, getRowPrefHeight, getRows, getSkin, getTableDebug, hit, invalidate, layout, left, pad, pad, pad, pad, padBottom, padBottom, padLeft, padLeft, padRight, padRight, padTop, padTop, removeActor, removeActor, reset, right, row, setBackground, setBackground, setClip, setDebug, setRound, setSkin, stack, top
      • Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup

        childrenChanged, getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
      • Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group

        act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, computeTransform, drawChildren, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, setCullingArea, setDebug, setTransform, swapActor, swapActor, toString
      • Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor

        addAction, addCaptureListener, addListener, ancestorsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        java.lang.String styleName)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.utils.ChangeListener changeListener)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable,
                        com.badlogic.gdx.scenes.scene2d.utils.ChangeListener changeListener)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable,
                        java.lang.String styleName)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.ui.Image image)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.ui.Image image,
                        com.badlogic.gdx.scenes.scene2d.utils.ChangeListener changeListener)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.ui.Image image,
                        java.lang.String styleName)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.ui.Image image,
                        MenuItem.MenuItemStyle style)
      • MenuItem

        public MenuItem​(java.lang.String text,
                        com.badlogic.gdx.scenes.scene2d.ui.Skin skin,
                        com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable,
                        MenuItem.MenuItemStyle style)
    • Method Detail

      • setSubMenu

        public void setSubMenu​(ContextMenu subMenu)
      • setParent

        protected void setParent​(com.badlogic.gdx.scenes.scene2d.Group parent)
        Overrides:
        setParent in class com.badlogic.gdx.scenes.scene2d.Actor
      • getStyle

        public MenuItem.MenuItemStyle getStyle()
        Overrides:
        getStyle in class com.badlogic.gdx.scenes.scene2d.ui.Button
      • setStyle

        public void setStyle​(com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle style)
        Overrides:
        setStyle in class com.badlogic.gdx.scenes.scene2d.ui.Button
      • draw

        public void draw​(com.badlogic.gdx.graphics.g2d.Batch batch,
                         float parentAlpha)
        Overrides:
        draw in class com.badlogic.gdx.scenes.scene2d.ui.Button
      • isOver

        public boolean isOver()
        Overrides:
        isOver in class com.badlogic.gdx.scenes.scene2d.ui.Button
      • isGenerateDisabledImage

        public boolean isGenerateDisabledImage()
      • setGenerateDisabledImage

        public void setGenerateDisabledImage​(boolean generateDisabledImage)
        Changes generateDisabledImage property, when true that function is enabled. When it is enabled and this MenuItem is disabled then image color will be changed to gray meaning that it is disabled, by default it is enabled.
      • setShortcut

        public MenuItem setShortcut​(int keycode)
        Set shortcuts text displayed in this menu item. This DOES NOT set actual hot key for this menu item, it only makes shortcut text visible in item.
        Parameters:
        keycode - from Input.Keys.
      • getShortcut

        public java.lang.CharSequence getShortcut()
      • setShortcut

        public MenuItem setShortcut​(java.lang.String text)
        Set shortcuts text displayed in this menu item. This DOES NOT set actual hot key for this menu item, it only makes shortcut text visible in item.
        Parameters:
        text - text that will be displayed
        Returns:
        this object for the purpose of chaining methods
      • setShortcut

        public MenuItem setShortcut​(int... keycodes)
        Creates platform dependant shortcut text. Converts int keycodes to String text. Eg. Keys.CONTROL_LEFT, Keys.SHIFT_LEFT, Keys.F5 will be converted to Ctrl+Shift+F5 on Windows and Linux, and to ⌘⇧F5 on Mac.

        CONTROL_LEFT and CONTROL_RIGHT are mapped to Ctrl. The same goes for Alt (ALT_LEFT, ALT_RIGHT) and Shift (SHIFT_LEFT, SHIFT_RIGHT).

        This DOES NOT set actual hot key for this menu item, it only makes shortcut text visible in item.

        Parameters:
        keycodes - keycodes from Input.Keys that are used to create shortcut text
        Returns:
        this object for the purpose of chaining methods
      • setStage

        protected void setStage​(com.badlogic.gdx.scenes.scene2d.Stage stage)
        Overrides:
        setStage in class com.badlogic.gdx.scenes.scene2d.Group
      • getImage

        public com.badlogic.gdx.scenes.scene2d.ui.Image getImage()
      • getImageCell

        public com.badlogic.gdx.scenes.scene2d.ui.Cell<?> getImageCell()
      • getLabel

        public com.badlogic.gdx.scenes.scene2d.ui.Label getLabel()
      • getLabelCell

        public com.badlogic.gdx.scenes.scene2d.ui.Cell<?> getLabelCell()
      • getText

        public java.lang.CharSequence getText()
      • setText

        public void setText​(java.lang.CharSequence text)
      • getSubMenuIconCell

        public com.badlogic.gdx.scenes.scene2d.ui.Cell<com.badlogic.gdx.scenes.scene2d.ui.Image> getSubMenuIconCell()
      • getShortcutCell

        public com.badlogic.gdx.scenes.scene2d.ui.Cell<com.badlogic.gdx.scenes.scene2d.ui.Label> getShortcutCell()