com.badlogic.gdx.scenes.scene2d.ui.Cell Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Cell. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicTable.java    From talos with Apache License 2.0 6 votes vote down vote up
public Cell addRow(Actor actor, boolean left) {
    Cell cell;
    if(left) {
        cell = add(actor).left().expandX();
    } else {
        cell = add(actor).right().expandX();
    }
    row();

    if(!rows.contains(actor, true)) {
        rows.add(actor);
        align.add(left);
    }

    return cell;
}
 
Example #2
Source File: FromToModuleWrapper.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureSlots() {
    Cell fromCell = addInputSlot("from", FromToModule.FROM);
    Cell toCell = addInputSlot("to", FromToModule.TO);
    fromLabel = getLabelFromCell(fromCell);
    toLabel = getLabelFromCell(toCell);

    addOutputSlot("rotation", FromToModule.ROTATION);
    addOutputSlot("size", FromToModule.LENGTH);
    addOutputSlot("position", FromToModule.POSITION);

    dragFrom = new DragPoint(-1, 0);
    dragTo = new DragPoint(1, 0);
    if(module != null) {
        module.setDefaults(dragFrom.position, dragTo.position);
    }
}
 
Example #3
Source File: TutorialMessageWindow.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void initialize() {
    Table table = new Table(Config.skin);
    table.setBackground(Config.skin.getDrawable("ui-tutorial-window-background"));

    label = new LocLabel("", DieMessageWindow.ACTIVE);
    label.setWrap(true);
    label.setAlignment(Align.center);

    table.setTouchable(Touchable.disabled);

    Label tapToContinue = new LocLabel("tap-to-continue", DieMessageWindow.INACTIVE);
    tapToContinue.setWrap(true);
    tapToContinue.setAlignment(Align.center);

    if (image != null) {
        image.setTouchable(Touchable.disabled);
        table.add(image).padTop(-15 - dy).row();
    }
    final Cell<LocLabel> cell = table.add(label).width(100);
    if (forceLabelHeight) cell.height(labelHeight);
    cell.row();
    table.add(new Image(Config.skin, "ui-tutorial-window-line")).padTop(4).row();
    table.add(tapToContinue).width(80).row();

    this.table.add(table);
}
 
Example #4
Source File: CenteredTableBuilder.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
protected void fillTable (final Table table) {
	final IntArray rowSizes = getRowSizes();
	final int widgetsInRow = getLowestCommonMultiple(rowSizes);

	for (int rowIndex = 0, widgetIndex = 0; rowIndex < rowSizes.size; rowIndex++) {
		final int rowSize = rowSizes.get(rowIndex);
		final int currentWidgetColspan = widgetsInRow / rowSize;
		boolean isFirst = shouldExpand(rowSize);

		for (final int totalWidgetsBeforeRowEnd = widgetIndex + rowSize; widgetIndex < totalWidgetsBeforeRowEnd; widgetIndex++) {
			final Cell<?> cell =
					getWidget(widgetIndex).buildCell(table, getDefaultWidgetPadding()).colspan(
							currentWidgetColspan);
			// Keeping widgets together - expanding X for first and last widget, setting alignments:
			if (isFirst) {
				isFirst = false;
				cell.expandX().right();
			} else if (isLast(widgetIndex, rowSize, totalWidgetsBeforeRowEnd)) {
				cell.expandX().left();
			}
		}
		table.row();
	}
}
 
Example #5
Source File: CraftingScreen.java    From TerraLegion with MIT License 6 votes vote down vote up
private void populateCraftableItems(ItemCategory category) {
	craftingTable.clear();
	currentCategory = category;
	itemNameLabel.setText("");
	itemInfoLabel.setText("");

	Array<CraftingRecipe> recipes = CraftingRecipes.getInstance().getCraftableItems(category);

	int y = 0;
	for (int i = 0; i < recipes.size; i++) {
		ItemStack stack = recipes.get(i).getCraftedItemStack();
		ItemBox box = new ItemBox(stack, String.valueOf(i));
		Cell<Table> cell = craftingTable.add((Table) box).width(60).height(60).padRight(10).padBottom(10);
		if (i % MAX_TABLE_WIDTH == 0) {
			cell.padLeft(10);
		}
		if (y == 0) {
			cell.padTop(10);
		}
		if ((i + 1) % MAX_TABLE_WIDTH == 0) {
			craftingTable.row();
			y++;
		}
	}
}
 
Example #6
Source File: TooltipLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    VisLabel lblText = new VisLabel(parser.parseString(rawAttributeData, actor));
    lblText.setAlignment(Align.center);
    boolean needLineWrap = lblText.getPrefWidth() > LINE_WRAP_THRESHOLD;
    if (needLineWrap) {
        lblText.setWrap(true);
    }

    final Tooltip tooltip = new Tooltip();
    tooltip.clearChildren(); // Removing empty cell with predefined paddings.
    Cell<VisLabel> tooltipCell = tooltip.add(lblText).center().pad(0f, 4f, 2f, 4f);
    if (needLineWrap) { tooltipCell.width(LINE_WRAP_THRESHOLD); }
    tooltip.pack();
    tooltip.setTarget(actor);
}
 
Example #7
Source File: TabbedPane.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private void initialize () {

		setTouchable(Touchable.enabled);
		tabTitleTable = new Table();
		tabBodyStack = new Stack();
		selectedIndex = -1;

		// Create 1st row
		Cell<?> leftCell = add(new Image(style.titleBegin));
		Cell<?> midCell = add(tabTitleTable);
		Cell<?> rightCell = add(new Image(style.titleEnd));
		switch (tabTitleAlign) {
		case Align.left:
			leftCell.width(((Image)leftCell.getActor()).getWidth()).bottom();
			midCell.left();
			rightCell.expandX().fillX().bottom();
			break;
		case Align.right:
			leftCell.expandX().fillX().bottom();
			midCell.right();
			rightCell.width(((Image)rightCell.getActor()).getWidth()).bottom();
			break;
		case Align.center:
			leftCell.expandX().fillX().bottom();
			midCell.center();
			rightCell.expandX().fillX().bottom();
			break;
		default:
			throw new IllegalArgumentException("TabbedPane align must be one of left, center, right");
		}

		// Create 2nd row
		row();
		Table t = new Table();
		t.setBackground(style.bodyBackground);
		t.add(tabBodyStack);
		add(t).colspan(3).expand().fill();
	}
 
Example #8
Source File: PopupMenu.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Actor> Cell<T> add (T actor) {
	if (actor instanceof MenuItem) {
		throw new IllegalArgumentException("MenuItems can be only added to PopupMenu by using addItem(MenuItem) method");
	}

	return super.add(actor);
}
 
Example #9
Source File: CellWidget.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void applyFillingData (final Cell<?> cell) {
	if (alignment != null) {
		alignment.apply(cell);
	}
	cell.expand(expandX, expandY);
	cell.fill(fillX, fillY);
}
 
Example #10
Source File: CellWidget.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void applySizeData (final Cell<?> cell) {
	if (width > IGNORED_SIZE) {
		cell.width(width);
	}
	if (height > IGNORED_SIZE) {
		cell.height(height);
	}
	if (minWidth > IGNORED_SIZE) {
		cell.minWidth(minWidth);
	}
	if (minHeight > IGNORED_SIZE) {
		cell.minHeight(minHeight);
	}
}
 
Example #11
Source File: CellWidget.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void applyPadding (final Cell<?> cell, final Padding defaultWidgetPadding) {
	final Padding appliedPadding = Nullables.getOrElse(padding, defaultWidgetPadding);
	if (appliedPadding != null) {
		if (useSpacing) {
			appliedPadding.applySpacing(cell);
		} else {
			appliedPadding.applyPadding(cell);
		}
	}
}
 
Example #12
Source File: CellWidget.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * @param table will contain a cell with the object's widget with specified cell settings.
 * @param defaultWidgetPadding will be applied to the cell if padding was not specified. Can be null.
 * @return a reference to the built cell.
 */
public Cell<?> buildCell (final Table table, final Padding defaultWidgetPadding) {
	final Cell<?> cell = table.add(widget);

	applyPadding(cell, defaultWidgetPadding);
	applySizeData(cell);
	applyFillingData(cell);

	return cell;
}
 
Example #13
Source File: VisTable.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Adds vertical or horizontal {@link Separator} widget to table with padding top, bottom 2px with fill and expand properties.
 * If vertical == false then inserts new row after separator (not before!)
 */
public Cell<Separator> addSeparator (boolean vertical) {
	Cell<Separator> cell = add(new Separator(vertical ? "vertical" : "default")).padTop(2).padBottom(2);

	if (vertical)
		cell.fillY().expandY();
	else {
		cell.fillX().expandX();
		row();
	}

	return cell;
}
 
Example #14
Source File: ToastManager.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** Displays basic toast with provided text as message. Toast will be displayed for given amount of seconds. */
public Toast show (String text, float timeSec) {
	VisTable table = new VisTable();
	Cell<Label> cell = table.add(text).grow();
	cell.getActor().setTouchable(Touchable.disabled);
	return show(table, timeSec);
}
 
Example #15
Source File: PagedScrollPane.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void setWidth (float width) {
	super.setWidth(width);
	if (content != null) {
		for (Cell<?> cell : content.getCells()) {
			cell.width(width);
		}
		content.invalidate();
	}
}
 
Example #16
Source File: UIWindow.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void updateSizeImageButtons(Actor actor) {
	final ImageButton button = (ImageButton) actor;
	if (button.getImage() != null) {
		final Cell<Actor> cell = this.getCell(actor);
		cell.size(Gdx.graphics.getWidth() / BUTTON_WIDTH_FACTOR, Gdx.graphics.getHeight() / BUTTON_HEIGHT_FACTOR);
		button.setBounds(cell.getActorX(), cell.getActorY(), Gdx.graphics.getWidth() / BUTTON_WIDTH_FACTOR, Gdx.graphics.getHeight() / BUTTON_HEIGHT_FACTOR);
	}
}
 
Example #17
Source File: PagedScrollPane.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void setPageSpacing (float pageSpacing) {
	if (content != null) {
		content.defaults().space(pageSpacing);
		for (Cell<?> cell : content.getCells()) {
			cell.space(pageSpacing);
		}
		content.invalidate();
	}
}
 
Example #18
Source File: EditDialog.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void setVisible(InputPanel i, boolean v) {
	i.setVisible(v);
	Cell<InputPanel> c = getCenterPanel().getCell(i);

	if (v) {
		c.height(i.getPrefHeight());
	} else {
		c.height(1);
	}

	i.invalidateHierarchy();
}
 
Example #19
Source File: MenuItem.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Cell<?> getLabelCell () {
	return getCell(label);
}
 
Example #20
Source File: MenuItem.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Cell<Image> getSubMenuIconCell () {
	return subMenuIconCell;
}
 
Example #21
Source File: MenuItem.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Cell<VisLabel> getShortcutCell () {
	return getCell(shortcutLabel);
}
 
Example #22
Source File: MenuItem.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Cell<?> getImageCell () {
	return getCell(image);
}
 
Example #23
Source File: VisImageButton.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Cell<?> getImageCell () {
	return getCell(image);
}
 
Example #24
Source File: TabbedPane.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
/** @return separator cell or null if separator is not used */
public Cell<Image> getSeparatorCell () {
	return separatorCell;
}
 
Example #25
Source File: TabbedPane.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Cell<DragPane> getTabsPaneCell () {
	return tabsPaneCell;
}
 
Example #26
Source File: TabbedPane.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
private void setPaneCells (Cell<DragPane> tabsPaneCell, Cell<Image> separatorCell) {
	this.tabsPaneCell = tabsPaneCell;
	this.separatorCell = separatorCell;
}
 
Example #27
Source File: ContainerPadLeftLmlAttribute.java    From gdx-vfx with Apache License 2.0 4 votes vote down vote up
@Override
protected void applyToCell(final Container<?> actor, final Cell<?> cell) {
    cell.padLeft(actor.getPadLeft()); // Any could do, height(Value) sets all.
}
 
Example #28
Source File: TabbedPane.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public TabbedPane (TabbedPaneStyle style, Sizes sizes) {
	this.style = style;
	this.sizes = sizes;
	listeners = new Array<TabbedPaneListener>();

	sharedCloseActiveButtonStyle = VisUI.getSkin().get("close-active-tab", VisImageButtonStyle.class);

	group = new ButtonGroup<Button>();

	mainTable = new TabbedPaneTable(this);
	tabsPane = new DragPane(style.vertical ? new VerticalFlowGroup() : new HorizontalFlowGroup());
	configureDragPane(style);

	mainTable.setBackground(style.background);

	tabs = new Array<Tab>();
	tabsButtonMap = new IdentityMap<Tab, TabButtonTable>();

	Cell<DragPane> tabsPaneCell = mainTable.add(tabsPane);
	Cell<Image> separatorCell = null;

	if (style.vertical) {
		tabsPaneCell.top().growY().minSize(0, 0);
	} else {
		tabsPaneCell.left().growX().minSize(0, 0);
	}

	//note: if separatorBar height/width is not set explicitly it may sometimes disappear
	if (style.separatorBar != null) {
		if (style.vertical) {
			separatorCell = mainTable.add(new Image(style.separatorBar)).growY().width(style.separatorBar.getMinWidth());
		} else {
			mainTable.row();
			separatorCell = mainTable.add(new Image(style.separatorBar)).growX().height(style.separatorBar.getMinHeight());
		}
	} else {
		//make sure that tab will fill available space even when there is no separatorBar image set
		if (style.vertical) {
			mainTable.add().growY();
		} else {
			mainTable.add().growX();
		}
	}

	mainTable.setPaneCells(tabsPaneCell, separatorCell);
}
 
Example #29
Source File: Tooltip.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public Cell<Actor> getContentCell () {
	return contentCell;
}
 
Example #30
Source File: InventoryScreen.java    From TerraLegion with MIT License 4 votes vote down vote up
@Override
public void create() {
	camera = new OrthoCamera();
	camera.resize();

	stageSb = new SpriteBatch();
	stage = new Stage(new StretchViewport(Settings.getWidth(), Settings.getHeight()), stageSb);

	ScrollPane.ScrollPaneStyle paneStyle = new ScrollPane.ScrollPaneStyle();
	paneStyle.background = new TextureRegionDrawable(new TextureRegion(ResourceManager.getInstance().getTexture("invStageBg")));
	//paneStyle.vScrollKnob = new TextureRegionDrawable();
	//paneStyle.hScroll = paneStyle.hScrollKnob = paneStyle.vScroll = paneStyle.vScrollKnob;

	Table invContainer = CachePool.getTable();
	invContainer.setCullingArea(new Rectangle(0, 0, Settings.getWidth(), Settings.getHeight()));
	usedTablesCache.add(invContainer);

	float startX = (Settings.getWidth() / 2) - 255;
	invContainer.setBounds(startX, 0, 370, Settings.getHeight() - 61);

	table = CachePool.getTable();
	table.setCullingArea(new Rectangle(0, 0, Settings.getWidth(), Settings.getHeight()));
	table.addListener(new InventoryButtonClickListener(table));
	usedTablesCache.add(table);

	ScrollPane pane = new ScrollPane(table, paneStyle);
	pane.setCancelTouchFocus(false);
	pane.setCullingArea(new Rectangle(0, 0, Settings.getWidth(), Settings.getHeight()));

	invContainer.add(pane).width(370).height(Settings.getHeight() - 61);
	invContainer.row();
	stage.addActor(invContainer);

	itemNameLabel = new Label("", ResourceManager.getInstance().getFont("font"), startX + 370 + 10, Settings.getHeight() - 61 - 35, false);
	itemInfoLabel = new MultilineLabel("", ResourceManager.getInstance().getFont("font"), startX + 370 + 10, Settings.getHeight() - 61 - 85, false);

	for (int y = 0; y < inventory.getHeight(); y++) {
		for (int x = 0; x < inventory.getWidth(); x++) {

			ItemStack stack = inventory.getItemStack(x, y);
			ItemBox box = new ItemBox(stack, x, y, x + " " + y);
			InventoryDragListener dragListener = getDragListener(box);
			dragListener.setScrollPane(pane);
			dragListener.setTableHolder(table);
			dragListener.setInventory(inventory);
			box.addListener(dragListener);

			Cell<Table> cell = table.add((Table) box).width(60).height(60).padRight(10).padBottom(10);
			if (x == 0) {
				cell.padLeft(10);
			}
			if (y == 0) {
				cell.padTop(10);
			}
		}
		table.row();
	}
	InputController.getInstance().addInputProcessor(stage);
}