TextEdit::scroll_fit_content_* is now maximum size aware
If `Control::get_combined_maximum_size()` returns a size smaller than `get_minimum_size()` in the target axis, scrollbars are shown.
This commit is contained in:
1 parent
653fed37e0
commit
747c3deeb5
3 files changed
+51
-4
No files matched your search
@@ -1375,10 +1375,10 @@
|
||||
Text shown when the [TextEdit] is empty. It is [b]not[/b] the [TextEdit]'s default value (see [member text]).
|
||||
</member>
|
||||
<member name="scroll_fit_content_height" type="bool" setter="set_fit_content_height_enabled" getter="is_fit_content_height_enabled" default="false">
|
||||
If [code]true[/code], [TextEdit] will disable vertical scroll and fit minimum height to the number of visible lines. When both this property and [member scroll_fit_content_width] are [code]true[/code], no scrollbars will be displayed.
|
||||
If [code]true[/code], [TextEdit] fits its minimum height to the number of visible lines instead of scrolling vertically. If a maximum height is set (for example via [member Control.custom_maximum_size]) and content exceeds it, a vertical scrollbar is shown.
|
||||
</member>
|
||||
<member name="scroll_fit_content_width" type="bool" setter="set_fit_content_width_enabled" getter="is_fit_content_width_enabled" default="false">
|
||||
If [code]true[/code], [TextEdit] will disable horizontal scroll and fit minimum width to the widest line in the text. When both this property and [member scroll_fit_content_height] are [code]true[/code], no scrollbars will be displayed.
|
||||
If [code]true[/code], [TextEdit] fits its minimum width to the widest line instead of scrolling horizontally. If a maximum width is set (for example via [member Control.custom_maximum_size]) and content exceeds it, a horizontal scrollbar is shown.
|
||||
</member>
|
||||
<member name="scroll_horizontal" type="int" setter="set_h_scroll" getter="get_h_scroll" default="0">
|
||||
If there is a horizontal scrollbar, this determines the current horizontal scroll value in pixels.
|
||||
|
||||
@@ -8678,9 +8678,16 @@ void TextEdit::_update_scrollbars() {
|
||||
update_minimum_size();
|
||||
}
|
||||
|
||||
const Size2 combined_maximum_size = get_combined_maximum_size();
|
||||
const Size2 style_minimum_size = style->get_minimum_size();
|
||||
const bool fit_content_height_exceeds_maximum = fit_content_height && combined_maximum_size.y >= 0 &&
|
||||
style_minimum_size.y + content_size_cache.y > combined_maximum_size.y;
|
||||
const bool fit_content_width_exceeds_maximum = fit_content_width && combined_maximum_size.x >= 0 &&
|
||||
style_minimum_size.x + content_size_cache.x > combined_maximum_size.x;
|
||||
|
||||
updating_scrolls = true;
|
||||
|
||||
if (!fit_content_height && total_rows > visible_rows) {
|
||||
if ((!fit_content_height || fit_content_height_exceeds_maximum) && total_rows > visible_rows) {
|
||||
double visible_rows_exact = (double)_get_control_height() / (double)get_line_height();
|
||||
double fractional_visible_rows = visible_rows_exact - (double)visible_rows;
|
||||
fractional_visible_rows = CLAMP(fractional_visible_rows, 0.0, 1.0);
|
||||
@@ -8696,7 +8703,7 @@ void TextEdit::_update_scrollbars() {
|
||||
v_scroll->hide();
|
||||
}
|
||||
|
||||
if (total_width > visible_width) {
|
||||
if ((!fit_content_width || fit_content_width_exceeds_maximum) && total_width > visible_width) {
|
||||
h_scroll->show();
|
||||
h_scroll->set_max(total_width);
|
||||
h_scroll->set_page(visible_width);
|
||||
|
||||
@@ -8045,6 +8045,46 @@ TEST_CASE("[SceneTree][TextEdit] small height value") {
|
||||
memdelete(text_edit);
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][TextEdit] fit content scrollbar behavior") {
|
||||
TextEdit *text_edit = memnew(TextEdit);
|
||||
SceneTree::get_singleton()->get_root()->add_child(text_edit);
|
||||
|
||||
text_edit->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_NONE);
|
||||
text_edit->set_fit_content_width_enabled(true);
|
||||
text_edit->set_fit_content_height_enabled(true);
|
||||
|
||||
const String long_line = "0123456789012345678901234567890123456789012345678901234567890123456789";
|
||||
String content;
|
||||
for (int i = 0; i < 40; i++) {
|
||||
if (i > 0) {
|
||||
content += "\n";
|
||||
}
|
||||
content += long_line;
|
||||
}
|
||||
text_edit->set_text(content);
|
||||
MessageQueue::get_singleton()->flush();
|
||||
|
||||
SUBCASE("[TextEdit] fit content without maximum size") {
|
||||
text_edit->set_custom_maximum_size(Size2(-1, -1));
|
||||
text_edit->set_size(text_edit->get_combined_minimum_size());
|
||||
MessageQueue::get_singleton()->flush();
|
||||
|
||||
CHECK_FALSE(text_edit->get_h_scroll_bar()->is_visible());
|
||||
CHECK_FALSE(text_edit->get_v_scroll_bar()->is_visible());
|
||||
}
|
||||
|
||||
SUBCASE("[TextEdit] fit content with maximum size") {
|
||||
text_edit->set_custom_maximum_size(Size2(180, 120));
|
||||
text_edit->set_size(text_edit->get_combined_maximum_size());
|
||||
MessageQueue::get_singleton()->flush();
|
||||
|
||||
CHECK(text_edit->get_h_scroll_bar()->is_visible());
|
||||
CHECK(text_edit->get_v_scroll_bar()->is_visible());
|
||||
}
|
||||
|
||||
memdelete(text_edit);
|
||||
}
|
||||
|
||||
TEST_CASE("[SceneTree][TextEdit] setter getters") {
|
||||
TextEdit *text_edit = memnew(TextEdit);
|
||||
SceneTree::get_singleton()->get_root()->add_child(text_edit);
|
||||
|
||||
Reference in new issue
Block a user