@Override public void draw(SpriteBatch batch, float parentAlpha) { Drawable background; if (list != null && list.getParent() != null && style.backgroundOpen != null) background = style.backgroundOpen; else if (clickListener.isOver() && style.backgroundOver != null) background = style.backgroundOver; else background = style.background; final BitmapFont font = style.font; final Color fontColor = style.fontColor; Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); background.draw(batch, x, y, width, height); if (items.length > 0) { float availableWidth = width - background.getLeftWidth() - background.getRightWidth(); int numGlyphs = font.computeVisibleGlyphs( items[selectedIndex], 0, items[selectedIndex].length(), availableWidth); bounds.set(font.getBounds(items[selectedIndex])); height -= background.getBottomHeight() + background.getTopHeight(); float textY = (int) (height / 2 + background.getBottomHeight() + bounds.height / 2); font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha); font.draw( batch, items[selectedIndex], x + background.getLeftWidth(), y + textY, 0, numGlyphs); } // calculate screen coords where list should be displayed getStage().toScreenCoordinates(screenCoords.set(x, y), batch.getTransformMatrix()); }
public void setText(String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); BitmapFont font = style.font; StringBuffer buffer = new StringBuffer(); for (int i = 0; i < text.length(); i++) { if (maxLength > 0 && buffer.length() + 1 > maxLength) { break; } char c = text.charAt(i); if (font.containsCharacter(c) && (filter == null || filter.acceptChar(this, c))) buffer.append(c); } this.text = buffer.toString(); updateDisplayText(); cursor = 0; clearSelection(); textBounds.set(font.getBounds(displayText)); textBounds.height -= font.getDescent() * 2; font.computeGlyphAdvancesAndPositions(displayText, glyphAdvances, glyphPositions); }