mirror of
https://github.com/godotengine/godot.git
synced 2024-11-11 06:33:10 +00:00
[RTL] Add pop_all
, push_context
and pop_context
methods, and use it for print_rich
to avoid unclosed tags.
This commit is contained in:
parent
85c9db592f
commit
5216a08617
@ -266,6 +266,18 @@
|
||||
Terminates the current tag. Use after [code]push_*[/code] methods to close BBCodes manually. Does not need to follow [code]add_*[/code] methods.
|
||||
</description>
|
||||
</method>
|
||||
<method name="pop_all">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Terminates all tags opened by [code]push_*[/code] methods.
|
||||
</description>
|
||||
</method>
|
||||
<method name="pop_context">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Terminates tags opened after the last [method push_context] call (including context marker), or all tags if there's no context marker on the stack.
|
||||
</description>
|
||||
</method>
|
||||
<method name="push_bgcolor">
|
||||
<return type="void" />
|
||||
<param index="0" name="bgcolor" type="Color" />
|
||||
@ -298,6 +310,12 @@
|
||||
Adds a [code][color][/code] tag to the tag stack.
|
||||
</description>
|
||||
</method>
|
||||
<method name="push_context">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Adds a context marker to the tag stack. See [method pop_context].
|
||||
</description>
|
||||
</method>
|
||||
<method name="push_customfx">
|
||||
<return type="void" />
|
||||
<param index="0" name="effect" type="RichTextEffect" />
|
||||
|
@ -338,13 +338,7 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
|
||||
} else {
|
||||
log->add_text(p_message.text);
|
||||
}
|
||||
|
||||
// Need to use pop() to exit out of the RichTextLabels current "push" stack.
|
||||
// We only "push" in the above switch when message type != STD and RICH, so only pop when that is the case.
|
||||
if (p_message.type != MSG_TYPE_STD && p_message.type != MSG_TYPE_STD_RICH) {
|
||||
log->pop();
|
||||
}
|
||||
|
||||
log->pop_all(); // Pop all unclosed tags.
|
||||
log->add_newline();
|
||||
|
||||
if (p_replace_previous) {
|
||||
|
@ -3444,6 +3444,7 @@ void RichTextLabel::push_fade(int p_start_index, int p_length) {
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_COND(current->type == ITEM_TABLE);
|
||||
ItemFade *item = memnew(ItemFade);
|
||||
item->starting_index = p_start_index;
|
||||
item->length = p_length;
|
||||
@ -3454,6 +3455,7 @@ void RichTextLabel::push_shake(int p_strength = 10, float p_rate = 24.0f, bool p
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_COND(current->type == ITEM_TABLE);
|
||||
ItemShake *item = memnew(ItemShake);
|
||||
item->strength = p_strength;
|
||||
item->rate = p_rate;
|
||||
@ -3465,6 +3467,7 @@ void RichTextLabel::push_wave(float p_frequency = 1.0f, float p_amplitude = 10.0
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_COND(current->type == ITEM_TABLE);
|
||||
ItemWave *item = memnew(ItemWave);
|
||||
item->frequency = p_frequency;
|
||||
item->amplitude = p_amplitude;
|
||||
@ -3476,6 +3479,7 @@ void RichTextLabel::push_tornado(float p_frequency = 1.0f, float p_radius = 10.0
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_COND(current->type == ITEM_TABLE);
|
||||
ItemTornado *item = memnew(ItemTornado);
|
||||
item->frequency = p_frequency;
|
||||
item->radius = p_radius;
|
||||
@ -3487,6 +3491,7 @@ void RichTextLabel::push_rainbow(float p_saturation, float p_value, float p_freq
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_COND(current->type == ITEM_TABLE);
|
||||
ItemRainbow *item = memnew(ItemRainbow);
|
||||
item->frequency = p_frequency;
|
||||
item->saturation = p_saturation;
|
||||
@ -3520,6 +3525,7 @@ void RichTextLabel::push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionar
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_COND(current->type == ITEM_TABLE);
|
||||
ItemCustomFX *item = memnew(ItemCustomFX);
|
||||
item->custom_effect = p_custom_effect;
|
||||
item->char_fx_transform->environment = p_environment;
|
||||
@ -3528,6 +3534,15 @@ void RichTextLabel::push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionar
|
||||
set_process_internal(true);
|
||||
}
|
||||
|
||||
void RichTextLabel::push_context() {
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_COND(current->type == ITEM_TABLE);
|
||||
ItemContext *item = memnew(ItemContext);
|
||||
_add_item(item, true);
|
||||
}
|
||||
|
||||
void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio) {
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
@ -3621,6 +3636,31 @@ void RichTextLabel::pop() {
|
||||
current = current->parent;
|
||||
}
|
||||
|
||||
void RichTextLabel::pop_context() {
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
ERR_FAIL_NULL(current->parent);
|
||||
|
||||
while (current->parent && current != main) {
|
||||
if (current->type == ITEM_FRAME) {
|
||||
current_frame = static_cast<ItemFrame *>(current)->parent_frame;
|
||||
} else if (current->type == ITEM_CONTEXT) {
|
||||
current = current->parent;
|
||||
return;
|
||||
}
|
||||
current = current->parent;
|
||||
}
|
||||
}
|
||||
|
||||
void RichTextLabel::pop_all() {
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
|
||||
current = main;
|
||||
current_frame = main;
|
||||
}
|
||||
|
||||
void RichTextLabel::clear() {
|
||||
_stop_thread();
|
||||
MutexLock data_lock(data_mutex);
|
||||
@ -5508,7 +5548,10 @@ void RichTextLabel::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("push_fgcolor", "fgcolor"), &RichTextLabel::push_fgcolor);
|
||||
ClassDB::bind_method(D_METHOD("push_bgcolor", "bgcolor"), &RichTextLabel::push_bgcolor);
|
||||
ClassDB::bind_method(D_METHOD("push_customfx", "effect", "env"), &RichTextLabel::push_customfx);
|
||||
ClassDB::bind_method(D_METHOD("push_context"), &RichTextLabel::push_context);
|
||||
ClassDB::bind_method(D_METHOD("pop_context"), &RichTextLabel::pop_context);
|
||||
ClassDB::bind_method(D_METHOD("pop"), &RichTextLabel::pop);
|
||||
ClassDB::bind_method(D_METHOD("pop_all"), &RichTextLabel::pop_all);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("clear"), &RichTextLabel::clear);
|
||||
|
||||
|
@ -75,7 +75,8 @@ public:
|
||||
ITEM_META,
|
||||
ITEM_HINT,
|
||||
ITEM_DROPCAP,
|
||||
ITEM_CUSTOMFX
|
||||
ITEM_CUSTOMFX,
|
||||
ITEM_CONTEXT
|
||||
};
|
||||
|
||||
enum MenuItems {
|
||||
@ -370,6 +371,10 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
struct ItemContext : public Item {
|
||||
ItemContext() { type = ITEM_CONTEXT; }
|
||||
};
|
||||
|
||||
ItemFrame *main = nullptr;
|
||||
Item *current = nullptr;
|
||||
ItemFrame *current_frame = nullptr;
|
||||
@ -614,6 +619,7 @@ public:
|
||||
void push_bgcolor(const Color &p_color);
|
||||
void push_fgcolor(const Color &p_color);
|
||||
void push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment);
|
||||
void push_context();
|
||||
void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1);
|
||||
void set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg);
|
||||
void set_cell_border_color(const Color &p_color);
|
||||
@ -622,6 +628,8 @@ public:
|
||||
int get_current_table_column() const;
|
||||
void push_cell();
|
||||
void pop();
|
||||
void pop_context();
|
||||
void pop_all();
|
||||
|
||||
void clear();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user