001package squidpony.squidgrid.gui.gdx; 002 003/** 004 * Interface to build instances of {@link SquidPanel} by taking care of 005 * adjusting the panel to the screen size and the available fonts. 006 * 007 * @author smelC 008 */ 009public interface IPanelBuilder { 010 011 /** 012 * This method builds a panel whose number of cells is such that the cell 013 * size is close to {@code desiredCellSize}. This method only supports 014 * square cells. 015 * 016 * @param screenWidth 017 * The screen's width, in number of pixels, as given by libgdx. 018 * @param screenHeight 019 * The screen's height, in number of pixels, as given by libgdx. 020 * @param desiredCellSize 021 * The cell size that you would like the panel to have. Width and 022 * height cannot be different, because this method supports only 023 * square cells. 024 * @param tcf 025 * The {@link TextCellFactory} to use. Can be {@code null} to 026 * create the panel. 027 * @return A screen wide squid panel, margins-aware, and with its position 028 * set. 029 */ 030 SquidPanel buildScreenWide(int screenWidth, int screenHeight, int desiredCellSize, 031 /* @Nullable */ TextCellFactory tcf); 032 033 /** 034 * Builds a panel by the number of requested cells. 035 * 036 * @param hCells 037 * The number of horizontal cells of the panel to build. 038 * @param vCells 039 * The number of vertical cells of the panel to build. 040 * @param cellWidth 041 * The width of a cell (in pixels). 042 * @param cellHeight 043 * The height of a cell (in pixels). 044 * @param tcf_ 045 * The text cell factory to use, if any. 046 * @return A freshly built panel. 047 */ 048 SquidPanel buildByCells(int hCells, int vCells, int cellWidth, int cellHeight, 049 /* @Nullable */ TextCellFactory tcf_); 050 051 /** 052 * @param sz 053 * @return A cell size close to {@code sz} that can be displayed (i.e. for 054 * which there's a font, according to 055 * {@link #fontSizeForCellSize(int)} and {@link #hasFontOfSize(int)} 056 * ). 057 */ 058 int adjustCellSize(int sz); 059 060 /** 061 * Method to check whether increasing the cell size is possible. 062 * 063 * @param cellSize 064 * @return {@code true} if {@code cellSize} is too big. 065 */ 066 boolean cellSizeTooBig(int cellSize); 067 068 /** 069 * Method to check whether decreasing the cell size is possible. 070 * 071 * @param cellSize 072 * @return {@code true} if {@code cellSize} is too small. 073 */ 074 boolean cellSizeTooSmall(int cellSize); 075 076 /** 077 * @param cellSize 078 * @return Whether there's a font available for a cell of size 079 * {@code cellSize}. 080 */ 081 boolean hasFontForCellOfSize(int cellSize); 082 083 /** 084 * @param cellSize 085 * @return The font size to use for a square cell size of {@code cellSize}. 086 * Generally, it is {@code cellSize}; but it can be less in case 087 * glyphs are too large. 088 */ 089 int fontSizeForCellSize(int cellSize); 090 091 /** 092 * @param sz 093 * @return Whether a square font of size {@code sz} is available. 094 */ 095 boolean hasFontOfSize(int sz); 096 097 /** 098 * A partial implementation of {@link IPanelBuilder}. 099 * 100 * @author smelC 101 */ 102 abstract class Skeleton implements IPanelBuilder { 103 104 @Override 105 public boolean hasFontForCellOfSize(int cellSize) { 106 return hasFontOfSize(fontSizeForCellSize(cellSize)); 107 } 108 109 } 110}