com.badlogic.gdx.scenes.scene2d.ui.Label.getStyle()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中com.badlogic.gdx.scenes.scene2d.ui.Label.getStyle()方法的一些代码示例,展示了Label.getStyle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Label.getStyle()方法的具体详情如下:
包路径:com.badlogic.gdx.scenes.scene2d.ui.Label
类名称:Label
方法名:getStyle

Label.getStyle介绍

[英]Returns the label's style. Modifying the returned style may not have an effect until #setStyle(LabelStyle) is called.
[中]返回标签的样式。在调用#setStyle(LabelStyle)之前,修改返回的样式可能不会产生效果。

代码示例

代码示例来源:origin: libgdx/libgdx

public void setStyle (ButtonStyle style) {
  if (style == null) throw new NullPointerException("style cannot be null");
  if (!(style instanceof TextButtonStyle)) throw new IllegalArgumentException("style must be a TextButtonStyle.");
  super.setStyle(style);
  this.style = (TextButtonStyle)style;
  if (label != null) {
    TextButtonStyle textButtonStyle = (TextButtonStyle)style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

代码示例来源:origin: libgdx/libgdx

public void setStyle (ButtonStyle style) {
  if (style == null) throw new NullPointerException("style cannot be null");
  if (!(style instanceof TextButtonStyle)) throw new IllegalArgumentException("style must be a TextButtonStyle.");
  super.setStyle(style);
  this.style = (TextButtonStyle)style;
  if (label != null) {
    TextButtonStyle textButtonStyle = (TextButtonStyle)style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

代码示例来源:origin: libgdx/libgdx

public void setStyle (ButtonStyle style) {
  if (!(style instanceof ImageTextButtonStyle)) throw new IllegalArgumentException("style must be a ImageTextButtonStyle.");
  super.setStyle(style);
  this.style = (ImageTextButtonStyle)style;
  if (image != null) updateImage();
  if (label != null) {
    ImageTextButtonStyle textButtonStyle = (ImageTextButtonStyle)style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

代码示例来源:origin: libgdx/libgdx

public void setStyle (ButtonStyle style) {
  if (!(style instanceof ImageTextButtonStyle)) throw new IllegalArgumentException("style must be a ImageTextButtonStyle.");
  super.setStyle(style);
  this.style = (ImageTextButtonStyle)style;
  if (image != null) updateImage();
  if (label != null) {
    ImageTextButtonStyle textButtonStyle = (ImageTextButtonStyle)style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

代码示例来源:origin: libgdx/libgdx

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;
  super.draw(batch, parentAlpha);
}

代码示例来源:origin: libgdx/libgdx

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;
  super.draw(batch, parentAlpha);
}

代码示例来源:origin: libgdx/libgdx

public void draw (Batch batch, float parentAlpha) {
  updateImage();
  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;
  super.draw(batch, parentAlpha);
}

代码示例来源:origin: libgdx/libgdx

public void draw (Batch batch, float parentAlpha) {
  updateImage();
  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;
  super.draw(batch, parentAlpha);
}

代码示例来源:origin: bladecoder/bladecoder-adventure-engine

public void setError(boolean value) {
  if (value)
    title.getStyle().fontColor = Color.RED;
  else
    title.getStyle().fontColor = Color.WHITE;
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

public void setStyle (ButtonStyle style) {
  if (style == null) throw new NullPointerException("style cannot be null");
  if (!(style instanceof TextButtonStyle)) throw new IllegalArgumentException("style must be a TextButtonStyle.");
  super.setStyle(style);
  this.style = (TextButtonStyle)style;
  if (label != null) {
    TextButtonStyle textButtonStyle = (TextButtonStyle)style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

代码示例来源:origin: kotcrab/vis-ui

@Override
public void setStyle (ButtonStyle style) {
  if (!(style instanceof MenuItemStyle)) throw new IllegalArgumentException("style must be a MenuItemStyle.");
  super.setStyle(style);
  this.style = (MenuItemStyle) style;
  if (label != null) {
    TextButtonStyle textButtonStyle = (TextButtonStyle) style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

public void setStyle (ButtonStyle style) {
  if (!(style instanceof ImageTextButtonStyle)) throw new IllegalArgumentException("style must be a ImageTextButtonStyle.");
  super.setStyle(style);
  this.style = (ImageTextButtonStyle)style;
  if (image != null) updateImage();
  if (label != null) {
    ImageTextButtonStyle textButtonStyle = (ImageTextButtonStyle)style;
    LabelStyle labelStyle = label.getStyle();
    labelStyle.font = textButtonStyle.font;
    labelStyle.fontColor = textButtonStyle.fontColor;
    label.setStyle(labelStyle);
  }
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

private static void scaleLabel(Label label, float labelWidth){

    float labelTextWidth = GdxUtils.getTextWidth(label) /label.getFontScaleX();
    float scaleDownFactor = labelWidth / labelTextWidth;
    if (labelTextWidth > labelWidth) {
      label.setFontScale(label.getStyle().font.getScaleX() * scaleDownFactor);
    }
  }
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

public static void autoScaleLabel(Label label){
  float labelTextWidth = getTextWidth(label);
  float labelWidth = label.getWidth();
  float scaleDownFactor = labelWidth / labelTextWidth;
  if (labelTextWidth > labelWidth) {
    label.setFontScale(label.getStyle().font.getScaleX() * scaleDownFactor);
  }
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

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;
  super.draw(batch, parentAlpha);
}

代码示例来源:origin: bladecoder/bladecoder-adventure-engine

private static void add(Stage stage, String text) {
  msg.clearActions();
  msg.setText(text);
  GlyphLayout textLayout = new GlyphLayout();
  textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true);
  msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2);
  if (!stage.getActors().contains(msg, true))
    stage.addActor(msg);
  msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2),
      Math.round((stage.getHeight() - msg.getHeight()) / 2));
  msg.invalidate();
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

private void autoScaleTextButton(TextButton textButton) {
    Label label = textButton.getLabel();
    float textButtonWidth = textButton.getWidth() - textButton.getPadLeft() - textButton.getPadRight();
    float labelWidth = label.getWidth();
    if (labelWidth > textButtonWidth) {
      float scaleDownFactor = textButtonWidth / labelWidth;
      label.setFontScale(label.getStyle().font.getScaleX() * scaleDownFactor);
      label.setWidth(label.getWidth() * scaleDownFactor);
    }
  }
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

public static void autoScaleTextButton(TextButton textButton){
  Label label = textButton.getLabel();
  float textButtonWidth = textButton.getWidth() - textButton.getPadLeft() - textButton.getPadRight();
  float labelWidth = getTextWidth(label);
  if (labelWidth > textButtonWidth) {
    float scaleDownFactor = textButtonWidth / labelWidth;
    label.setFontScale(label.getStyle().font.getScaleX() * scaleDownFactor);
    label.setWidth(label.getWidth() * scaleDownFactor);
  }
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

public static void setLineHeight(Label label, float height) {
  BitmapFont font = label.getStyle().font;
  BitmapFont.BitmapFontData copiedData = new BitmapFont.BitmapFontData(font.getData().fontFile, font.getData().flipped);
  copiedData.setLineHeight(height);
  Label.LabelStyle style = new Label.LabelStyle(new BitmapFont(copiedData, font.getRegion(), true), new Color(font.getColor()));
  label.setStyle(style);
}

代码示例来源:origin: peakgames/libgdx-stagebuilder

private void setAlignmentAndScaling(LabelModel labelModel, Label label) {
  label.setAlignment(calculateAlignment(labelModel.getAlignment()));
  label.setWrap(labelModel.isWrap());
  if (labelModel.isFontAutoScale()) {
    autoScaleLabel(label);
  } else if (labelModel.getFontScale() != 1) {
    label.setFontScale(label.getStyle().font.getScaleX() * labelModel.getFontScale());
  } else if (labelModel.getLabelScale() != 0) {
    float scaleLabelWidth = labelModel.getLabelScale() * resolutionHelper.getPositionMultiplier();
    scaleLabel(label, scaleLabelWidth);
  }
}

相关文章