• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Glurth · Feb 12, 2018 at 07:21 PM · guilayouteditorguilayoutscroll view

GUILayout.MinHeight and EditorGUILayout.BeginScrollView not respecting layout options.

I suspect I’m just misunderstanding what the various GUILayoutOptions are supposed to do. I’m not actually looking for a workaround, my research has found a few of those; I’m just looking for help to clear up my confusion.

I’d like a fairly simple text control in the editor.

  • It should always be at least 60 units high, if all the text can fit vertically.

  • If the text cannot fit vertically in 60 units, it should expand vertically, to the height of the text, but at most 500 units.

  • If the text is larger, vertically than 500 units, a scroll bar should be shown.

    Now I had EXPECTED the following code to create an extreemly simple control like that:

     textScrollPosition = EditorGUILayout.BeginScrollView(textScrollPosition, GUILayout.ExpandHeight(true));
       mytext = EditorGUILayout.TextArea((mytext, GUILayout.MinHeight(60), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(500));
       EditorGUILayout.EndScrollView();
    
    

It does NOT work as expected, so I did some troubleshooting, and I’m clearly not understanding the results, or perhaps, the intention of these functions/parameters:

Let’s start with GUILayout.MinHeight. I would expect this to specify the minimum height a control should be. I would NOT expect it to affect the maximum height of the control. But the following code displays a text area that is 60 units high: All the time, regardless of the text.

    mytext = EditorGUILayout.TextArea((mytext, GUILayout.MinHeight(60), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(500));

If I exclude the MinHeight, it expands/contracts properly based on the text. But it CAN also be less than 60 unit high, which is what I wanted to avoid.
What am I misunderstanding about the GUILayout.MinHeight option?

I’m also unclear what’s going on with the layout system when I use EditorGUILayout.BeginScrollView. If I enclose the above text area, in a scroll view, the height of the text box changes to only two lines of text. Even if I assign the GUILayout.ExpandHeight(true) option, to the scroll view, it still limits the text to two lines.
If I follow the limited examples in the docs, and use a SPECIFIC height option, for the scrollView, like GUILayout.Height(300): THIS option IS respected by the scroll view.
What am I misunderstanding about the "automatically layouted" scroll view?

I’ve seen other answers that go and compute the height of the text and stuff like that, to feed a fixed GUILayout.Height option to the ScrollView and Text Area: and I can certainly do this as a last resort, but I’d like an explanation of what it is that I’m not understanding in the GUILayout system. What incorrect assumptions am I making?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by randomdragon · Aug 04, 2021 at 01:38 AM

This may help: https://answers.unity.com/questions/648971/why-is-guilayoutminheight-applying-a-maximum-heigh.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is the difference between editorguilayout and guilayout? 1 Answer

EditorGUI, EditorGUILayout, GUI, GUILayout... pshhh... WHEN TO USE WHAT?! 3 Answers

Custom Editor Struct array layout 0 Answers

Custom Inspector tooltips behaving inconsistently 0 Answers

Small GUILayout button 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges