Merge pull request #100432 from markdibarry/add_get_line_range_rtl
Add `get_line_range()` to `RichTextLabel`
This commit is contained in:
@ -112,6 +112,15 @@
|
||||
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_finished] or [signal finished] to determine whether document is fully loaded.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_line_range">
|
||||
<return type="Vector2i" />
|
||||
<param index="0" name="line" type="int" />
|
||||
<description>
|
||||
Returns the indexes of the first and last visible characters for the given [param line], as a [Vector2i].
|
||||
[b]Note:[/b] If [member visible_characters_behavior] is set to [constant TextServer.VC_CHARS_BEFORE_SHAPING] only visible wrapped lines are counted.
|
||||
[b]Note:[/b] If [member threaded] is enabled, this method returns a value for the loaded part of the document. Use [method is_finished] or [signal finished] to determine whether document is fully loaded.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_menu" qualifiers="const">
|
||||
<return type="PopupMenu" />
|
||||
<description>
|
||||
|
||||
@ -5562,6 +5562,26 @@ int RichTextLabel::get_line_count() const {
|
||||
return line_count;
|
||||
}
|
||||
|
||||
Vector2i RichTextLabel::get_line_range(int p_line) {
|
||||
const_cast<RichTextLabel *>(this)->_validate_line_caches();
|
||||
|
||||
int line_count = 0;
|
||||
int to_line = main->first_invalid_line.load();
|
||||
for (int i = 0; i < to_line; i++) {
|
||||
MutexLock lock(main->lines[i].text_buf->get_mutex());
|
||||
int lc = main->lines[i].text_buf->get_line_count();
|
||||
|
||||
if (p_line < line_count + lc) {
|
||||
Vector2i char_offset = Vector2i(main->lines[i].char_offset, main->lines[i].char_offset);
|
||||
Vector2i line_range = main->lines[i].text_buf->get_line_range(p_line - line_count);
|
||||
return char_offset + line_range;
|
||||
}
|
||||
|
||||
line_count += lc;
|
||||
}
|
||||
return Vector2i();
|
||||
}
|
||||
|
||||
int RichTextLabel::get_visible_line_count() const {
|
||||
if (!is_visible()) {
|
||||
return 0;
|
||||
@ -6455,6 +6475,7 @@ void RichTextLabel::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("is_using_bbcode"), &RichTextLabel::is_using_bbcode);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_line_count"), &RichTextLabel::get_line_count);
|
||||
ClassDB::bind_method(D_METHOD("get_line_range", "line"), &RichTextLabel::get_line_range);
|
||||
ClassDB::bind_method(D_METHOD("get_visible_line_count"), &RichTextLabel::get_visible_line_count);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_paragraph_count"), &RichTextLabel::get_paragraph_count);
|
||||
|
||||
@ -772,6 +772,7 @@ public:
|
||||
|
||||
void scroll_to_line(int p_line);
|
||||
int get_line_count() const;
|
||||
Vector2i get_line_range(int p_line);
|
||||
int get_visible_line_count() const;
|
||||
|
||||
int get_content_height() const;
|
||||
|
||||
Reference in New Issue
Block a user