Documentation - Mthec/BMLBuilder GitHub Wiki
Always start with a BMLBuilder
object, use the id
from the Question
class, then finish with .build()
to construct the final String
.
I tend to keep mine in one chain, so use a String variable, however you can store the current stage in a variable as well. Beware of reusing the same stage.
String bml = new BMLBuilder(id)
// add elements
.build();
There is a second constructor that allows you to define horizontal/vertical scroll, the other constructor uses true for vertical and false for horizontal, and a first line of bold text (Wurm Question
objects call this the question).
public BMLBuilder(int id, boolean vertical, boolean horizontal, String question)
BML elements all inherit from the BML
class to allow chaining of elements. Some elements also have extra methods.
Adds a line of text. Subsequent text
calls will start a new line.
.text("This is my text.")
Methods
Font style
bold()
italic()
bolditalic()
Colours
color(short r, short g, short b)
-
safe()
- green -
warning()
- yellow -
error()
- red
Alignment
center()
Hover text
hover(String text)
Adds a button. The id
is used in the returned Properties
.
.button("Send") // Uses "submit" as id
.button("my-id", "Do Something")
Methods
-
confirm(String message, String question)
When the button is clicked a Yes/No box is shown for confirmation.question
is the title of the box,message
is the text inside the box. -
hover(String text)
Add a text input. There are two methods available for this element, id
is used in the returned Properties
, value
is optional pre-filled text, and maxChars
limits the characters allowed.
.entry("my-id", 10)
.entry("my-id", "Editable text", 25)
Methods
-
onEnter(String command)
- When the Enter key is pressed whilst in theentry
box, this is sent as if it was the id of a pressed button. (Seecom.wurmonline.server.questions.ItemCreationQuestion.class
for a usage example.)
Hover text
hover(String text)
Adds a toggle-able checkbox. id
is used in the returned Properties
, label
is the label text, checked
is optional and allows preselecting of the checkbox (default is false).
.checkbox("my-id", "Label text")
.checkbox("my-id", "Label text", true)
Adds a radio option. group
is a label that prevents more than one radio in the same group being selected, id
is used in the returned Properties
, checked
is optional and allows preselecting of the radio option (default is false).
.radio("Food", "my-id1", "Label text")
.radio("Task", "my-id2", "Label text") // Different group
.radio("Food", "my-id3", "Label text", true)
Aligns the contained elements in a single row. The main use would be for aligning multiple buttons at the bottom of a dialog box. Takes a Function<BML, BML>
, which will likely be a lambda function, defining the contents of the harray
.
.harray(b -> b.button("one", "One").button("two", "Two")) // Two side-by-side buttons.
Adds a dropdown selector box. Several methods are available for creation. id
is used in the returned Properties
, options is either a List<String>
or an already combined string of comma separated entries in the dropdown, selected
is an optional index of the entry to be preselected (default is 0).
.dropdown("my-id", "one,two,three")
.dropdown("my-id", "one,two,three", 1) // "two" is preselected
.dropdown("my-id", myList)
.dropdown("my-id", myList, myList.size() - 1) // Last option is preselected
Adds a table of elements. columnTitles
is an array of String
s defining the title for each column, rowData
is a Collection<T>
whose contents will be passed to, rowBuilder
, which a BMLFor
(see below) that iterates through each item in rowData
and creates a row of BML.
.table(new String[] {"One", "Two", "Three"}, myData,
(nextObject, b) ->
b.text(nextObject.id.toString).text(nextObject.name).checkbox("id" + nextObject.id, "")
)
// Result:
// One Two Three
// 1 myName □
Operates as an un-styled Text
. Included because it has a separated meaning in BML, but I am not aware of any actual differences from text.
.label("My Label")
-
.newLine()
- Shorthand for an emptyText
element that adds a blank line. -
.spacer()
- Useful for spacing out button and other horizontal elements. -
.raw(String rawString)
- Anything missing, or you want to write something in a special way? This will add theString
as is to the current point in the BML.
You're probably best off storing the latest BML
object in a variable and using normal if/for etc. However, to keep things in a similar inline format you can use the following.
If the condition
is false
then nothing is added. Uses a Function<BML, BML>
to capture the needed elements. The last BML element comes in as the only parameter, then the last parameter is returned to be used as normal. An optional Else Function<BML, BML>' can be used, including another
If`. Just remember to use another variable name.
.If(a > 20, b -> b.text("Some text"))
.If(a > 20, b -> b.text("Higher"), b -> b.text("Not Higher"))
.If(a > 20, b -> b.text("Higher"), b ->
b.If(a < 20, b2 -> b2.text("Lower"), b2 -> b2.text("Twenty")))
Takes an Iterable<T>
and applies action
to each element.
.forEach(myList, (myObject, b) -> b.text(myObject.name).newLine())