This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
the_dmx's profile picture

Label wrap for touchpoint API.

Started by the_dmx, 22 September 2013 - 12:17 PM
the_dmx #1
Posted 22 September 2013 - 02:17 PM
Im just learning Lua. And wondering how I can get label text to wrap to the next line inside of the button instead of trimmed?
Lyqyd #2
Posted 22 September 2013 - 02:26 PM
Split into new topic.

Well, that is a good question. I'll look at the code real quick and see if it'll be a tremendous pain to change that.

What are you looking to have the button say, out of curiousity?
the_dmx #3
Posted 22 September 2013 - 02:41 PM
I'm writing a mystcraftportal controller.

example:
pg1:add("The_dmx House", b1_1, 1, 5, 7, 9, colors.red, colors.lime)

The_dmx House gets cut off.
Lyqyd #4
Posted 29 September 2013 - 05:26 PM
I've added a new optional way to specify button labels. Instead of passing a string, you can pass a table if you need further control of the button label. You could specify your button this way instead, to take advantage of this new option:


pg1:add({"	   ","	   ","The_dmx"," House ","	   ",label = "The_dmx House"}, b1_1, 1, 5, 7, 9, colors.red, colors.lime)

Note that you have to fully specify the characters for every line of the label, including spaces, so this is an option for advanced use. You can also separate out the table to make it easier to read, of course, like so:


local houseLabel = {
    "	   ",
    "	   ",
    "The_dmx",
    " House ",
    "	   ",
    label = "The_dmx House"
}

pg1:add(houseLabel, b1_1, 1, 5, 7, 9, colors.red, colors.lime)
jay5476 #5
Posted 29 September 2013 - 08:10 PM
lyqyd why not do it like term.write does and cut off at whitespaces if to big but that may be
I'll look at the code real quick and see if it'll be a tremendous pain to change that.
Lyqyd #6
Posted 29 September 2013 - 08:32 PM
Because I think that providing these two options is a good balance between simplicity and power. A user providing just a string gets that string, as much as will fit in one line, centered in the button. A user needing more control over it provides a table of each line of the button. Trying to take the textual label and word-wrap it would quickly get rather nasty, and I'm just not interested in getting that much bloat into the touchpoint API.
the_dmx #7
Posted 02 October 2013 - 02:07 AM
wow awesome! thank you much for the time you put into this Lyqyd! I'll give this a go asap.