List of usage examples for com.badlogic.gdx.scenes.scene2d Actor setWidth
public void setWidth(float width)
From source file:com.agateau.ui.menu.Menu.java
License:Apache License
private void updateGroupBounds() { Actor actor = mGroup.getActor(); actor.setWidth(getWidth() - 2 * mStyle.focusPadding); ((Layout) actor).invalidate();/*from ww w.j av a2 s. co m*/ ((Layout) actor).validate(); actor.setPosition(mStyle.focusPadding, mStyle.focusPadding); }
From source file:com.agateau.ui.menu.MenuItemGroup.java
License:Apache License
private void layoutItems() { // Keep in sync with computeHeight()! float y = 0;//from w ww.jav a 2 s .com Menu.MenuStyle style = mMenu.getMenuStyle(); final float spacing = style.focusPadding * 2 + style.spacing; for (int idx = mItems.size - 1; idx >= 0; --idx) { MenuItem item = mItems.get(idx); ItemInfo info = mInfoForItem.get(item); if (!info.visible) { continue; } Actor actor = item.getActor(); if (actor instanceof Layout) { ((Layout) actor).invalidate(); ((Layout) actor).validate(); } float x = 0; float width = mGroup.getWidth(); if (info.label != null) { info.label.setPosition(0, y); x = mMenu.getLabelColumnWidth(); width -= x; } float ratio = mItemForActor.get(actor).getParentWidthRatio(); if (ratio > 0) { actor.setWidth(width * ratio); } if (info.label == null) { x += (width - actor.getWidth()) / 2; } actor.setPosition(x, y); y += actor.getHeight() + spacing; } }
From source file:com.agateau.ui.UiBuilder.java
License:Apache License
protected void applyActorProperties(Actor actor, XmlReader.Element element, Group parentActor) { AnchorGroup anchorGroup = null;/* w ww. j av a 2 s.co m*/ if (parentActor != null) { parentActor.addActor(actor); if (parentActor instanceof AnchorGroup) { anchorGroup = (AnchorGroup) parentActor; } } String attr = element.getAttribute("x", ""); if (!attr.isEmpty()) { actor.setX(Float.parseFloat(attr)); } attr = element.getAttribute("y", ""); if (!attr.isEmpty()) { actor.setY(Float.parseFloat(attr)); } attr = element.getAttribute("width", ""); if (!attr.isEmpty()) { actor.setWidth(Float.parseFloat(attr)); } attr = element.getAttribute("height", ""); if (!attr.isEmpty()) { actor.setHeight(Float.parseFloat(attr)); } attr = element.getAttribute("originX", ""); if (!attr.isEmpty()) { actor.setOriginX(Float.parseFloat(attr)); } attr = element.getAttribute("originY", ""); if (!attr.isEmpty()) { actor.setOriginY(Float.parseFloat(attr)); } attr = element.getAttribute("visible", ""); if (!attr.isEmpty()) { actor.setVisible(Boolean.parseBoolean(attr)); } attr = element.getAttribute("color", ""); if (!attr.isEmpty()) { actor.setColor(Color.valueOf(attr)); } attr = element.getAttribute("debug", ""); if (!attr.isEmpty()) { if (actor instanceof Group) { Group group = (Group) actor; attr = attr.toLowerCase(); if (attr.equals("true")) { group.debug(); } else if (attr.equals("all")) { group.debugAll(); } } else { actor.setDebug(Boolean.parseBoolean(attr)); } } for (int idx = 0, size = ANCHOR_NAMES.length; idx < size; ++idx) { String anchorName = ANCHOR_NAMES[idx]; attr = element.getAttribute(anchorName, ""); if (!attr.isEmpty()) { if (anchorGroup == null) { throw new RuntimeException("Parent of " + actor + " is not an anchor group"); } PositionRule rule = parseRule(attr, anchorGroup.getSpacing()); rule.target = actor; rule.targetAnchor = ANCHORS[idx]; anchorGroup.addRule(rule); } } }
From source file:com.vlaaad.common.gdx.scene2d.TabPane.java
License:Open Source License
@Override public void layout() { if (selectedIndex == -1) return;//ww w . j a v a 2s . c o m // left offset float bordersHeight = 0f; headersLeftOffset = 0f; if (selectedIndex == 0) { if (style.activeBorderLeftEdge != null) { headersLeftOffset = style.activeBorderLeftEdge.getMinWidth(); bordersHeight = style.activeBorderLeftEdge.getMinHeight(); } } else { if (style.inactiveBorderLeftEdge != null) { headersLeftOffset = style.inactiveBorderLeftEdge.getMinWidth(); bordersHeight = Math.max(bordersHeight, style.inactiveBorderLeftEdge.getMinHeight()); } } //right offset headersRightOffset = 0f; if (selectedIndex == headers.size - 1) { if (style.activeBorderRightEdge != null) { headersRightOffset = style.activeBorderRightEdge.getMinWidth(); bordersHeight = Math.max(bordersHeight, style.activeBorderRightEdge.getMinHeight()); } } else { if (style.inactiveBorderRightEdge != null) { headersRightOffset = style.inactiveBorderRightEdge.getMinWidth(); bordersHeight = Math.max(bordersHeight, style.inactiveBorderRightEdge.getMinHeight()); } } //size between headers headersBetweenOffset = 0f; if (style.inactiveBorder != null) { headersBetweenOffset = style.inactiveBorder.getMinWidth(); bordersHeight = Math.max(bordersHeight, style.inactiveBorder.getMinHeight()); } if (style.activeBorderLeft != null) { headersBetweenOffset = Math.max(style.activeBorderLeft.getMinWidth(), headersBetweenOffset); bordersHeight = Math.max(bordersHeight, style.activeBorderLeft.getMinHeight()); } if (style.activeBorderRight != null) { headersBetweenOffset = Math.max(style.activeBorderRight.getMinWidth(), headersBetweenOffset); bordersHeight = Math.max(bordersHeight, style.activeBorderRight.getMinHeight()); } headersHeight = bordersHeight; for (Actor header : headers) { headersHeight = Math.max(headersHeight, header instanceof Layout ? ((Layout) header).getPrefHeight() : header.getHeight()); } headerWidth = (getWidth() - headersLeftOffset - headersRightOffset - headersBetweenOffset * (headers.size - 1)) / headers.size; int i = 0; contentHeight = getHeight() - headersHeight; for (Actor header : headers) { header.setWidth(headerWidth); header.setHeight(headersHeight); header.setPosition(i * headerWidth + headersLeftOffset + headersBetweenOffset * i, contentHeight); if (header instanceof Layout) { ((Layout) header).layout(); } i++; } Actor content = contents.get(selectedIndex); content.setWidth(getWidth()); content.setHeight(contentHeight); content.setPosition(0, 0); if (content instanceof Layout) ((Layout) content).layout(); }
From source file:de.bitbrain.craft.ui.elements.ElementConnector.java
License:Open Source License
private Actor addSpacing(String id) { Actor spacing = new Actor(); spacing.setWidth(group.getWidth()); spacing.setHeight(SPACING);//from w ww. j a v a 2s .co m spacings.put(id, spacing); return spacing; }
From source file:mobi.shad.s3lib.gui.GuiUtil.java
License:Apache License
/** * @param actor//ww w. j a va 2 s.c om * @param sizeX * @param sizeY * @return */ public static Actor normalizeSize(Actor actor, float sizeX, float sizeY) { if (sizeX < 0.0) { sizeX = 0; } else if (sizeX > 1) { sizeX = 1; } if (sizeY < 0.0) { sizeY = 0; } else if (sizeY > 1) { sizeY = 1; } actor.setWidth(sizeX * S3Screen.width); actor.setHeight(sizeY * S3Screen.height); return actor; }
From source file:mobi.shad.s3lib.gui.widget.HtmlView.java
License:Apache License
private void addActor(final Element element, final Actor actor, final Table mainTable) { CssStyle style = parseCssStyle(element); mainTable.row();//ww w . jav a2s. c om String src = element.getAttribute("src", ""); String align = element.getAttribute("align", ""); int width = element.getIntAttribute("width", 0); int height = element.getIntAttribute("height", 0); int collSpan = element.getIntAttribute("collspan", 1); int padding = element.getIntAttribute("padding", 0); int cellwidth = element.getIntAttribute("cellwidth", 0); int cellheight = element.getIntAttribute("cellheight", 0); int fill = element.getIntAttribute("fill", 0); int size = element.getIntAttribute("size", S3Constans.textureImageSize); int length = 0; if (element.getText() != null) { length = element.getText().length(); } if (width > 0) { actor.setWidth(width); } if (height > 0) { actor.setHeight(height); } if (align.equalsIgnoreCase("center")) { mainTable.row(); Cell cell = mainTable.add(actor).center().colspan(collSpan).pad(padding); if (width > 0) { cell.width(width); } if (height > 0) { cell.height(height); } if (cellwidth > 0) { cell.width(cellwidth); } if (cellheight > 0) { cell.height(cellheight); } if (fill > 0) { cell.fill(); } if (length > 0) { mainTable.row(); addTableNode(element, style, mainTable); } } else if (align.equalsIgnoreCase("left")) { mainTable.row(); Cell cell = mainTable.add(actor).left().colspan(collSpan).pad(padding).uniform(); if (width > 0) { cell.width(width); } if (height > 0) { cell.height(height); } if (cellwidth > 0) { cell.width(cellwidth); } if (cellheight > 0) { cell.height(cellheight); } if (fill > 0) { cell.fill(); } if (length > 0) { addTableNode(element, style, mainTable); } } else if (align.equalsIgnoreCase("right")) { mainTable.row(); if (length > 0) { addTableNode(element, style, mainTable); } Cell cell = mainTable.add(actor).right().colspan(collSpan).pad(padding).uniform(); if (width > 0) { cell.width(width); } if (height > 0) { cell.height(height); } if (cellwidth > 0) { cell.width(cellwidth); } if (cellheight > 0) { cell.height(cellheight); } if (fill > 0) { cell.fill(); } } else { mainTable.row(); Cell cell = mainTable.add(actor).colspan(collSpan).pad(padding); if (width > 0) { cell.width(width); } if (height > 0) { cell.height(height); } if (cellwidth > 0) { cell.width(cellwidth); } if (cellheight > 0) { cell.height(cellheight); } if (fill > 0) { cell.fill(); } if (length > 0) { addTableNode(element, style, mainTable); } } }
From source file:net.mwplay.cocostudio.ui.DemoScreen.java
License:Apache License
private void initDemoChange(InputMultiplexer multiplexer) { Stage demoChangeStage = new Stage(new StretchViewport(DemoGame.GAME_WIDTH, DemoGame.GAME_HEIGHT)); Actor actor = new Actor(); actor.setWidth(stage.getWidth()); actor.setHeight(stage.getHeight());/*w w w .j a va 2 s . c o m*/ actor.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { updateCurrentIndex(); changeDemo(); } }); demoChangeStage.addActor(actor); multiplexer.addProcessor(demoChangeStage); }
From source file:org.ams.core.SceneUtil.java
License:Open Source License
public static void fillAndCenter(Stage stage, Actor actor) { actor.setWidth(stage.getWidth()); actor.setHeight(stage.getHeight());/*from w w w. j a v a 2s . c om*/ float x = stage.getWidth() * 0.5f; float y = stage.getHeight() * 0.5f; actor.setPosition(x, y, Align.center); }