Class FoliosText
java.lang.Object
net.ixdarklord.folios.api.client.page.FoliosText
Text written for a book, set out in lines to a width. It is a small part of Markdown, so long text reads well in
a JSON file:
- A line is a line; an empty line starts a new paragraph.
# Headingand## Smaller heading;---alone is a dividing rule.- item(or* item) is a bullet,1. itema numbered one; two spaces before nest it.> textis set apart as a note.**bold**,*italic*(or_italic_),__underlined__,~~struck~~,`code`.[label](target)links to an entry (entry:id,entry:id#markeror the bare id), a category (category:id), an item's page (item:minecraft:diamond) or a web page (https://...).- Tags in braces:
{#FF8800}coloured{/}colours text;{key:key.jump}names the key bound to something;{player}is the reader's name;{item:minecraft:diamond}an item's name, linking to its page when the book has one;{entry:tools/scribe#scribe}a link with the entry's name;{flag:mymod:hard_mode|on text|off text}text by a flag;{lang:key|first|second}a translation, itself read as this markup, its%sfilled from the rest. A tag that doesn't parse is shown as written. - A backslash keeps the next character as it is:
\*, invalid input: '{@code \{}.</li> </ul> Text that is a translation key as a whole is translated first. In JSON, a text field takes either a string of this markup or {@code {"translate": "key", "with": [...], "fallback": "..."}} ({@link #CODEC}), so a book can keep all its words in lang files.'
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhat a line is part of, which decides how it is drawn.static final recordOne line, at (x, y) from the text's top left. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<String> Text as JSON writes it: a string of this markup, or{"translate": "key", "with": ["first"], "fallback": "text"}for a translation (the arguments and fallback are markup too).static final intstatic final StringThe insertion text of a link's characters starts with this; the rest is where it goes. -
Method Summary
Modifier and TypeMethodDescriptionvoiddraw(FoliosPainter painter, int x, int y) Draws the text with its top left at (x, y), its links pressable.static booleanhasTranslation(String key) Whether the language has text for a translation key.intheight()From the top of the first line to the bottom of the last.static <T> Tin(FoliosBook book, Supplier<T> read) Runs something with a book as the one text is read for: its{entry:...}tags take its entries' names, and{item:...}links to its pages.static net.minecraft.network.chat.ComponentOne line of marked-up text (a title or a label) as a component; block marks are kept as written.static booleanWhether text comes to nothing once read (a translation with an empty fallback and no key, say).booleanisEmpty()lines()lineTops()Where each line starts down the text, top first, each once: where a window of it can start.static FoliosTextReads marked-up text and sets it out in lines no wider thanwidth.static FoliosTextof(net.minecraft.client.gui.Font font, String raw, int width, @Nullable FoliosAlign align) Asof(Font, String, int), its lines aligned: null orFoliosAlign.LEFTas written.static StringText without its marks, for searching.static Stringread(com.google.gson.JsonElement json) Text from JSON, asCODECreads it.static StringThe text a raw string stands for: its translation if it is a translation key, with each{lang:...}put in its place.split(int firstHeight, int nextHeight) Splits the text into pieces that fit: the firstfirstHeighttall, the restnextHeight.static Stringtranslation(String key, List<String> with, @Nullable String fallback) Markup for a translation,{lang:key|with...}, with what to show if there is no such key (null to show the key).intwidth()The width it was set out to.intwidth(net.minecraft.client.gui.Font font) The widest line.window(int from, int height) The lines that lie whole betweenfromandfrom + heightdown the text, starting again at y 0.
-
Field Details
-
LINK
The insertion text of a link's characters starts with this; the rest is where it goes.- See Also:
-
LINE_HEIGHT
public static final int LINE_HEIGHT- See Also:
-
CODEC
Text as JSON writes it: a string of this markup, or{"translate": "key", "with": ["first"], "fallback": "text"}for a translation (the arguments and fallback are markup too). Either way it is read as a string of markup.
-
-
Method Details
-
lines
-
height
public int height()From the top of the first line to the bottom of the last. -
width
public int width()The width it was set out to. -
isEmpty
public boolean isEmpty() -
read
-
translation
-
hasTranslation
Whether the language has text for a translation key. -
isBlank
Whether text comes to nothing once read (a translation with an empty fallback and no key, say). -
in
Runs something with a book as the one text is read for: its{entry:...}tags take its entries' names, and{item:...}links to its pages. A book sets itself while it lays out its pages and searches them. -
resolve
-
inline
One line of marked-up text (a title or a label) as a component; block marks are kept as written. -
plain
-
of
Reads marked-up text and sets it out in lines no wider thanwidth. -
of
public static FoliosText of(net.minecraft.client.gui.Font font, String raw, int width, @Nullable FoliosAlign align) Asof(Font, String, int), its lines aligned: null orFoliosAlign.LEFTas written. A paragraph written->like this<-is centred, and->like thisright-aligned, whatever the rest is. -
split
Splits the text into pieces that fit: the firstfirstHeighttall, the restnextHeight. A heading is never left alone at the foot of a piece. Each piece's lines start again at y 0. -
lineTops
-
window
The lines that lie whole betweenfromandfrom + heightdown the text, starting again at y 0. -
draw
Draws the text with its top left at (x, y), its links pressable. -
width
public int width(net.minecraft.client.gui.Font font) The widest line.
-