From e9c219cff25e93d3156320ecee1263f29841f967 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:30:22 +0200 Subject: [PATCH] [Label] Add get_character_bounds method to get bounding rectangles of the characters. --- doc/classes/Label.xml | 7 +++ scene/gui/label.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++ scene/gui/label.h | 2 + 3 files changed, 132 insertions(+) diff --git a/doc/classes/Label.xml b/doc/classes/Label.xml index fda45a42c8d..94b1815dce3 100644 --- a/doc/classes/Label.xml +++ b/doc/classes/Label.xml @@ -10,6 +10,13 @@ https://godotengine.org/asset-library/asset/515 + + + + + Returns the bounding rectangle of the character at position [param pos]. If the character is a non-visual character or [param pos] is outside the valid range, an empty [Rect2] is returned. If the character is a part of a composite grapheme, the bounding rectangle of the whole grapheme is returned. + + diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 3df0d971602..1b1905e7936 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -668,6 +668,127 @@ void Label::_notification(int p_what) { } } +Rect2 Label::get_character_bounds(int p_pos) const { + if (dirty || font_dirty || lines_dirty) { + const_cast