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

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

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

Label.getWidth介绍

暂无

代码示例

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

private void computePrefSize () {
  prefSizeInvalid = false;
  GlyphLayout prefSizeLayout = Label.prefSizeLayout;
  if (wrap && ellipsis == null) {
    float width = getWidth();
    if (style.background != null) width -= style.background.getLeftWidth() + style.background.getRightWidth();
    prefSizeLayout.setText(cache.getFont(), text, Color.WHITE, width, Align.left, true);
  } else
    prefSizeLayout.setText(cache.getFont(), text);
  prefSize.set(prefSizeLayout.width, prefSizeLayout.height);
}

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

private void computePrefSize () {
  prefSizeInvalid = false;
  GlyphLayout prefSizeLayout = Label.prefSizeLayout;
  if (wrap && ellipsis == null) {
    float width = getWidth();
    if (style.background != null) width -= style.background.getLeftWidth() + style.background.getRightWidth();
    prefSizeLayout.setText(cache.getFont(), text, Color.WHITE, width, Align.left, true);
  } else
    prefSizeLayout.setText(cache.getFont(), text);
  prefSize.set(prefSizeLayout.width, prefSizeLayout.height);
}

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

public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = tempColor.set(getColor());
  color.a *= parentAlpha;
  if (style.background != null) {
    batch.setColor(color.r, color.g, color.b, color.a);
    style.background.draw(batch, getX(), getY(), getWidth(), getHeight());
  }
  if (style.fontColor != null) color.mul(style.fontColor);
  cache.tint(color);
  cache.setPosition(getX(), getY());
  cache.draw(batch);
}

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

public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = tempColor.set(getColor());
  color.a *= parentAlpha;
  if (style.background != null) {
    batch.setColor(color.r, color.g, color.b, color.a);
    style.background.draw(batch, getX(), getY(), getWidth(), getHeight());
  }
  if (style.fontColor != null) color.mul(style.fontColor);
  cache.tint(color);
  cache.setPosition(getX(), getY());
  cache.draw(batch);
}

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

float width = getWidth(), height = getHeight();
Drawable background = style.background;
float x = 0, y = 0;

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

float width = getWidth(), height = getHeight();
Drawable background = style.background;
float x = 0, y = 0;

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

statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
statusLabel.setAlignment(Align.center);
statusLabel.setPosition(Gdx.graphics.getWidth() * 0.5f - statusLabel.getWidth() * 0.5f, 30f);
statusLabel.setColor(Color.CYAN);
stage.addActor(statusLabel);

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

@Override
public float getWidth() {
  return super.getWidth();
}

代码示例来源:origin: langurmonkey/gaiasky

public float getMessage1Width() {
  return message1 != null ? message1.getWidth() : 0;
}

代码示例来源:origin: langurmonkey/gaiasky

public float getMessage2Width() {
  return message2 != null ? message2.getWidth() : 0;
}

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

private void autoScaleLabel(Label label) {
  scaleLabel(label, label.getWidth());
}

代码示例来源: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 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: xietansheng/Game2048ForGDX

public void setScore(int score) {
  this.score = score;
  scoreLabel.setText("" + this.score);
  
  // 重新设置文本后, 文本的宽度可能被改变, 需要重新设置标签的宽度, 并重新水平居中
  scoreLabel.setWidth(scoreLabel.getPrefWidth());
  scoreLabel.setX(getWidth() / 2 - scoreLabel.getWidth() / 2);
}

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

public static void autoTrim(Label label){
  label.setText(trim(label.getText().toString(), label.getWidth(), label.getStyle().font));
}

代码示例来源:origin: langurmonkey/gaiasky

public static void capLabelWidth(Label l, float targetWidth){
  while(l.getWidth() > targetWidth){
    StringBuilder currText = l.getText();
    currText.deleteCharAt(currText.length);
    l.setText(currText);
    l.pack();
  }
  l.setText(l.getText() + "...");
}

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

private void computePrefSize () {
  prefSizeInvalid = false;
  GlyphLayout prefSizeLayout = Label.prefSizeLayout;
  if (wrap && ellipsis == null) {
    float width = getWidth();
    if (style.background != null) width -= style.background.getLeftWidth() + style.background.getRightWidth();
    prefSizeLayout.setText(cache.getFont(), text, Color.WHITE, width, Align.left, true);
  } else
    prefSizeLayout.setText(cache.getFont(), text);
  prefSize.set(prefSizeLayout.width, prefSizeLayout.height);
}

代码示例来源: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

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: com.badlogicgames.gdx/gdx

public void draw (Batch batch, float parentAlpha) {
  validate();
  Color color = tempColor.set(getColor());
  color.a *= parentAlpha;
  if (style.background != null) {
    batch.setColor(color.r, color.g, color.b, color.a);
    style.background.draw(batch, getX(), getY(), getWidth(), getHeight());
  }
  if (style.fontColor != null) color.mul(style.fontColor);
  cache.tint(color);
  cache.setPosition(getX(), getY());
  cache.draw(batch);
}

相关文章