Merge pull request #54114 from timothyqiu/rich-text-label-fill-pointer

This commit is contained in:
Rémi Verschelde 2021-10-22 12:26:20 +02:00 committed by GitHub
commit 72fb4d7b09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -207,100 +207,101 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
#define RETURN return nonblank_line_count #define RETURN return nonblank_line_count
#define NEW_LINE \ #define NEW_LINE \
{ \ { \
if (p_mode != PROCESS_CACHE) { \ if (p_mode != PROCESS_CACHE) { \
line++; \ line++; \
backtrack = 0.0f; \ backtrack = 0.0f; \
if (!line_is_blank) { \ if (!line_is_blank) { \
nonblank_line_count++; \ nonblank_line_count++; \
} \ } \
line_is_blank = true; \ line_is_blank = true; \
if (line < l.offset_caches.size()) \ if (line < l.offset_caches.size()) \
line_ofs = l.offset_caches[line]; \ line_ofs = l.offset_caches[line]; \
wofs = margin; \ wofs = margin; \
if (align != ALIGN_FILL) \ if (align != ALIGN_FILL) \
wofs += line_ofs; \ wofs += line_ofs; \
} else { \ } else { \
int used = wofs - margin; \ int used = wofs - margin; \
switch (align) { \ switch (align) { \
case ALIGN_LEFT: \ case ALIGN_LEFT: \
l.offset_caches.push_back(0); \ l.offset_caches.push_back(0); \
break; \ break; \
case ALIGN_CENTER: \ case ALIGN_CENTER: \
l.offset_caches.push_back(((p_width - margin) - used) / 2); \ l.offset_caches.push_back(((p_width - margin) - used) / 2); \
break; \ break; \
case ALIGN_RIGHT: \ case ALIGN_RIGHT: \
l.offset_caches.push_back(((p_width - margin) - used)); \ l.offset_caches.push_back(((p_width - margin) - used)); \
break; \ break; \
case ALIGN_FILL: \ case ALIGN_FILL: \
l.offset_caches.push_back(line_wrapped ? ((p_width - margin) - used) : 0); \ l.offset_caches.push_back(line_wrapped ? ((p_width - margin) - used) : 0); \
break; \ break; \
} \ } \
l.height_caches.push_back(line_height); \ l.height_caches.push_back(line_height); \
l.ascent_caches.push_back(line_ascent); \ l.ascent_caches.push_back(line_ascent); \
l.descent_caches.push_back(line_descent); \ l.descent_caches.push_back(line_descent); \
l.space_caches.push_back(spaces); \ l.space_caches.push_back(spaces); \
} \ } \
line_wrapped = false; \ line_wrapped = false; \
y += line_height + get_constant(SceneStringNames::get_singleton()->line_separation); \ y += line_height + get_constant(SceneStringNames::get_singleton()->line_separation); \
line_height = 0; \ line_height = 0; \
line_ascent = 0; \ line_ascent = 0; \
line_descent = 0; \ line_descent = 0; \
spaces = 0; \ spaces = 0; \
wofs = begin; \ wofs = begin; \
align_ofs = 0.0f; \ align_ofs = 0.0f; \
if (p_mode != PROCESS_CACHE) { \ if (p_mode != PROCESS_CACHE) { \
lh = line < l.height_caches.size() ? l.height_caches[line] : 1; \ lh = line < l.height_caches.size() ? l.height_caches[line] : 1; \
line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1; \ line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1; \
line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1; \ line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1; \
if (align != ALIGN_FILL) { \ if (align != ALIGN_FILL) { \
if (line < l.offset_caches.size()) { \ if (line < l.offset_caches.size()) { \
wofs = l.offset_caches[line]; \ wofs = l.offset_caches[line]; \
} \ } \
} \ } \
} \ } \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x < p_ofs.x + wofs) { \ if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x < p_ofs.x + align_ofs + wofs) { \
if (r_outside) \ if (r_outside) \
*r_outside = true; \ *r_outside = true; \
*r_click_item = it; \ *r_click_item = it; \
*r_click_char = rchar; \ *r_click_char = rchar; \
RETURN; \ RETURN; \
} \ } \
} }
#define ENSURE_WIDTH(m_width) \ #define ENSURE_WIDTH(m_width) \
if (p_mode == PROCESS_CACHE) { \ if (p_mode == PROCESS_CACHE) { \
l.maximum_width = MAX(l.maximum_width, MIN(p_width, wofs + m_width)); \ l.maximum_width = MAX(l.maximum_width, MIN(p_width, wofs + m_width)); \
l.minimum_width = MAX(l.minimum_width, m_width); \ l.minimum_width = MAX(l.minimum_width, m_width); \
} \ } \
if (wofs - backtrack + m_width > p_width) { \ if (wofs - backtrack + m_width > p_width) { \
line_wrapped = true; \ line_wrapped = true; \
if (p_mode == PROCESS_CACHE) { \ if (p_mode == PROCESS_CACHE) { \
if (spaces > 0) \ if (spaces > 0) \
spaces -= 1; \ spaces -= 1; \
} \ } \
const bool x_in_range = (p_click_pos.x > p_ofs.x + wofs) && (!p_frame->cell || p_click_pos.x < p_ofs.x + p_width); \ const bool x_in_range = (p_click_pos.x > p_ofs.x + align_ofs + wofs) && (!p_frame->cell || p_click_pos.x < p_ofs.x + align_ofs + p_width); \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && x_in_range) { \
if (r_outside) \
*r_outside = true; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
} \
NEW_LINE \
}
#define ADVANCE(m_width) \
{ \
const bool x_in_range = (p_click_pos.x >= p_ofs.x + align_ofs + wofs) && (p_click_pos.x < p_ofs.x + align_ofs + wofs + m_width); \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && x_in_range) { \ if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && x_in_range) { \
if (r_outside) \ if (r_outside) \
*r_outside = true; \ *r_outside = false; \
*r_click_item = it; \ *r_click_item = it; \
*r_click_char = rchar; \ *r_click_char = rchar; \
RETURN; \ RETURN; \
} \ } \
NEW_LINE \ wofs += m_width; \
}
#define ADVANCE(m_width) \
{ \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x >= p_ofs.x + wofs && p_click_pos.x < p_ofs.x + wofs + m_width) { \
if (r_outside) \
*r_outside = false; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
} \
wofs += m_width; \
} }
#define CHECK_HEIGHT(m_height) \ #define CHECK_HEIGHT(m_height) \