Hi!
I try to port the
original example of NanoVG into
Michael Bickel's hx-nanovg lib with Haxe, Hxcpp windows platform. It's going well, but...
There is a function in C++:
// Breaks the specified text into lines. If end is specified only the sub-string will be used.
// White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
// Words longer than the max width are slit at nearest character (i.e. no hyphenation).
int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows);
// the used structure
struct NVGtextRow {
const char* start; // Pointer to the input text where the row starts.
const char* end; // Pointer to the input text where the row ends (one past the last character).
const char* next; // Pointer to the beginning of the next row.
float width; // Logical width of the row.
float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
};
... and in Nvg.hx the extern for this:
@:native("::nvgTextBreakLines")
public static function textBreakLines(_ctx:Pointer<NvgContext>, _string:ConstPointer<Char>, _end:ConstPointer<Char>, _breakRowWidth:Float32, _rows:Pointer<NvgTextRow>, _maxRows:Int):Int;
@:native("NVGtextRow")
extern class NvgTextRow {
/** Pointer to the input text where the row starts. **/
public var start:ConstPointer<Char>;
/** Pointer to the input text where the row ends (one past the last character). **/
public var end:ConstPointer<Char>;
/** Pointer to the beginning of the next row. **/
public var next:ConstPointer<Char>;
/** Logical width of the row. **/
public var width:Float32;
/** Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending. **/
public var minx:Float32;
/** Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending. **/
public var maxx:Float32;
}
I have a problem with the
_rows:Pointer<NvgTextRow>
variable, because the original code of the usage of this function is: (the comments are my interpretation, and maybe not correct)
NVGtextRow rows[3]; // create a 3 length array of NVGtextRow
nvgTextBreakLines(vg, start, end, width, rows, 3); // this function sets the rows variable
I can't create in Haxe the appropriate rows variable.
I tried:
var rows:Array<NvgTextRow>; // This will be in cpp: Array<Dynamic> type.
Nvg.textBreakLines(vg, start, end, width, Pointer.fromHandle(rows), 3); // error: can't covert Dynamic to NVGtextRow
How can I do this in the right way and pass a pointer of 3 length array? Can it be done in Hxcpp?
Thanks in advance!
Tom