-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Padding #12
Comments
Greetings and thank you for your interest in my project! So, in the current context, I must admit its a bit confusing since this project is table/cell based and in that context, I'm considering renaming the In the meantime, here's how to accomplish what you're looking for: import com.inamik.text.tables.Cell;
import com.inamik.text.tables.GridTable;
import com.inamik.text.tables.SimpleTable;
import com.inamik.text.tables.grid.Border;
import com.inamik.text.tables.grid.Util;
import java.util.Collection;
import static com.inamik.text.tables.Cell.Functions.BOTTOM_PAD;
import static com.inamik.text.tables.Cell.Functions.LEFT_PAD;
import static com.inamik.text.tables.Cell.Functions.RIGHT_PAD;
import static com.inamik.text.tables.Cell.Functions.TOP_PAD;
class Scratch {
public static void main(String[] args) {
// Manually build the cell with content
//
Collection<String> cell = Cell.of();
cell = Cell.append(cell, "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");
cell = Cell.append(cell, "Duis risus. Nullam rhoncus aliquam metus.");
// Determine width and height of actual content
//
int cellWidth = getCellWidth (cell);
int cellHeight = getCellHeight(cell);
// Always apply TOP/BOTTOM padding *before* LEFT/RIGHT padding
//
SimpleTable simpleTable = SimpleTable.of()
.nextRow()
.nextCell(cell)
// Expand to current height + 5, adding new lines to TOP
//
.applyToCell(TOP_PAD .withHeight(cellHeight + 5 ))
// Expand to new-current-height + 5, adding new lines to the BOTTOM
//
.applyToCell(BOTTOM_PAD.withHeight(cellHeight + 5 + 5))
// Expand to current width + 5, adding new lines to the LEFT
//
.applyToCell(LEFT_PAD .withWidth (cellWidth + 5 ))
// Expand to new-current-width + 5, adding new lines to the RIGHT
//
.applyToCell(RIGHT_PAD .withWidth (cellWidth + 5 + 5))
;
GridTable g = simpleTable.toGrid();
g = Border.DOUBLE_LINE.apply(g);
System.out.println(Util.asString(g)); }
static int getCellWidth(Collection<String> cell) {
int width = 0;
for (String line: cell) {
width = Math.max(width, line.length());
}
return width;
}
static int getCellHeight(Collection<String> cell) {
return cell.size();
}
} Should generate the following output:
The keys here are :
Give that a try and let me know what you think. Thanks again for your interest in my project ! -iNamik |
Thanks very much! I had to change it to :
so that it does not align right, now it seems to work fine.
Sounds good. |
Hello,
I am trying to implement krasa/StringManipulation#169
However, there is an issue with padding:
produces:
I would expect:
The text was updated successfully, but these errors were encountered: