Jump to content

GUI scrolling problem


Recommended Posts

It is better to show a picture of my problem:

NOe3EPF.png

It appears that the scroll box packs the many GUI labels tightly within its visible boundary instead of showing a visible snapshot of the labels.

Here're my snapshot of relevant codes.

	protected override List<DialogGUIBase> drawContentComponents()
        {
            List<DialogGUIBase> listComponments = new List<DialogGUIBase>();

            //Label for the brief message
            listComponments.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.UpperCenter, new DialogGUIBase[] { new DialogGUILabel(this. briefMessage, false, false) }));

            //A GUILayout for each message (eg label + textfield + button)
            List<DialogGUIHorizontalLayout> eachMessageGroupList = new List<DialogGUIHorizontalLayout>();
            while(messages.Count > 0)
            {
                DialogGUILabel messageLabel = new DialogGUILabel(messages.Dequeue(), false, false);
                DialogGUIHorizontalLayout lineGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.UpperLeft, new DialogGUIBase[] { messageLabel });
                eachMessageGroupList.Add(lineGroup);
            }

            //Prepare a list container for the message GUILayouts
            DialogGUIBase[] messageLabels = new DialogGUIBase[eachMessageGroupList.Count];
            for (int i = 0; i < eachMessageGroupList.Count; i++)
                messageLabels[i] = eachMessageGroupList[i];

            listComponments.Add(new DialogGUIScrollList(Vector2.one, false, true, new DialogGUIVerticalLayout(10, 100, 4, new RectOffset(5, 15, 0, 0), TextAnchor.UpperLeft, messageLabels)));

            return listComponments;
        }
	private PopupDialog spawnDialog()
        {
            /* This dialog looks like below
             * -----------------------
             * |        TITLE        |
             * |----------------------
             * |                     |
             * |      CONTENT        |
             * |                     |
             * |----------------------
             * |       CLOSE      XX |
             * ----------------------- 
             */

            List<DialogGUIBase> entireComponentList = new List<DialogGUIBase>();

            //content
            List<DialogGUIBase> contentComponentList = drawContentComponents(); // <--------- FROM THE CODE BOX ABOVE
            for(int i=0;i<contentComponentList.Count;i++)
                entireComponentList.Add(contentComponentList.ElementAt(i));

            //close button and some info
            //entireComponentList.Add(new DialogGUISpace(4));
            entireComponentList.Add(new DialogGUIHorizontalLayout(
                                        new DialogGUIBase[]
                                        {
                                            new DialogGUIFlexibleSpace(),
                                            new DialogGUIButton("Close", dismiss),
                                            new DialogGUIFlexibleSpace(),
                                            new DialogGUILabel("vX.X", false, false)
                                        }
                                    ));

            //Spawn the dialog
            MultiOptionDialog moDialog = new MultiOptionDialog("",
                                                               dialogTitle,
                                                               HighLogic.UISkin,
                                                               new Rect(normalizedCenterX, normalizedCenterY, windowWidth, windowHeight),
                                                               entireComponentList.ToArray());

            return PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                new Vector2(0.5f, 0.5f),
                                                moDialog,
                                                true,
                                                HighLogic.UISkin);
        }

 

The problem is I use the PopupDialog.SpawnPopupDialog class (KSP's own class) instead of the Unity Engine's GUILayout. I can't figure out how to position each label.

Edited by TaxiService
Link to comment
Share on other sites

The first element of the DialogGUIScrollList needs to be a content size fitter (DialogGUIContentSizer). So for the list of elements you want to populate the scroll list you need to take the number of those elements, plus one for the sizer.

            //Prepare a list container for the message GUILayouts
            DialogGUIBase[] messageLabels = new DialogGUIBase[eachMessageGroupList.Count + 1];
            messageLabels[0] = new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true);
            
            for (int i = 1; i < eachMessageGroupList.Count; i++)
                messageLabels[i] = eachMessageGroupList[i];

The arguments are for how it sets up the scroll view, for only vertical scrolling I think you need leave the width unconstrained.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...