Sponge pagination service - format text into table-like structure

Does sponge support this feature?

Lets say i would like to display a “text table” where “columns” will adjust width according to logest string in any row.

Since its a bit hard to explain lets have a simple example.

Table 1

text1 text2 tttext3
text1 a b

Formated Table

text1 text2 tttext3
text1 a     b

Whether it’s tabled or not will entirely depend on what font is being used. Even if it’s the default one, the letters are not monowidth, and therefore it is difficult to perfectly line up text, and involves special space characters which may not display on all systems.

This looks promising: Chat UI - A UI toolkit for the vanilla chat box

And supports Unicode? :slight_smile:

If it’s ingame it’s completely possible unless a mod or resource pack is changing the font.

As @RandomByte suggested, my ChatUI plugin should be able to render a table like you wanted.

The ‘force unicode’ option currently breaks the plugin but I am working to improve support.

Edit:
I just made a quick example.
It renders outside of the framework i.e. creates a standalone Text object instead of drawing to a Tab

TableModel model = new SimpleTableModel(new Object[][] {
        {"text1", "text2", "tttext3"},
        {"text1", "a", "b"}
});
TableRenderer renderer = new BorderlessTableRenderer();
TableUI table = new TableUI(model, renderer);
// Hard coded because we're rendering outside of the framework
PlayerContext ctx = new PlayerContext(this.player, 320, 10, false);
this.player.sendMessage(table.draw(ctx));

5 Likes

Sorry to bring back a dead thread, but is there any way to do this without using ChatUI?
@simon816 is there a code snippet you can share? Is there a way to change a user’s font to a monospaced version?

Looking at your code I see that you count the pixels for each character, and then I guess you decide how many spaces to add.

I see this code section: ChatUI/TextUtils.java at 3f0fe8343b39a2714656da0ed928698b2be861a4 · simon816/ChatUI · GitHub

where you use ‘⁚’ to round out the pixels if a space (which is a few pixels) is too big.

Pretty clever!

Looks like you’ve found the relevant part of Chat UI, so you can go from there.
Since my last post, I have branched Chat UI out into a separate UI library - simon816 / Chat UI Library

This is designed to be usable by plugins and handles the low-level text manipulation, without needing the tabbed interface from Chat UI.

1 Like