yage.gui.textblock
Authors:
Eric Poggel
License:
LGPL v3
This module is dedicated to my loving wife, Brittany Poggel.
- struct
TextCursor
;
- uint
position
;
- uint
selectionStart
;
- uint
selectionEnd
;
- struct
TextBlock
;
- Render text and simple html with styles to an image.
TextBlock
has two modes of input: setHtml() and the input() function that receives keypresses.
This class is used internally by the engine. In most cases it shouldn't need to be called externally.
- Vec!(2,int)
cursorToXy
(int position);
- Get the xy pixel position of a cursor position.
Functions for converting between line/letter/cursor space and x/y position.
- int
xyToCursor
(Vec!(2,int) xy);
- Get the cursor position from an xy pixel position.
Functions for converting between line/letter/cursor space and x/y position.
- int
cursorToLine
(ref int position);
- Convert an absolute cursor position to a line/position pair.
Params:
int position |
Character position from the beginning of the TextBlock
After the function executes, this will be the position on the line returned. |
Returns:
The line number. If position is after the last line,
then the number of the last line is returned and position is an offset from this.
Functions for converting between line/letter/cursor space and x/y position.
- int
lineToCursor
(int line, int position);
- Convert a cursor line/position pair to an absolute position.
Params:
int line |
|
int position |
Position from the beginning of the line, may be negative or exceed the line length. |
Returns:
The absolute position of the cursor from the beginning of the text block.
Functions for converting between line/letter/cursor space and x/y position.
- char[]
getHtml
();
- Reverse the normal function of TextLayout and convert letters[] back to a string of html text.
The text may use different tags than the original html, (since some information is lost)
but will be functionally the same.
- void
input
(int key, int mod, dchar unicode, ref TextCursor cursor);
- Update lines and letters data structures from keyboard
input
Params:
int key |
SDL key code constant |
int mod |
modifier key. |
dchar unicode |
Unicode value of the pressed key. |
TextCursor cursor |
The Surface's TextCursor. |
- Image
render
(bool pow2 = false, TextCursor* cursor = null);
- Convert a string of primitive html text and
render
it to an image.
Note that this is currently not thread-safe, since the reusable buffers above make it non-re-entrant
and also due to the non thread-safety of using Font.
Characters with a bold font-weight are rendered at 1.5x normal width.
Characters with a italic/oblique font-style are rendered skewed.
For ideal rendering, instead use a font-family that has a bold or italic style.
Params:
style |
A style with fontSize and lineHeight in terms of pixels |
bool pow2 |
Render an image with dimensions that are a power of 2 (useful for older graphics cards) |
TextCursor* cursor |
Render this text cursor if not null
. |
Returns:
An RGBA image of width pixels wide and is shorter or equal to height.
Note that the same buffer is used for each return, so one call to this function will overwrite a previous result.
- void
setHtml
(char[] html);
- Set the contents of the Textblock with html.
Params:
char[] html |
String of utf-8 encoded html text to render.
The following html tags are supported:
a, b, br, del, i, span, sub, sup, u
The following css is supported via inline style attributes:
color, font-family, font-size[%|px], font-style[normal|italic|oblique], font-weight[normal|bold],
letter-spacing[%|px], line-height[%|px],
text-align[left|center|right] text-decoration[none|underline|overline|line-through] |
- bool
update
(Style style, int width, int height);
- Replace the text with new text, rebuilding the internal lines and letters data structures.
This is unlike input(), which modifies the text based on a single keystroke.
Params:
Style style |
A style with fontSize and lineHeight in terms of pixels |
int width |
Available width for rendering text |
int height |
Available height for rendering text. |
Returns:
True if the text will need to be re-rendered, false
otherwise.
TODO:
Should this be a constructor to maintain RAII?
|