EDIT 4: Finally found a working solution thanks to… Chat GPT. It became clear that a script is needed - Unity’s UI settings in the editor cannot achieve what I was looking for (90% sure, 10% still possible I couldn’t figure it out). Here is the core part of the script (placed in the Update function of my popup window):
Scrollview content is assigned in the editor.
private void Update()
{
float contentHeight = content.sizeDelta.y;
float maxHeight = Screen.height - 50f;
float scrollViewHeight = Mathf.Min(contentHeight, maxHeight);
scrollRect.GetComponent<LayoutElement>().preferredHeight = scrollViewHeight;
}
Edit 3: this guys pdf actually does what I want, but then when the scrollbar appears you can’t actually scroll: Expanding panel with scrollbars when max size
EDIT 2: The above solution doesn’t seem to work either.
EDIT: It’s possible this is the solution (currently testing): Layout Element max width/height
Original:
I have a ScrollView with content that is just TMP_Text to display a message. I have it working so that the content has a minimum height and the text can expand infinitely into a ScrollView. The entire message container is set to fill the screen with a fixed margin.
The problem is when someone’s screen is tall and the content isn’t big enough, there is a huge gap below the text. I’d like to set the expansion of the viewport to have a maximum.
Here is the current version. I’d like to avoid using code for this, unless it isn’t possible in the editor.
Short screen with too much content (working as intended):

Tall screen without enough content (not working as intended):

