drawTextList static method
dynamic
drawTextList(
- dynamic canvas,
- dynamic textList,
- dynamic font
Implementation
static drawTextList(canvas, textList, font) {
if (textList == null || textList.isEmpty) {
return;
}
int i = 0, il = textList.length;
num offx = 0, offy = 0;
for (; i < il; i++) {
offx = 0;
offy = 0;
var txt = textList[i];
var txtSize = Tools.getStrW(txt[0], font);
//第四个是定制样式
if (txt.length >= 4) {
font = <String, dynamic>{...font, ...txt[3]};
if (txt[3]['ylayout'] == 'top') {
//操控y
offy = txtSize['height'];
} else if (txt[3]['ylayout'] == 'bottom') {
//操控y
offy = -txtSize['height'];
} else if (txt[3]['ylayout'] == 'center') {
//操控y
offy = -(txtSize['height'] * 0.5);
}
if (txt[3]['xlayout'] == 'left') {
//操控y
offx = txtSize['width'];
} else if (txt[3]['xlayout'] == 'right') {
//操控y
offx = -txtSize['width'];
} else if (txt[3]['xlayout'] == 'center') {
//操控y
offx = -(txtSize['width'] * 0.5);
}
}
//绘制文字
Tools.drawText(canvas, txt[0].toString(), font, {
'x': txt[1] + offx,
'y': txt[2] + offy,
'w': txtSize['width'],
'h': txtSize['height']
});
}
}