Example #1
0
  private void init(String text, Image image, MenuItemStyle style) {
    this.style = style;
    this.image = image;
    setSkin(VisUI.getSkin());
    Sizes sizes = getSkin().get(Sizes.class);

    defaults().space(3);

    if (image != null) image.setScaling(Scaling.fit);
    add(image).size(sizes.menuItemIconSize);

    label = new Label(text, new LabelStyle(style.font, style.fontColor));
    label.setAlignment(Align.left);
    add(label).expand().fill();

    add(shortcutLabel = new VisLabel("", "menuitem-shortcut")).padLeft(10).right();
    shortcutLabelColor = shortcutLabel.getStyle().fontColor;

    subMenuIconCell =
        add(subMenuImage = new Image(style.subMenu))
            .padLeft(3)
            .padRight(3)
            .size(style.subMenu.getMinWidth(), style.subMenu.getMinHeight());
    subMenuIconCell.setActor(null);

    addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            // makes submenu item not clickable
            if (subMenu != null) event.stop();
          }
        });

    addListener(
        new InputListener() {
          @Override
          public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            if (subMenu == null || isDisabled()) {
              // hides last visible submenu (if any)
              PopupMenu parent = (PopupMenu) getParent();
              parent.setSubMenu(null);
            } else {
              Stage stage = getStage();
              Vector2 pos = localToStageCoordinates(new Vector2(0, 0));

              subMenu.setPosition(
                  pos.x + getWidth() - 1, pos.y - subMenu.getHeight() + getHeight());
              if (subMenu.getY() < 0) {
                subMenu.setY(subMenu.getY() + subMenu.getHeight() - getHeight());
              }

              stage.addActor(subMenu);

              PopupMenu parent = (PopupMenu) getParent();
              parent.setSubMenu(subMenu);
            }
          }
        });
  }
Example #2
0
  @Override
  public void draw(Batch batch, float parentAlpha) {
    Color fontColor;
    if (isDisabled() && style.disabledFontColor != null) fontColor = style.disabledFontColor;
    else if (isPressed() && style.downFontColor != null) fontColor = style.downFontColor;
    else if (isChecked() && style.checkedFontColor != null)
      fontColor =
          (isOver() && style.checkedOverFontColor != null)
              ? style.checkedOverFontColor
              : style.checkedFontColor;
    else if (isOver() && style.overFontColor != null) fontColor = style.overFontColor;
    else fontColor = style.fontColor;
    if (fontColor != null) label.getStyle().fontColor = fontColor;

    if (isDisabled()) shortcutLabel.getStyle().fontColor = style.disabledFontColor;
    else shortcutLabel.getStyle().fontColor = shortcutLabelColor;

    if (image != null && generateDisabledImage) {
      if (isDisabled()) image.setColor(Color.GRAY);
      else image.setColor(Color.WHITE);
    }

    super.draw(batch, parentAlpha);
  }
Example #3
0
 /**
  * Set shortcut text displayed in this menu item. Displayed as keycode+keycode+keycode (eg.
  * Ctrl+Shift+F5 on Windows and Linux, on Mac ⌘⇧F5). CONTROL_LEFT and CONTROL_RIGHT are mapped to
  * Ctrl. The same goes for Alt and Shift. This DOES NOT set actual hot key for this menu item, it
  * only makes shortcut text visible in item.
  *
  * @param keycodes keycodes from {@link Keys} that are used to determine the shortcut text
  * @return this object for the purpose of chaining methods
  */
 public MenuItem setShortcut(int... keycodes) {
   shortcutLabel.setText(OsUtils.getShortcutFor(keycodes));
   packParentMenu();
   return this;
 }
Example #4
0
 /**
  * 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.
  *
  * @param text text that will be displayed
  * @return this object for the purpose of chaining methods
  */
 public MenuItem setShortcut(String text) {
   shortcutLabel.setText(text);
   packParentMenu();
   return this;
 }
Example #5
0
 public CharSequence getShortcut() {
   return shortcutLabel.getText();
 }
Example #6
0
 public String getShortcut() {
   return shortcutLabel.getText().toString();
 }