summaryrefslogtreecommitdiff
path: root/scene/gui/rich_text_label.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/rich_text_label.cpp')
-rw-r--r--scene/gui/rich_text_label.cpp60
1 files changed, 39 insertions, 21 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index af5d0e2f45..bc1510d6f6 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -204,6 +204,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int line_ascent = cfont->get_ascent();
int line_descent = cfont->get_descent();
+ int backtrack = 0; // for dynamic hidden content.
+
int nonblank_line_count = 0; //number of nonblank lines as counted during PROCESS_DRAW
Variant meta;
@@ -214,6 +216,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
{ \
if (p_mode != PROCESS_CACHE) { \
line++; \
+ backtrack = 0; \
if (!line_is_blank) { \
nonblank_line_count++; \
} \
@@ -263,7 +266,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
l.maximum_width = MAX(l.maximum_width, MIN(p_width, wofs + m_width)); \
l.minimum_width = MAX(l.minimum_width, m_width); \
} \
- if (wofs + m_width > p_width) { \
+ if (wofs - backtrack + m_width > p_width) { \
line_wrapped = true; \
if (p_mode == PROCESS_CACHE) { \
if (spaces > 0) \
@@ -390,6 +393,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int fw = 0;
lh = 0;
+
if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1;
@@ -432,13 +436,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
{
- int ofs = 0;
+ int ofs = 0 - backtrack;
for (int i = 0; i < end; i++) {
int pofs = wofs + ofs;
if (p_mode == PROCESS_POINTER && r_click_char && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
- //int o = (wofs+w)-p_click_pos.x;
int cw = font->get_char_size(c[i], c[i + 1]).x;
@@ -481,7 +484,10 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
bool visible = visible_characters < 0 || ((p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent)) &&
faded_visibility > 0.0f);
+ const bool previously_visible = visible;
+
for (int j = 0; j < fx_stack.size(); j++) {
+
ItemFX *item_fx = fx_stack[j];
if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) {
@@ -575,6 +581,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} else {
cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color);
}
+ } else if (previously_visible) {
+ backtrack += font->get_char_size(fx_char, c[i + 1]).x;
}
p_char_count++;
@@ -648,6 +656,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
case ITEM_NEWLINE: {
lh = 0;
+
if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
line_is_blank = true;
@@ -1199,49 +1208,59 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
if (k.is_valid()) {
if (k->is_pressed() && !k->get_alt() && !k->get_shift()) {
- bool handled = true;
- switch (k->get_scancode()) {
+ bool handled = false;
+ switch (k->get_keycode()) {
case KEY_PAGEUP: {
- if (vscroll->is_visible_in_tree())
+ if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() - vscroll->get_page());
+ handled = true;
+ }
} break;
case KEY_PAGEDOWN: {
- if (vscroll->is_visible_in_tree())
+ if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page());
+ handled = true;
+ }
} break;
case KEY_UP: {
- if (vscroll->is_visible_in_tree())
+ if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height());
+ handled = true;
+ }
} break;
case KEY_DOWN: {
- if (vscroll->is_visible_in_tree())
+ if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height());
+ handled = true;
+ }
} break;
case KEY_HOME: {
- if (vscroll->is_visible_in_tree())
+ if (vscroll->is_visible_in_tree()) {
vscroll->set_value(0);
+ handled = true;
+ }
} break;
case KEY_END: {
- if (vscroll->is_visible_in_tree())
+ if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_max());
+ handled = true;
+ }
} break;
case KEY_INSERT:
case KEY_C: {
if (k->get_command()) {
selection_copy();
- } else {
- handled = false;
+ handled = true;
}
} break;
- default: handled = false;
}
if (handled)
@@ -1648,7 +1667,7 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
}
}
-void RichTextLabel::add_image(const Ref<Texture> &p_image, const int p_width, const int p_height) {
+void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height) {
if (current->type == ITEM_TABLE)
return;
@@ -2204,7 +2223,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
- Ref<Texture> texture = ResourceLoader::load(image, "Texture");
+ Ref<Texture2D> texture = ResourceLoader::load(image, "Texture2D");
if (texture.is_valid())
add_image(texture);
@@ -2230,7 +2249,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
- Ref<Texture> texture = ResourceLoader::load(image, "Texture");
+ Ref<Texture2D> texture = ResourceLoader::load(image, "Texture");
if (texture.is_valid())
add_image(texture, width, height);
@@ -2655,7 +2674,7 @@ void RichTextLabel::set_effects(const Vector<Variant> &effects) {
Vector<Variant> RichTextLabel::get_effects() {
Vector<Variant> r;
for (int i = 0; i < custom_effects.size(); i++) {
- r.push_back(custom_effects[i].get_ref_ptr());
+ r.push_back(custom_effects[i]);
}
return r;
}
@@ -2680,7 +2699,6 @@ int RichTextLabel::get_content_height() {
void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input);
- ClassDB::bind_method(D_METHOD("_scroll_changed"), &RichTextLabel::_scroll_changed);
ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text);
ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text);
ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text);
@@ -2762,7 +2780,7 @@ void RichTextLabel::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode_text", PROPERTY_HINT_MULTILINE_TEXT), "set_bbcode", "get_bbcode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta_underlined"), "set_meta_underline", "is_meta_underlined");
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_size", PROPERTY_HINT_RANGE, "0,24,1"), "set_tab_size", "get_tab_size");
@@ -2944,7 +2962,7 @@ RichTextLabel::RichTextLabel() {
vscroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0);
vscroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
vscroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
- vscroll->connect("value_changed", this, "_scroll_changed");
+ vscroll->connect("value_changed", callable_mp(this, &RichTextLabel::_scroll_changed));
vscroll->set_step(1);
vscroll->hide();
current_idx = 1;