|
@@ -2668,7 +2668,11 @@ void TextEdit::_update_caches() {
|
|
|
|
|
|
/* General overrides. */
|
|
|
Size2 TextEdit::get_minimum_size() const {
|
|
|
- return style_normal->get_minimum_size();
|
|
|
+ Size2 size = style_normal->get_minimum_size();
|
|
|
+ if (fit_content_height) {
|
|
|
+ size.y += content_height_cache;
|
|
|
+ }
|
|
|
+ return size;
|
|
|
}
|
|
|
|
|
|
bool TextEdit::is_text_field() const {
|
|
@@ -4499,6 +4503,18 @@ float TextEdit::get_v_scroll_speed() const {
|
|
|
return v_scroll_speed;
|
|
|
}
|
|
|
|
|
|
+void TextEdit::set_fit_content_height_enabled(const bool p_enabled) {
|
|
|
+ if (fit_content_height == p_enabled) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ fit_content_height = p_enabled;
|
|
|
+ update_minimum_size();
|
|
|
+}
|
|
|
+
|
|
|
+bool TextEdit::is_fit_content_height_enabled() const {
|
|
|
+ return fit_content_height;
|
|
|
+}
|
|
|
+
|
|
|
double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
|
|
|
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
|
|
|
ERR_FAIL_COND_V(p_wrap_index < 0, 0);
|
|
@@ -5297,7 +5313,7 @@ void TextEdit::_bind_methods() {
|
|
|
|
|
|
/* Viewport. */
|
|
|
// Scrolling.
|
|
|
- ClassDB::bind_method(D_METHOD("set_smooth_scroll_enable", "enable"), &TextEdit::set_smooth_scroll_enabled);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_smooth_scroll_enabled", "enable"), &TextEdit::set_smooth_scroll_enabled);
|
|
|
ClassDB::bind_method(D_METHOD("is_smooth_scroll_enabled"), &TextEdit::is_smooth_scroll_enabled);
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_v_scroll", "value"), &TextEdit::set_v_scroll);
|
|
@@ -5312,6 +5328,9 @@ void TextEdit::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_v_scroll_speed", "speed"), &TextEdit::set_v_scroll_speed);
|
|
|
ClassDB::bind_method(D_METHOD("get_v_scroll_speed"), &TextEdit::get_v_scroll_speed);
|
|
|
|
|
|
+ ClassDB::bind_method(D_METHOD("set_fit_content_height_enabled"), &TextEdit::set_fit_content_height_enabled);
|
|
|
+ ClassDB::bind_method(D_METHOD("is_fit_content_height_enabled"), &TextEdit::is_fit_content_height_enabled);
|
|
|
+
|
|
|
ClassDB::bind_method(D_METHOD("get_scroll_pos_for_line", "line", "wrap_index"), &TextEdit::get_scroll_pos_for_line, DEFVAL(0));
|
|
|
|
|
|
// Visible lines.
|
|
@@ -5431,11 +5450,12 @@ void TextEdit::_bind_methods() {
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "syntax_highlighter", PROPERTY_HINT_RESOURCE_TYPE, "SyntaxHighlighter", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_syntax_highlighter", "get_syntax_highlighter");
|
|
|
|
|
|
ADD_GROUP("Scroll", "scroll_");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_smooth"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_smooth"), "set_smooth_scroll_enabled", "is_smooth_scroll_enabled");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_v_scroll_speed", PROPERTY_HINT_NONE, "suffix:px/s"), "set_v_scroll_speed", "get_v_scroll_speed");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_past_end_of_file"), "set_scroll_past_end_of_file_enabled", "is_scroll_past_end_of_file_enabled");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_vertical", PROPERTY_HINT_NONE, "suffix:px"), "set_v_scroll", "get_v_scroll");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal", PROPERTY_HINT_NONE, "suffix:px"), "set_h_scroll", "get_h_scroll");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_fit_content_height"), "set_fit_content_height_enabled", "is_fit_content_height_enabled");
|
|
|
|
|
|
ADD_GROUP("Minimap", "minimap_");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "minimap_draw"), "set_draw_minimap", "is_drawing_minimap");
|
|
@@ -6197,6 +6217,11 @@ void TextEdit::_update_scrollbars() {
|
|
|
total_width += minimap_width;
|
|
|
}
|
|
|
|
|
|
+ content_height_cache = MAX(total_rows, 1) * get_line_height();
|
|
|
+ if (fit_content_height) {
|
|
|
+ update_minimum_size();
|
|
|
+ }
|
|
|
+
|
|
|
updating_scrolls = true;
|
|
|
|
|
|
if (total_rows > visible_rows) {
|