Commit ba29541b authored by limingzhe's avatar limingzhe

fix: 换行 填空

parent 50064f04
......@@ -838,6 +838,7 @@ export class RichTextOld extends Label {
export class RichText extends Label {
......@@ -846,6 +847,9 @@ export class RichText extends Label {
row = 1;
textBaseline = "middle";
isShowWordBg = false;
wordBgData;
constructor(ctx?: any) {
super(ctx);
......@@ -864,7 +868,10 @@ export class RichText extends Label {
return tmpTextH + tmpDisH;
}
getSubTextRect(subText) {
getSubTextRect(subText, targetIndex=0) {
const tmpLabel = new RichText();
tmpLabel.fontSize = this.fontSize;
......@@ -875,21 +882,28 @@ export class RichText extends Label {
tmpLabel.width = this.width;
tmpLabel.height = this.height;
const index = this.text.indexOf(subText);
tmpLabel.text = this.text.substring(0, index);
tmpLabel.refreshSize();
// console.log('subText: ', subText);
// const indexArr = searchSubStr(this.text, subText);
// console.log('indexArr: ', indexArr);
// const index = indexArr[targetIndex];
const index = this.text.indexOf(subText, targetIndex);
const x = tmpLabel.width;
tmpLabel.text = subText;
tmpLabel.refreshSize();
if (!index) {
return;
}
// const index = this.text.indexOf(subText);
// console.log('!!!index: ', index);
const width = tmpLabel.width;
const data = this.wordBgData[index.toString()];
// console.log('!!!wordBgData: ', this.wordBgData);
// console.log('!!!data: ', data);
return data;
const y = this.fontSize / 2;
const height = this.fontSize;
return {x, y, width, height}
}
......@@ -916,16 +930,39 @@ export class RichText extends Label {
const w = selfW - this.offW * 2;
const disH = (this.fontSize + this.disH) * this.scaleY;
let isPushWordData = false;
if (this.isShowWordBg && !this.wordBgData) {
this.wordBgData = {};
isPushWordData = true;
}
let wordIndex = -1;
for (const c of chr) {
if (isPushWordData) {
}
for (const c of chr) {
if (this.ctx.measureText(temp).width < w && this.ctx.measureText(temp + (c)).width <= w) {
if (c == '\n') {
row.push(temp);
temp = '';
} else if (this.ctx.measureText(temp).width < w && this.ctx.measureText(temp + (c)).width <= w) {
temp += ' ' + c;
} else {
row.push(temp);
temp = ' ' + c;
}
if (isPushWordData) {
wordIndex = this.text.indexOf(c, wordIndex+1);
const key = wordIndex.toString();
const rectX = this.ctx.measureText(temp).width
const rectY = ( row.length ) * disH / this.scaleY
const rectW = this.ctx.measureText(c).width;
const rectH = this.fontSize;
this.wordBgData[key] = {rect: {x: rectX, y: rectY, width: rectW, height: rectH}, text: c, index: wordIndex}
}
}
row.push(temp);
......@@ -965,7 +1002,6 @@ export class RichText extends Label {
export class LineRect extends MySprite {
lineColor = '#ffffff';
......
......@@ -1105,23 +1105,44 @@ export class PlayComponent implements OnInit, OnDestroy {
richText.y = curY;
richText.text = arr[i].text;
const rect = richText.getSubTextRect('____________________');
richText.isShowWordBg = true;
richText.update();
const rectData = richText.getSubTextRect('____________________');
const rect = rectData.rect;
// index = rectData.index + 1;
const edgeW = 5 * this.mapScale;
const edgeH = 10 * this.mapScale;
const colorRect = new ShapeRectNew();
rect.height += 30;
colorRect.setSize(rect.width, rect.height, 1);
colorRect.fillColor = '#ff0000'
const offX = 13;
colorRect.x = rect.x + offX;
colorRect.y = -rect.height / 2;
console.log('rect.height: ', rect.height);
colorRect.setSize(rect.width + edgeW * 2, rect.height + edgeH * 2, 10 * this.mapScale);
colorRect.x = rect.x - rect.width - edgeW;
colorRect.y = rect.y - rect.height / 2 - edgeH * 0.7;
colorRect.alpha = 0;
richText.addChild(colorRect);
this.sentenceEmptyArr.push(colorRect);
// const colorRect = new ShapeRectNew();
// rect.height += 30;
// colorRect.setSize(rect.width, rect.height, 1);
// colorRect.fillColor = '#ff0000'
// const offX = 13;
// colorRect.x = rect.x + offX;
// colorRect.y = -rect.height / 2;
// console.log('rect.height: ', rect.height);
// colorRect.alpha = 0.5;
// richText.addChild(colorRect);
// this.sentenceEmptyArr.push(colorRect);
curY += richText.getAreaHeight() * this.mapScale + disH;
richText['data'] = arr[i];
......@@ -1415,7 +1436,7 @@ export class PlayComponent implements OnInit, OnDestroy {
return;
}
if (this.maskPic.visible) {
if (this.maskPic?.visible) {
return;
}
this.downFlag = true;
......@@ -1509,11 +1530,7 @@ export class PlayComponent implements OnInit, OnDestroy {
event.preventDefault()
}
if (this.resultSv) {
this.resultSv.onTouchMove(this.mx, this.my);
} else {
this.scrollView.onTouchMove(this.mx, this.my);
}
if (!this.curMoveItem) {
......@@ -1524,6 +1541,12 @@ export class PlayComponent implements OnInit, OnDestroy {
return;
}
if (this.resultSv) {
this.resultSv.onTouchMove(this.mx, this.my);
} else {
this.scrollView.onTouchMove(this.mx, this.my);
}
this.curMoveItem.x = this.mx;
this.curMoveItem.y = this.my;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment