Selaa lähdekoodia

Merge pull request #5489 from jejung/richtextlabel-get_text

RichTextLabel-get_text
Juan Linietsky 9 vuotta sitten
vanhempi
commit
5bb552273b
3 muutettua tiedostoa jossa 39 lisäystä ja 0 poistoa
  1. 19 0
      doc/base/classes.xml
  2. 19 0
      scene/gui/rich_text_label.cpp
  3. 1 0
      scene/gui/rich_text_label.h

+ 19 - 0
doc/base/classes.xml

@@ -21677,6 +21677,12 @@
 			<description>
 			</description>
 		</method>
+		<method name="is_displayed_folded" qualifiers="const">
+			<return type="bool">
+			</return>
+			<description>
+			</description>
+		</method>
 		<method name="is_fixed_processing" qualifiers="const">
 			<return type="bool">
 			</return>
@@ -21802,6 +21808,12 @@
 			<description>
 			</description>
 		</method>
+		<method name="set_display_folded">
+			<argument index="0" name="fold" type="bool">
+			</argument>
+			<description>
+			</description>
+		</method>
 		<method name="set_filename">
 			<argument index="0" name="filename" type="String">
 			</argument>
@@ -31551,6 +31563,13 @@
 			<description>
 			</description>
 		</method>
+		<method name="get_text">
+			<return type="String">
+			</return>
+			<description>
+			Returns the raw text, stripping out the formatting information.
+			</description>
+		</method>
 		<method name="get_total_character_count" qualifiers="const">
 			<return type="int">
 			</return>

+ 19 - 0
scene/gui/rich_text_label.cpp

@@ -1877,11 +1877,30 @@ bool RichTextLabel::is_using_bbcode() const {
 
 	return use_bbcode;
 }
+
+String RichTextLabel::get_text() {
+	String text = "";
+	Item *it = main;
+	while (it) {
+		if (it->type == ITEM_TEXT) {
+			ItemText *t = static_cast<ItemText*>(it);
+			text += t->text;
+		} else if (it->type == ITEM_NEWLINE) {
+			text += "\n";
+		} else if (it->type == ITEM_INDENT) {
+			text += "\t";
+		}
+		it=_get_next_item(it,true);
+	}
+	return text;
+}
+
 void RichTextLabel::_bind_methods() {
 
 
 	ObjectTypeDB::bind_method(_MD("_input_event"),&RichTextLabel::_input_event);
 	ObjectTypeDB::bind_method(_MD("_scroll_changed"),&RichTextLabel::_scroll_changed);
+	ObjectTypeDB::bind_method(_MD("get_text"),&RichTextLabel::get_text);
 	ObjectTypeDB::bind_method(_MD("add_text","text"),&RichTextLabel::add_text);
 	ObjectTypeDB::bind_method(_MD("add_image","image:Texture"),&RichTextLabel::add_image);
 	ObjectTypeDB::bind_method(_MD("newline"),&RichTextLabel::add_newline);

+ 1 - 0
scene/gui/rich_text_label.h

@@ -280,6 +280,7 @@ protected:
 
 public:
 
+	String get_text();
 	void add_text(const String& p_text);
 	void add_image(const Ref<Texture>& p_image);
 	void add_newline();