Moving GUILayout components

Hi everyone,

I’m making a dialog system whereby the user is shown a series of dialog boxes one after each other. Each dialog box contains a background texture, a player avatar and some text. I used the GUILayout system to display each dialog box. When a new box is added, I fade it in and then after some predefined time I fade it out and finally remove it from the screen. The last step I require is to move the boxes underneath the one deleted smoothly to the top.

Can anyone show how to do this please? This is the current code to display the dialog boxes;

GUILayout.BeginArea(_dialogBounds);
	GUILayout.BeginVertical();
		for(int i = 0; i < _dialogBoxes.Count; i++){
			GUI.color = _dialogBoxes[i].Color;
					
			float boxWidth = _dialogBounds.width - (i * _indentation);
			dialogStyle.margin.left = i * _indentation;
					
			GUILayout.BeginHorizontal(dialogStyle, GUILayout.MaxWidth(boxWidth));
				_dialogBoxes[i].CurrentRectangle = GUILayoutUtility.GetLastRect();
						
				GUILayout.Box(_dialogBoxes[i].Avatar, dialogImageStyle);
				Components.Label(GUILayoutUtility.GetRect(new GUIContent(_dialogBoxes[i].Text), dialogLabelStyle), _dialogBoxes[i].Text, dialogLabelStyle, true, false);
			GUILayout.EndHorizontal();
		}
	GUILayout.EndVertical();
GUILayout.EndArea();

This is the current output;

There’s no built-in or trivial way to do that. You’ll need some way to track when a dialog has been faded out and the rest need to be shuffled up; a way to keep the remaining ones offset by an amount that shrinks over time, and a way of managing the offset amount to shrink it; and a way of skipping the offsetting logic when not required.

A couple of suggestions that might help: first, GUILayout.Space() will let you offset the first drawn dialog; second, having some sort of place-holder value in your _dialogBoxes array for ‘closed’ dialogs (i.e. replace the dialog data with the place-holder/marker value, rather than just remove it from _dialogBoxes) will give you a way to tell when you need to render an offset, and potentially a place to store information about how much offset to draw for that closed/deleted dialog.

hi laurie,

thanks, I managed to do it using the GUILayout.Space() and varying the offset! :smile: Now it works perfectly :slight_smile:

regards,
clayton