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

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

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

Label.setWrap介绍

[英]If false, the text will only wrap where it contains newlines (\n). The preferred size of the label will be the text bounds. If true, the text will word wrap using the width of the label. The preferred width of the label will be 0, it is expected that something external will set the width of the label. Wrapping will not occur when ellipsis is enabled. Default is false.

When wrap is enabled, the label's preferred height depends on the width of the label. In some cases the parent of the label will need to layout twice: once to set the width of the label and a second time to adjust to the label's new preferred height.
[中]如果为false,文本将仅在包含换行符的位置换行(\n)。标签的首选大小为文本边界。如果为true,文本将使用标签的宽度进行换行。标签的首选宽度将为0,预计外部将设置标签的宽度。启用省略号时不会进行换行。默认值为false。
启用“包裹”时,标签的首选高度取决于标签的宽度。在某些情况下,标签的父级需要布局两次:一次设置标签的宽度,第二次调整标签的新首选高度。

代码示例

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

public TextTooltip (String text, final TooltipManager manager, TextTooltipStyle style) {
  super(null, manager);
  Label label = new Label(text, style.label);
  label.setWrap(true);
  container.setActor(label);
  container.width(new Value() {
    public float get (Actor context) {
      return Math.min(manager.maxWidth, container.getActor().getGlyphLayout().width);
    }
  });
  setStyle(style);
}

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

public TextTooltip (String text, final TooltipManager manager, TextTooltipStyle style) {
  super(null, manager);
  Label label = new Label(text, style.label);
  label.setWrap(true);
  container.setActor(label);
  container.width(new Value() {
    public float get (Actor context) {
      return Math.min(manager.maxWidth, container.getActor().getGlyphLayout().width);
    }
  });
  setStyle(style);
}

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

@Override
public void create () {
  batch = new SpriteBatch();
  skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  stage = new Stage();
  Gdx.input.setInputProcessor(stage);
  Table table = new Table();
  stage.addActor(table);
  table.setPosition(200, 65);
  Label label1 = new Label("This text is scaled 2x.", skin);
  label1.setFontScale(2);
  Label label2 = new Label(
    "This text is scaled. This text is scaled. This text is scaled. This text is scaled. This text is scaled. ", skin);
  label2.setWrap(true);
  label2.setFontScale(0.75f, 0.75f);
  table.debug();
  table.add(label1);
  table.row();
  table.add(label2).fill();
  table.pack();
}

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

label.setWrap(true);
label.setAlignment(Align.bottom | Align.right);
table.add(label).minWidth(200 * scale).minHeight(110 * scale).fill().row();
label.setWrap(true);
label.setAlignment(Align.bottom | Align.right);
table.add(label).minWidth(200 * scale).minHeight(110 * scale).fill().row();
label.setWrap(true);
table.add(label).align(Align.left).width(150 * scale).row();
label.setWrap(true);
table.add(label).align(Align.left).width(150 * scale).row();

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

statusLabel.setWrap(true);
statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
statusLabel.setAlignment(Align.center);

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

@Override
public void setWrap(boolean wrap) {
  super.setWrap(wrap);
  shadowLabel.setWrap(wrap);
}

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

lbl.setWrap(true);
window.row();
window.add(lbl).width(400);

代码示例来源:origin: stackoverflow.com

// Create
Label label = new Label("ORTHO", style);
label.setWrap(true);

Label label1 = new Label("A", style);
label1.setWrap(true);

Label label2 = new Label("A", style);
label2.setWrap(true);

// Add
table.add(label).width(100).colspan(2);
table.row();

table.add(label1).width(50).align(Align.left);
table.add(label2).width(50).align(Align.left);

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

myLabel.setWrap(true);

代码示例来源:origin: manuelbua/uracer-kotd

public static Label newLabel (String text, boolean wrap) {
  Label l = new Label(text, Art.scrSkin);
  l.setWrap(wrap);
  return l;
}

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

public static void init(Skin skin) {
  msg = new Label("", skin, "message") {
    @Override
    public Actor hit(float x, float y, boolean touchable) {
      if (isModal)
        return this;
      return null;
    }
  };
  Message.skin = skin;
  msg.setWrap(true);
  msg.setAlignment(Align.center, Align.center);
}

代码示例来源:origin: dingjibang/GDX-RPG

/**是否允许超长换行*/
public Label warp(boolean warp) {
  setWrap(warp);
  this.warp = warp;
  super.setWrap(warp);
  return this;
}

代码示例来源:origin: SquidPony/SquidLib

/**
 * Converts a String into a Label, or if the argument s is null, creates an Image of a solid block. Can be used
 * for preparing glyphs for animation effects.
 * @param s a String to make into an Actor, which can be null for a solid block.
 * @return the Actor, with no position set.
 */
public Label makeWrappingString(String s) {
  if (!initialized) {
    throw new IllegalStateException("This factory has not yet been initialized!");
  }
  if (s == null) {
    s = "";
  }
  Label lb = new Label(s, style);
  lb.setWrap(true);
  // lb.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
  return lb;
}

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

public OwnTextTooltip(String text, final TooltipManager manager, TextTooltipStyle style, int breakSpaces) {
  super(null, manager);
  // Warp text if breakSpaces <= 0
  if (breakSpaces > 0) {
    StringBuilder sb = new StringBuilder(text);
    int spaces = 0;
    for (int i = 0; i < sb.length(); i++) {
      char c = sb.charAt(i);
      if (c == ' ') {
        spaces++;
      }
      if (spaces == breakSpaces) {
        sb.setCharAt(i, '\n');
        spaces = 0;
      }
    }
    text = sb.toString();
  }
  label = new Label(text, style.label);
  label.setWrap(true);
  getContainer().setActor(label);
  getContainer().width(new Value() {
    public float get(Actor context) {
      return Math.min(manager.maxWidth, getContainer().getActor().getGlyphLayout().width);
    }
  });
  setStyle(style);
}

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

public TextTooltip (String text, final TooltipManager manager, TextTooltipStyle style) {
  super(null, manager);
  Label label = new Label(text, style.label);
  label.setWrap(true);
  container.setActor(label);
  container.width(new Value() {
    public float get (Actor context) {
      return Math.min(manager.maxWidth, container.getActor().getGlyphLayout().width);
    }
  });
  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);
  }
}

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

protected void init(Skin skin, String title, String desc, Actor c, boolean mandatory, String defaultValue) {
  // debug();
  this.mandatory = mandatory;
  this.setSkin(skin);
  LabelStyle style = new LabelStyle(skin.get(LabelStyle.class));
  this.title = new Label(title, style);
  this.desc = new Label(desc, skin, "subtitle");
  this.desc.setWrap(false);
  this.field = c;
  // row().expand();
  float titleWidth = this.title.getStyle().font.getSpaceXadvance() * 35;
  add(this.title).width(titleWidth).left().top();
  this.title.setWidth(titleWidth);
  this.title.setWrap(true);
  // row().expand();
  add(field).expandX().left().top();
  if (USE_TOOLTIPS) {
    TextTooltip t = new TextTooltip(desc, skin);
    this.title.addListener(t);
    this.field.addListener(t);
  } else {
    row().expand();
    add(this.desc).colspan(2).left();
  }
  if (defaultValue != null)
    setText(defaultValue);
}

代码示例来源:origin: kbz/SIFTrain

@Override
public void show() {
  float scaleFactor = stage.getHeight() / GlobalConfiguration.BASE_HEIGHT;
  backgroundImage.setSize(stage.getWidth(), stage.getHeight());
  loadingProgress.setSize(stage.getWidth() * 0.7f, stage.getHeight() * 0.07f);
  loadingProgress.setX(stage.getWidth() * 0.15f);
  loadingProgress.setY(stage.getHeight() * 0.1f);
  infoLabel.setX(stage.getWidth() * 0.1f);
  infoLabel.setY(stage.getHeight() * 0.2f);
  infoLabel.setWrap(true);
  infoLabel.setWidth(stage.getWidth() * 0.8f);
  infoLabel.setHeight(stage.getHeight() * 0.7f);
  infoLabel.setFontScale(scaleFactor);
  stage.addActor(backgroundImage);
  stage.addActor(loadingProgress);
  stage.addActor(infoLabel);
}

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

infoLbl.setWrap(true);
centerPanel = new Table(skin);
infoCell = getContentTable().add((Widget) infoLbl).prefWidth(200);

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

protected void setTextButtonProperties(TextButtonModel textButtonModel, BitmapFont font, TextButton textButton) {
  float positionMultiplier = resolutionHelper.getPositionMultiplier();
  if (textButtonModel.getLabelPadding() != 0) {
    textButton.pad(textButtonModel.getLabelPadding() * positionMultiplier);
  } else {
    textButton.padBottom(textButtonModel.getLabelPaddingBottom() * positionMultiplier);
    textButton.padTop(textButtonModel.getLabelPaddingTop() * positionMultiplier);
    textButton.padRight(textButtonModel.getLabelPaddingRight() * positionMultiplier);
    textButton.padLeft(textButtonModel.getLabelPaddingLeft() * positionMultiplier);
  }
  
  Label label = textButton.getLabel();
  label.setWrap(textButtonModel.isWrap());
  if (textButtonModel.getAlignment() != null) {
    int alignment = calculateAlignment(textButtonModel.getAlignment());
    label.setAlignment(alignment);
  }
  Cell labelCell = textButton.getLabelCell();
  if (textButtonModel.isFontAutoScale()) {
    autoScaleTextButton(textButton);
  } else if (textButtonModel.getFontScale() != 1) {
    labelCell.height(textButton.getHeight());
    labelCell.bottom();
    label.setFontScale(font.getScaleX() * textButtonModel.getFontScale());
    label.setAlignment(Align.center);
  }
}

相关文章