| 1332 | } |
| 1333 | |
| 1334 | void TextBox::paint(SkCanvas* canvas, const PaintOpts& paintOpts) { |
| 1335 | rebuild(); |
| 1336 | |
| 1337 | for(auto& pData : paragraphs) |
| 1338 | pData.p->paint(canvas, 0.0f, pData.heightOffset); |
| 1339 | |
| 1340 | if(paintOpts.cursor.has_value()) { |
| 1341 | auto& cur = paintOpts.cursor.value(); |
| 1342 | SkPaint selectionP{SkColor4f{paintOpts.cursorColor.x(), paintOpts.cursorColor.y(), paintOpts.cursorColor.z(), 1.0f}}; |
| 1343 | selectionP.setAntiAlias(paintOpts.skiaAA); |
| 1344 | if(cur.selectionBeginPos != cur.selectionEndPos) { |
| 1345 | canvas->saveLayerAlphaf(nullptr, 0.5f); |
| 1346 | rects_between_text_positions_func(cur.selectionBeginPos, cur.selectionEndPos, [&](const SkRect& rect) { |
| 1347 | canvas->drawRect(rect, selectionP); |
| 1348 | }); |
| 1349 | canvas->restore(); |
| 1350 | } |
| 1351 | SkPaint cursorP{SkColor4f{paintOpts.cursorColor.x(), paintOpts.cursorColor.y(), paintOpts.cursorColor.z(), 1.0f}}; |
| 1352 | cursorP.setAntiAlias(paintOpts.skiaAA); |
| 1353 | canvas->drawRect(get_cursor_rect(cur.pos), cursorP); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | } |