TextArea is superpowered version of TextField.
TextArea has normal anchoring as opposed to TextField and supports multiline text with different alignment modes, first-line indentation and other settings to fine-tune it.
TextArea can be created with:
TextArea.new(font, text, sample, align, width, letterspace, linespace) |
where
font = TTFont | Font
text = string
sample = string | nil
align = "L" | "C" | "R" | "J" | nil
width = number | nil
letterspace = number | nil
linespace = number | nil |
`font` and `text` parameters are same as for TextField.
`sample` is a string which overwrites a height of `text` and optionally adds first-line indentation. For example, if you have "note" text and "|" sample the result will have "|" height so all lines will have same height. To enable first-line indentation you need to use `width` parameter` and prefix `sample` with spaces. Each line after '\n' chars will be indented. If sample is not defined then it will be copied from `text`.
`align` is alignment for multiline text an can be the following char: "L" (left) | "C" (center) | "R" (right) | "J" (justified). If `align` is not defined then you will get oneline text.
`width` is optional width of multiline text. When defined the text will be automatically splitted into lines to fit into this width. If not defined then text will be splitted by '\n' chars.
`letterspace` is a space between characters so you can narrow or widen the text with it.
`linespace` is a space between lines for multiline text. It will be added to normal height of lines (i.e. to height of `sample`).
TextArea has following setters and getters:
setText - getText
setSample - getSample
setAlignment - getAlignment
setLetterSpacing - getLetterSpacing
setLineSpacing - getLineSpacing
setTextColor - getTextColor |
Example:
local font = TTFont.new("Airstream.ttf", 40)
local text = [[
The MIT License (MIT)
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.]]
local textarea = TextArea.new(font, text, " fg|", "J", 800, 0, -10)
textarea:setTextColor(0x0088BB)
stage:addChild(textarea) |
The result is attached jpg.
Hint: In order to get better justified text you need to use higher font size and then downscale the result. This is because TextField.setLetterSpacing function rounds down it's arguments which internally used by TextArea class for text justification ("J"-alignment).
Comments
Does TextArea allow adding a single line of text?
Only this way:
First, add, say, 10 TextAreas + 1 extra TextArea to a Sprite and add offsetY (between 0 and lineheight) field. Then setClip to that Sprite and while scrolling update each textarea with a text. So you can have huge text database with minimal performance overhead.
P.S. I am currently working on good demos/tutorials for my upcoming Gideros GUI library which supports all stuff your need, so you can just wait a little for it
Likes: antix, rolfpancake, pie, hotbuttered
=D>
@totebo, I published my LogWindow class back in January . It has everything you require, except history and scrolling which would be pretty easy to add. I've just updated it my thread (http://giderosmobile.com/forum/discussion/6257/simple-log-window-class#Item_1) to be the same one that I use currently in my RogueLike game.
Likes: totebo
Likes: n1cke
Likes: totebo
For now you can feast your eyes on touchscreen keyboard
Likes: simwhi, SinisterSoft, antix, totebo, pie, rolfpancake
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: keszegh, pie, antix, simwhi
Fragmenter - animated loop machine and IKONOMIKON - the memory game