Add optional constructor arguments to more Control nodes

This can be used to make editor code more compact.
However, as of writing, these constructor arguments cannot be used
from the scripting API.

This was already provided for Label and CheckBox, but it was missing
for other Control nodes where it made sense to provide a default value.
This commit is contained in:
Hugo Locurcio 2022-03-04 09:18:44 +01:00
parent d0c3094da8
commit a06f82ca4d
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
17 changed files with 31 additions and 17 deletions

View File

@ -583,8 +583,8 @@ void Button::_bind_methods() {
Button::Button(const String &p_text) {
text_buf.instantiate();
text_buf->set_flags(TextServer::BREAK_MANDATORY);
set_mouse_filter(MOUSE_FILTER_STOP);
set_text(p_text);
}

View File

@ -111,9 +111,12 @@ void CheckButton::_notification(int p_what) {
}
}
CheckButton::CheckButton() {
CheckButton::CheckButton(const String &p_text) :
Button(p_text) {
set_toggle_mode(true);
set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
if (is_layout_rtl()) {
_set_internal_margin(SIDE_LEFT, get_icon_size().width);
} else {

View File

@ -42,7 +42,7 @@ protected:
void _notification(int p_what);
public:
CheckButton();
CheckButton(const String &p_text = String());
~CheckButton();
};

View File

@ -1429,7 +1429,8 @@ void ColorPickerButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "edit_alpha"), "set_edit_alpha", "is_editing_alpha");
}
ColorPickerButton::ColorPickerButton() {
ColorPickerButton::ColorPickerButton(const String &p_text) :
Button(p_text) {
set_toggle_mode(true);
}

View File

@ -231,7 +231,7 @@ public:
ColorPicker *get_picker();
PopupPanel *get_popup();
ColorPickerButton();
ColorPickerButton(const String &p_text = String());
};
VARIANT_ENUM_CAST(ColorPicker::PickerShapeType);

View File

@ -2437,7 +2437,7 @@ void LineEdit::_ensure_menu() {
}
}
LineEdit::LineEdit() {
LineEdit::LineEdit(const String &p_placeholder) {
text_rid = TS->create_shaped_text();
_create_undo_state();
@ -2452,6 +2452,8 @@ LineEdit::LineEdit() {
caret_blink_timer->connect("timeout", callable_mp(this, &LineEdit::_toggle_draw_caret));
set_caret_blink_enabled(false);
set_placeholder(p_placeholder);
set_editable(true); // Initialise to opposite first, so we get past the early-out in set_editable.
}

View File

@ -332,7 +332,7 @@ public:
void show_virtual_keyboard();
LineEdit();
LineEdit(const String &p_placeholder = String());
~LineEdit();
};

View File

@ -317,8 +317,10 @@ void LinkButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options");
}
LinkButton::LinkButton() {
LinkButton::LinkButton(const String &p_text) {
text_buf.instantiate();
set_focus_mode(FOCUS_NONE);
set_default_cursor_shape(CURSOR_POINTING_HAND);
set_text(p_text);
}

View File

@ -90,7 +90,7 @@ public:
void set_underline_mode(UnderlineMode p_underline_mode);
UnderlineMode get_underline_mode() const;
LinkButton();
LinkButton(const String &p_text = String());
};
VARIANT_ENUM_CAST(LinkButton::UnderlineMode);

View File

@ -227,7 +227,8 @@ void MenuButton::set_disable_shortcuts(bool p_disabled) {
disable_shortcuts = p_disabled;
}
MenuButton::MenuButton() {
MenuButton::MenuButton(const String &p_text) :
Button(p_text) {
set_flat(true);
set_toggle_mode(true);
set_disable_shortcuts(false);

View File

@ -67,7 +67,7 @@ public:
void set_item_count(int p_count);
int get_item_count() const;
MenuButton();
MenuButton(const String &p_text = String());
~MenuButton();
};

View File

@ -412,7 +412,8 @@ void OptionButton::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "index")));
}
OptionButton::OptionButton() {
OptionButton::OptionButton(const String &p_text) :
Button(p_text) {
set_toggle_mode(true);
set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
if (is_layout_rtl()) {

View File

@ -94,7 +94,7 @@ public:
virtual void get_translatable_strings(List<String> *p_strings) const override;
OptionButton();
OptionButton(const String &p_text = String());
~OptionButton();
};

View File

@ -4712,7 +4712,7 @@ Dictionary RichTextLabel::parse_expressions_for_values(Vector<String> p_expressi
return d;
}
RichTextLabel::RichTextLabel() {
RichTextLabel::RichTextLabel(const String &p_text) {
main = memnew(ItemFrame);
main->index = 0;
current = main;
@ -4734,6 +4734,8 @@ RichTextLabel::RichTextLabel() {
vscroll->set_step(1);
vscroll->hide();
set_text(p_text);
set_clip_contents(true);
}

View File

@ -620,7 +620,7 @@ public:
void set_fixed_size_to_width(int p_width);
virtual Size2 get_minimum_size() const override;
RichTextLabel();
RichTextLabel(const String &p_text = String());
~RichTextLabel();
};

View File

@ -6579,7 +6579,7 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
emit_signal(SNAME("lines_edited_from"), p_to_line, p_from_line);
}
TextEdit::TextEdit() {
TextEdit::TextEdit(const String &p_placeholder) {
placeholder_data_buf.instantiate();
clear();
@ -6621,5 +6621,7 @@ TextEdit::TextEdit() {
undo_stack_max_size = GLOBAL_GET("gui/common/text_edit_undo_stack_max_size");
set_placeholder(p_placeholder);
set_editable(true);
}

View File

@ -940,7 +940,7 @@ public:
void set_draw_spaces(bool p_enabled);
bool is_drawing_spaces() const;
TextEdit();
TextEdit(const String &p_placeholder = String());
};
VARIANT_ENUM_CAST(TextEdit::CaretType);