本文整理了Java中com.badlogic.gdx.scenes.scene2d.ui.Button
类的一些代码示例,展示了Button
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Button
类的具体详情如下:
包路径:com.badlogic.gdx.scenes.scene2d.ui.Button
类名称:Button
[英]A button is a Table with a checked state and additional ButtonStyle fields for pressed, unpressed, and checked. Each time a button is clicked, the checked state is toggled. Being a table, a button can contain any other actors.
The button's padding is set to the background drawable's padding when the background changes, overwriting any padding set manually. Padding can still be set on the button's table cells.
ChangeEvent is fired when the button is clicked. Cancelling the event will restore the checked button state to what is was previously.
The preferred size of the button is determined by the background and the button contents.
[中]按钮是具有选中状态的表,以及用于按下、未按下和选中的其他按钮样式字段。每次单击按钮时,都会切换选中状态。作为一个表,按钮可以包含任何其他参与者。
当背景更改时,按钮的填充设置为背景可绘制的填充,手动覆盖任何填充设置。仍然可以在按钮的表格单元格上设置填充。
单击按钮时激发ChangeEvent。取消事件将使选中的按钮状态恢复到以前的状态。
按钮的首选大小由背景和按钮内容决定。
代码示例来源:origin: libgdx/libgdx
private void initialize () {
setTouchable(Touchable.enabled);
addListener(clickListener = new ClickListener() {
public void clicked (InputEvent event, float x, float y) {
if (isDisabled()) return;
setChecked(!isChecked, true);
}
});
addListener(new FocusListener() {
public void keyboardFocusChanged (FocusEvent event, Actor actor, boolean focused) {
Button.this.focused = focused;
}
});
}
代码示例来源:origin: libgdx/libgdx
/** Toggles the checked state. This method changes the checked state, which fires a {@link ChangeEvent} (if programmatic change
* events are enabled), so can be used to simulate a button click. */
public void toggle () {
setChecked(!isChecked);
}
代码示例来源:origin: libgdx/libgdx
public Button (Actor child, ButtonStyle style) {
initialize();
add(child);
setStyle(style);
setSize(getPrefWidth(), getPrefHeight());
}
代码示例来源:origin: libgdx/libgdx
public void clicked (InputEvent event, float x, float y) {
if (isDisabled()) return;
setChecked(!isChecked, true);
}
});
代码示例来源:origin: libgdx/libgdx
public void draw (Batch batch, float parentAlpha) {
validate();
boolean isDisabled = isDisabled();
boolean isPressed = isPressed();
boolean isChecked = isChecked();
boolean isOver = isOver();
setBackground(background);
Array<Actor> children = getChildren();
for (int i = 0; i < children.size; i++)
children.get(i).moveBy(offsetX, offsetY);
children.get(i).moveBy(-offsetX, -offsetY);
Stage stage = getStage();
if (stage != null && stage.getActionsRequestRendering() && isPressed != clickListener.isPressed())
Gdx.graphics.requestRendering();
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
final Button button = new Button(new ButtonStyle());
final ButtonStyle style = button.getStyle();
style.up = style.down = skin.getDrawable("black");
button.setSize(slotWidth, slotHeight);
button.add(getScreenshot(slot)).maxSize(slotWidth * .95f, slotHeight * .95f);
button.addListener(loadClickListener);
} else {
Image fg = new Image(skin.getDrawable("plus"));
button.add(fg).maxSize(slotHeight / 2, slotHeight / 2);
button.addListener(saveClickListener);
button.row();
button.add(label).fillX();
button.setName(slot);
return button;
代码示例来源:origin: Var3D/var3dframe
btn_back.add(game.getLabel("返回").setFontScale(0.6f).getActor());
btn_back.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
btn_dialog.add(game.getLabel("等比例舞台").setFontScale(0.6f).getActor());
btn_dialog.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.setStage(StageRatio.class);
btn_unRatio.add(game.getLabel("非等比例舞台").setFontScale(0.6f).getActor());
btn_unRatio.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.setStage(StageUnRatio.class);
btn_more.add(game.getLabel("等待添加...").setFontScale(0.6f).getActor());
btn_more.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.showMessege("更多效果尽请期待...");
代码示例来源:origin: libgdx/libgdx
Button imgButton = new Button(new Image(image), skin);
Button imgToggleButton = new Button(new Image(image), skin, "toggle");
passwordTextField.setPasswordMode(true);
buttonMulti.addListener(new TextTooltip(
"This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip!",
skin));
tooltipTable.pad(10).background("default-round");
tooltipTable.add(new TextButton("Fancy tooltip!", skin));
imgButton.addListener(new Tooltip(tooltipTable));
代码示例来源:origin: libgdx/libgdx
button0.addListener(new ChangeListener(){
public void changed (ChangeEvent event, Actor actor) {
boolean continuous = Gdx.graphics.isContinuousRendering();
button1.addListener(new ChangeListener(){
public void changed (ChangeEvent event, Actor actor) {
new Thread(new Runnable(){
button2.addListener(new ChangeListener(){
public void changed (ChangeEvent event, Actor actor) {
final Graphics graphics = Gdx.graphics; // caching necessary to ensure call on this window
button3.addListener(new ChangeListener(){
public void changed (ChangeEvent event, Actor actor) {
Timer.schedule(new Task(){
button4.addListener(new ChangeListener(){
public void changed (ChangeEvent event, Actor actor) {
stage.addAction(Actions.sequence(Actions.delay(2), Actions.run(new Runnable(){
button5.addListener(new ChangeListener(){
public void changed (ChangeEvent event, Actor actor) {
final Graphics graphics = Gdx.graphics; // caching necessary to ensure call on this window
代码示例来源:origin: libgdx/libgdx
public void setStyle (ButtonStyle style) {
if (style == null) throw new IllegalArgumentException("style cannot be null.");
this.style = style;
Drawable background = null;
if (isPressed() && !isDisabled())
background = style.down == null ? style.up : style.down;
else {
if (isDisabled() && style.disabled != null)
background = style.disabled;
else if (isChecked && style.checked != null) {
if (isOver() && style.checkedOver != null)
background = style.checkedOver;
else if (focused && style.checkedFocused != null)
background = style.checkedFocused;
else
background = style.checked;
} else if (isOver() && style.over != null)
background = style.over;
else if (focused && style.focused != null)
background = style.focused;
else
background = style.up;
}
setBackground(background);
}
代码示例来源:origin: xietansheng/Game2048ForGDX
getMainGame().getAtlas().findRegion(Res.AtlasNames.GAME_BTN_HELP, 2)
);
helpButton = new Button(helpStyle);
helpButton.setX(15);
helpButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
setSize(getMainGame().getWorldWidth(), helpButton.getHeight());
getMainGame().getAtlas().findRegion(Res.AtlasNames.GAME_BTN_EXIT, 2)
);
exitButton = new Button(exitStyle);
exitButton.setX(240);
exitButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
代码示例来源:origin: narfman0/GDXWorld
/** builds {@link #chooseButton}, {@link #cancelButtonListener}, {@link #tree}, {@link #treePane} */
protected void buildWidgets() {
(tree = new Tree(style.treeStyle)).addListener(treeListener);
if(style.scrollPaneStyle != null)
treePane = new ScrollPane(tree, style.scrollPaneStyle);
else
treePane = new ScrollPane(tree);
(chooseButton = Scene2DUtils.newButton(style.selectButtonStyle, "select")).addListener(chooseButtonListener);
chooseButton.setDisabled(true);
(cancelButton = Scene2DUtils.newButton(style.cancelButtonStyle, "cancel")).addListener(cancelButtonListener);
}
代码示例来源:origin: libgdx/libgdx
public void add (T button) {
if (button == null) throw new IllegalArgumentException("button cannot be null.");
button.buttonGroup = null;
boolean shouldCheck = button.isChecked() || buttons.size < minCheckCount;
button.setChecked(false);
button.buttonGroup = this;
buttons.add(button);
button.setChecked(shouldCheck);
}
代码示例来源:origin: Var3D/var3dframe
btn_tost.add(game.getLabel(R.strings.tost).getActor());
btn_tost.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.setUserData(DialogMessge.MODEL, new DialogMessge.Model("这是一个Tost范例"));
btn_dialog.add(game.getLabel("等比例对话框").getActor());
btn_dialog.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.showDialog(DialogRatio.class);
.setPosition(getWidth() / 2, btn_dialog.getTop()+10, Align.bottom).addClicAction().show();
btn_dialogfull.add(game.getLabel("拉伸全屏对话框").getActor());
btn_dialogfull.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
game.showDialog(DialogTestFull.class);
代码示例来源:origin: libgdx/libgdx
public void draw (Batch batch, float parentAlpha) {
updateImage();
super.draw(batch, parentAlpha);
}
代码示例来源:origin: langurmonkey/gaiasky
Button b = buttonMap.get(key);
b.setProgrammaticChangeEvents(false);
if (b != null) {
if (data.length == 3) {
b.setChecked((Boolean) data[2]);
} else {
b.setChecked(!b.isChecked());
b.setProgrammaticChangeEvents(true);
代码示例来源:origin: libgdx/libgdx
public void setStyle (ButtonStyle style) {
if (!(style instanceof ImageButtonStyle)) throw new IllegalArgumentException("style must be an ImageButtonStyle.");
super.setStyle(style);
this.style = (ImageButtonStyle)style;
if (image != null) updateImage();
}
代码示例来源:origin: Var3D/var3dframe
/**
* 创建Button
*/
public UI<Button> getButton() {
return getUI(new Button(getPointDrawable()));
}
代码示例来源:origin: dingjibang/GDX-RPG
public boolean checked(){
if(t instanceof Button)
return ((Button)t).isChecked();
return false;
}
代码示例来源:origin: kotcrab/vis-ui
if (wrapper.button.isChecked() != wrapper.mustBeChecked) {
wrapper.setButtonStateInvalid(true);
} else {
if (treatDisabledFieldsAsValid && wrapper.button.isDisabled()) {
continue;
if (wrapper.button.isChecked() != wrapper.mustBeChecked) {
errorMsgText = wrapper.errorMsg;
formInvalid = true;
内容来源于网络,如有侵权,请联系作者删除!