@@ -2928,7 +2928,10 @@ void TextEdit::_update_ime_text() {
2928
2928
Size2 TextEdit::get_minimum_size () const {
2929
2929
Size2 size = theme_cache.style_normal ->get_minimum_size ();
2930
2930
if (fit_content_height) {
2931
- size.y += content_height_cache;
2931
+ size.y += content_size_cache.y ;
2932
+ }
2933
+ if (fit_content_width) {
2934
+ size.x += content_size_cache.x ;
2932
2935
}
2933
2936
return size;
2934
2937
}
@@ -3098,7 +3101,7 @@ void TextEdit::apply_ime() {
3098
3101
insert_text_at_caret (insert_ime_text);
3099
3102
}
3100
3103
3101
- void TextEdit::set_editable (const bool p_editable) {
3104
+ void TextEdit::set_editable (bool p_editable) {
3102
3105
if (editable == p_editable) {
3103
3106
return ;
3104
3107
}
@@ -3223,7 +3226,7 @@ bool TextEdit::is_indent_wrapped_lines() const {
3223
3226
}
3224
3227
3225
3228
// User controls
3226
- void TextEdit::set_overtype_mode_enabled (const bool p_enabled) {
3229
+ void TextEdit::set_overtype_mode_enabled (bool p_enabled) {
3227
3230
if (overtype_mode == p_enabled) {
3228
3231
return ;
3229
3232
}
@@ -4486,7 +4489,7 @@ TextEdit::CaretType TextEdit::get_caret_type() const {
4486
4489
return caret_type;
4487
4490
}
4488
4491
4489
- void TextEdit::set_caret_blink_enabled (const bool p_enabled) {
4492
+ void TextEdit::set_caret_blink_enabled (bool p_enabled) {
4490
4493
if (caret_blink_enabled == p_enabled) {
4491
4494
return ;
4492
4495
}
@@ -4528,15 +4531,15 @@ bool TextEdit::is_drawing_caret_when_editable_disabled() const {
4528
4531
return draw_caret_when_editable_disabled;
4529
4532
}
4530
4533
4531
- void TextEdit::set_move_caret_on_right_click_enabled (const bool p_enabled) {
4534
+ void TextEdit::set_move_caret_on_right_click_enabled (bool p_enabled) {
4532
4535
move_caret_on_right_click = p_enabled;
4533
4536
}
4534
4537
4535
4538
bool TextEdit::is_move_caret_on_right_click_enabled () const {
4536
4539
return move_caret_on_right_click;
4537
4540
}
4538
4541
4539
- void TextEdit::set_caret_mid_grapheme_enabled (const bool p_enabled) {
4542
+ void TextEdit::set_caret_mid_grapheme_enabled (bool p_enabled) {
4540
4543
caret_mid_grapheme_enabled = p_enabled;
4541
4544
}
4542
4545
@@ -4646,7 +4649,7 @@ void TextEdit::add_caret_at_carets(bool p_below) {
4646
4649
for (int i = 0 ; i < num_carets; i++) {
4647
4650
const int caret_line = get_caret_line (i);
4648
4651
const int caret_column = get_caret_column (i);
4649
- const bool is_selected = has_selection (i) || carets[i].last_fit_x != carets[i].selection .origin_last_fit_x ;
4652
+ bool is_selected = has_selection (i) || carets[i].last_fit_x != carets[i].selection .origin_last_fit_x ;
4650
4653
const int selection_origin_line = get_selection_origin_line (i);
4651
4654
const int selection_origin_column = get_selection_origin_column (i);
4652
4655
const int caret_wrap_index = get_caret_wrap_index (i);
@@ -5111,7 +5114,7 @@ String TextEdit::get_word_under_caret(int p_caret) const {
5111
5114
}
5112
5115
5113
5116
/* Selection. */
5114
- void TextEdit::set_selecting_enabled (const bool p_enabled) {
5117
+ void TextEdit::set_selecting_enabled (bool p_enabled) {
5115
5118
if (selecting_enabled == p_enabled) {
5116
5119
return ;
5117
5120
}
@@ -5127,7 +5130,7 @@ bool TextEdit::is_selecting_enabled() const {
5127
5130
return selecting_enabled;
5128
5131
}
5129
5132
5130
- void TextEdit::set_deselect_on_focus_loss_enabled (const bool p_enabled) {
5133
+ void TextEdit::set_deselect_on_focus_loss_enabled (bool p_enabled) {
5131
5134
if (deselect_on_focus_loss_enabled == p_enabled) {
5132
5135
return ;
5133
5136
}
@@ -5142,7 +5145,7 @@ bool TextEdit::is_deselect_on_focus_loss_enabled() const {
5142
5145
return deselect_on_focus_loss_enabled;
5143
5146
}
5144
5147
5145
- void TextEdit::set_drag_and_drop_selection_enabled (const bool p_enabled) {
5148
+ void TextEdit::set_drag_and_drop_selection_enabled (bool p_enabled) {
5146
5149
drag_and_drop_selection_enabled = p_enabled;
5147
5150
}
5148
5151
@@ -5702,7 +5705,7 @@ Vector<String> TextEdit::get_line_wrapped_text(int p_line) const {
5702
5705
5703
5706
/* Viewport */
5704
5707
// Scrolling.
5705
- void TextEdit::set_smooth_scroll_enabled (const bool p_enabled) {
5708
+ void TextEdit::set_smooth_scroll_enabled (bool p_enabled) {
5706
5709
v_scroll->set_smooth_scroll_enabled (p_enabled);
5707
5710
smooth_scroll_enabled = p_enabled;
5708
5711
}
@@ -5711,7 +5714,7 @@ bool TextEdit::is_smooth_scroll_enabled() const {
5711
5714
return smooth_scroll_enabled;
5712
5715
}
5713
5716
5714
- void TextEdit::set_scroll_past_end_of_file_enabled (const bool p_enabled) {
5717
+ void TextEdit::set_scroll_past_end_of_file_enabled (bool p_enabled) {
5715
5718
if (scroll_past_end_of_file_enabled == p_enabled) {
5716
5719
return ;
5717
5720
}
@@ -5765,7 +5768,7 @@ float TextEdit::get_v_scroll_speed() const {
5765
5768
return v_scroll_speed;
5766
5769
}
5767
5770
5768
- void TextEdit::set_fit_content_height_enabled (const bool p_enabled) {
5771
+ void TextEdit::set_fit_content_height_enabled (bool p_enabled) {
5769
5772
if (fit_content_height == p_enabled) {
5770
5773
return ;
5771
5774
}
@@ -5777,6 +5780,18 @@ bool TextEdit::is_fit_content_height_enabled() const {
5777
5780
return fit_content_height;
5778
5781
}
5779
5782
5783
+ void TextEdit::set_fit_content_width_enabled (bool p_enabled) {
5784
+ if (fit_content_width == p_enabled) {
5785
+ return ;
5786
+ }
5787
+ fit_content_width = p_enabled;
5788
+ update_minimum_size ();
5789
+ }
5790
+
5791
+ bool TextEdit::is_fit_content_width_enabled () const {
5792
+ return fit_content_width;
5793
+ }
5794
+
5780
5795
double TextEdit::get_scroll_pos_for_line (int p_line, int p_wrap_index) const {
5781
5796
ERR_FAIL_INDEX_V (p_line, text.size (), 0 );
5782
5797
ERR_FAIL_COND_V (p_wrap_index < 0 , 0 );
@@ -6330,7 +6345,7 @@ bool TextEdit::is_highlight_current_line_enabled() const {
6330
6345
return highlight_current_line;
6331
6346
}
6332
6347
6333
- void TextEdit::set_highlight_all_occurrences (const bool p_enabled) {
6348
+ void TextEdit::set_highlight_all_occurrences (bool p_enabled) {
6334
6349
if (highlight_all_occurrences == p_enabled) {
6335
6350
return ;
6336
6351
}
@@ -6748,6 +6763,9 @@ void TextEdit::_bind_methods() {
6748
6763
ClassDB::bind_method (D_METHOD (" set_fit_content_height_enabled" , " enabled" ), &TextEdit::set_fit_content_height_enabled);
6749
6764
ClassDB::bind_method (D_METHOD (" is_fit_content_height_enabled" ), &TextEdit::is_fit_content_height_enabled);
6750
6765
6766
+ ClassDB::bind_method (D_METHOD (" set_fit_content_width_enabled" , " enabled" ), &TextEdit::set_fit_content_width_enabled);
6767
+ ClassDB::bind_method (D_METHOD (" is_fit_content_width_enabled" ), &TextEdit::is_fit_content_width_enabled);
6768
+
6751
6769
ClassDB::bind_method (D_METHOD (" get_scroll_pos_for_line" , " line" , " wrap_index" ), &TextEdit::get_scroll_pos_for_line, DEFVAL (0 ));
6752
6770
6753
6771
// Visible lines.
@@ -6872,6 +6890,7 @@ void TextEdit::_bind_methods() {
6872
6890
ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " scroll_vertical" , PROPERTY_HINT_NONE, " suffix:lines" ), " set_v_scroll" , " get_v_scroll" );
6873
6891
ADD_PROPERTY (PropertyInfo (Variant::INT, " scroll_horizontal" , PROPERTY_HINT_NONE, " suffix:px" ), " set_h_scroll" , " get_h_scroll" );
6874
6892
ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_fit_content_height" ), " set_fit_content_height_enabled" , " is_fit_content_height_enabled" );
6893
+ ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_fit_content_width" ), " set_fit_content_width_enabled" , " is_fit_content_width_enabled" );
6875
6894
6876
6895
ADD_GROUP (" Minimap" , " minimap_" );
6877
6896
ADD_PROPERTY (PropertyInfo (Variant::BOOL, " minimap_draw" ), " set_draw_minimap" , " is_drawing_minimap" );
@@ -7859,8 +7878,8 @@ void TextEdit::_update_scrollbars() {
7859
7878
total_width += minimap_width;
7860
7879
}
7861
7880
7862
- content_height_cache = MAX (total_rows, 1 ) * get_line_height ();
7863
- if (fit_content_height) {
7881
+ content_size_cache = Vector2i (total_width + 10 , MAX (total_rows, 1 ) * get_line_height () );
7882
+ if (fit_content_height || fit_content_width ) {
7864
7883
update_minimum_size ();
7865
7884
}
7866
7885
@@ -8067,7 +8086,7 @@ void TextEdit::_update_minimap_hover() {
8067
8086
const Point2 mp = get_local_mouse_pos ();
8068
8087
const int xmargin_end = get_size ().width - theme_cache.style_normal ->get_margin (SIDE_RIGHT);
8069
8088
8070
- const bool hovering_sidebar = mp.x > xmargin_end - minimap_width && mp.x < xmargin_end;
8089
+ bool hovering_sidebar = mp.x > xmargin_end - minimap_width && mp.x < xmargin_end;
8071
8090
if (!hovering_sidebar) {
8072
8091
if (hovering_minimap) {
8073
8092
// Only redraw if the hovering status changed.
@@ -8081,7 +8100,7 @@ void TextEdit::_update_minimap_hover() {
8081
8100
8082
8101
const int row = get_minimap_line_at_pos (mp);
8083
8102
8084
- const bool new_hovering_minimap = row >= get_first_visible_line () && row <= get_last_full_visible_line ();
8103
+ bool new_hovering_minimap = row >= get_first_visible_line () && row <= get_last_full_visible_line ();
8085
8104
if (new_hovering_minimap != hovering_minimap) {
8086
8105
// Only redraw if the hovering status changed.
8087
8106
hovering_minimap = new_hovering_minimap;
0 commit comments