@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) { canvas.setPart(ICON_PART); if (icon != null) { Vector2i iconSize = getIconSize(canvas); int maxHorizontalIcons = sizeHint.x / iconSize.x; int rows = ((maxIcons - 1) / maxHorizontalIcons) + 1; int columns = Math.min(maxIcons, maxHorizontalIcons); return new Vector2i(columns * iconSize.x + (columns - 1) * spacing, rows * iconSize.y + (rows - 1) * spacing); } else { return Vector2i.zero(); } }
@Override public void onDraw(Canvas canvas) { canvas.setPart(SLIDER_PART); canvas.drawBackground(); drawTicker(canvas, TICKER_LEFT_PART, valueLeft, tickerListenerLeft, false); drawTicker(canvas, TICKER_RIGHT_PART, valueRight, tickerListenerRight, true); }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) { canvas.setPart("item"); Vector2i result = new Vector2i(); for (T item : list.get()) { Vector2i preferredSize = canvas.getCurrentStyle().getMargin().grow(itemRenderer.getPreferredSize(item, canvas)); result.x = Math.max(result.x, preferredSize.x); result.y += preferredSize.y; } return result; }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) { Vector2i result = new Vector2i(); canvas.setPart(SLIDER_PART); result.x = canvas.getCurrentStyle().getFixedWidth(); if (result.x == 0) { result.x = canvas.getCurrentStyle().getMinWidth(); } result.y = canvas.getCurrentStyle().getFixedHeight(); if (result.y == 0) { result.y = canvas.getCurrentStyle().getMinHeight(); } Vector2i left = getTickerPreferredContentSize(canvas, TICKER_LEFT_PART); Vector2i right = getTickerPreferredContentSize(canvas, TICKER_RIGHT_PART); result.y = Math.max(result.y, Math.max(left.y, right.y)); result.x = Math.max(result.x, left.x + left.y); return result; }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) { canvas.setPart("handle"); int x = canvas.getCurrentStyle().getFixedWidth(); if (x == 0) { x = canvas.getCurrentStyle().getMinWidth(); } int y = canvas.getCurrentStyle().getFixedHeight(); if (y == 0) { y = canvas.getCurrentStyle().getMinHeight(); } return new Vector2i(x, y); }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) { Vector2i result = new Vector2i(); canvas.setPart(SLIDER); result.x = canvas.getCurrentStyle().getFixedWidth(); if (result.x == 0) { result.x = canvas.getCurrentStyle().getMinWidth(); } result.y = canvas.getCurrentStyle().getFixedHeight(); if (result.y == 0) { result.y = canvas.getCurrentStyle().getMinHeight(); } canvas.setPart(TICKER); int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(getDisplayText()); tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth(); result.x = Math.max(result.x, tickerWidth); if (canvas.getCurrentStyle().getFixedWidth() != 0) { result.x = Math.max(result.x, canvas.getCurrentStyle().getFixedWidth()); } else { result.x = Math.max(result.x, canvas.getCurrentStyle().getMinWidth()); } if (canvas.getCurrentStyle().getFixedHeight() != 0) { result.y = Math.max(result.y, canvas.getCurrentStyle().getFixedHeight()); } else { result.y = Math.max(result.y, canvas.getCurrentStyle().getMinHeight()); } return result; }
@Override public void onDraw(Canvas canvas) { updateItemListeners(); canvas.setPart("item");
@Override public void onDraw(Canvas canvas) { if (vertical) { canvas.setPart("sliderVertical"); } else { canvas.setPart("sliderHorizontal"); } canvas.drawBackground(); canvas.addInteractionRegion(sliderListener); canvas.setPart("handle"); if (vertical) { sliderSize = canvas.size().y - canvas.getCurrentStyle().getFixedHeight(); } else { sliderSize = canvas.size().x - canvas.getCurrentStyle().getFixedWidth(); } if (sliderSize > handleSize) { int drawLocation = pixelOffsetFor(getValue()); Rect2i handleRegion; if (vertical) { handleSize = canvas.getCurrentStyle().getFixedHeight(); handleRegion = Rect2i.createFromMinAndSize(0, drawLocation, canvas.getCurrentStyle().getFixedWidth(), handleSize); } else { handleSize = canvas.getCurrentStyle().getFixedWidth(); handleRegion = Rect2i.createFromMinAndSize(drawLocation, 0, handleSize, canvas.getCurrentStyle().getFixedHeight()); } canvas.drawBackground(handleRegion); canvas.addInteractionRegion(handleListener, handleRegion); } }
@Override public void onDraw(Canvas canvas) { canvas.setPart(SLIDER); canvas.drawBackground(); canvas.setPart(TICKER); String display = getDisplayText(); int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(display); tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth(); sliderWidth = canvas.size().x - tickerWidth; int drawLocation = pixelOffsetFor(getValue(), sliderWidth); Rect2i tickerRegion = Rect2i.createFromMinAndSize(drawLocation, 0, tickerWidth, canvas.size().y); try (SubRegion ignored = canvas.subRegion(tickerRegion, false)) { canvas.drawBackground(); canvas.drawText(display); if (isEnabled()) { canvas.addInteractionRegion(tickerListener); } } }
private Vector2i getTickerPreferredContentSize(Canvas canvas, String part) { Vector2i result = new Vector2i(); canvas.setPart(part); int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(formatString); tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth(); result.x = tickerWidth; if (canvas.getCurrentStyle().getFixedWidth() != 0) { result.x = Math.max(result.x, canvas.getCurrentStyle().getFixedWidth()); } else { result.x = Math.max(result.x, canvas.getCurrentStyle().getMinWidth()); } if (canvas.getCurrentStyle().getFixedHeight() != 0) { result.y = canvas.getCurrentStyle().getFixedHeight(); } else { result.y = canvas.getCurrentStyle().getMinHeight(); } return result; }
private void drawTicker(Canvas canvas, String part, Binding<Float> value, InteractionListener tickerListener, boolean rightTicker) { canvas.setPart(part); String display = String.format("%." + precision + "f", value.get()); int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(formatString); tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth(); sliderWidth = canvas.size().x - tickerWidth * 2; int drawLocation = pixelOffsetFor(value.get(), sliderWidth); if (rightTicker) { drawLocation += tickerWidth; } Rect2i tickerRegion = Rect2i.createFromMinAndSize(drawLocation, 0, tickerWidth, canvas.size().y); try (SubRegion ignored = canvas.subRegion(tickerRegion, false)) { canvas.drawBackground(); canvas.drawText(display); if (isEnabled()) { canvas.addInteractionRegion(tickerListener); } } }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) { canvas.setPart(TREE_NODE); if (model.get().getNodeCount() == 0) { return new Vector2i(); } model.get().setEnumerateExpandedOnly(false); Vector2i result = new Vector2i(); for (int i = 0; i < model.get().getNodeCount(); i++) { Tree<T> node = model.get().getNode(i); Vector2i preferredSize = canvas.getCurrentStyle().getMargin() .grow(itemRenderer.getPreferredSize(node.getValue(), canvas) .addX(node.getDepth() * levelIndent.get())); result.x = Math.max(result.x, preferredSize.x); result.y += preferredSize.y; } model.get().setEnumerateExpandedOnly(true); // Account for the expand/contract button! result.addX(levelIndent.get()); return result; }
@Override public void onDraw(Canvas canvas) { canvas.setPart(ICON_PART); if (icon != null && getMaxValue() > 0) { Vector2i iconSize = getIconSize(canvas);