| 1517 | } |
| 1518 | |
| 1519 | void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2 &p_region) { |
| 1520 | if (!Rect2(Vector2(0, 0), get_size()).intersects(p_region)) { |
| 1521 | return; |
| 1522 | } |
| 1523 | |
| 1524 | bool rtl = is_layout_rtl(); |
| 1525 | HashMap<int, RID>::Iterator E = line_number_text_cache.find(p_line); |
| 1526 | RID text_rid; |
| 1527 | if (E) { |
| 1528 | text_rid = E->value; |
| 1529 | } else { |
| 1530 | String fc = String::num_int64(p_line + 1).lpad(line_number_digits, line_number_padding); |
| 1531 | if (is_localizing_numeral_system()) { |
| 1532 | fc = TS->format_number(fc); |
| 1533 | } |
| 1534 | |
| 1535 | text_rid = TS->create_shaped_text(); |
| 1536 | if (theme_cache.font.is_valid()) { |
| 1537 | TS->shaped_text_add_string(text_rid, fc, theme_cache.font->get_rids(), theme_cache.font_size, theme_cache.font->get_opentype_features()); |
| 1538 | } |
| 1539 | line_number_text_cache.insert(p_line, text_rid); |
| 1540 | } |
| 1541 | |
| 1542 | Size2 text_size = TS->shaped_text_get_size(text_rid); |
| 1543 | Point2 ofs = p_region.get_center() - text_size / 2; |
| 1544 | ofs.y += TS->shaped_text_get_ascent(text_rid); |
| 1545 | |
| 1546 | if (rtl) { |
| 1547 | ofs.x = p_region.get_end().x - text_size.width; |
| 1548 | } else { |
| 1549 | ofs.x = p_region.position.x; |
| 1550 | } |
| 1551 | |
| 1552 | Color number_color = get_line_gutter_item_color(p_line, line_number_gutter); |
| 1553 | if (number_color == Color(1, 1, 1)) { |
| 1554 | number_color = theme_cache.line_number_color; |
| 1555 | } |
| 1556 | |
| 1557 | TS->shaped_text_draw(text_rid, get_canvas_item(), ofs, -1, -1, number_color); |
| 1558 | } |
| 1559 | |
| 1560 | void CodeEdit::_clear_line_number_text_cache() { |
| 1561 | for (const KeyValue<int, RID> &KV : line_number_text_cache) { |
nothing calls this directly
no test coverage detected