//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2019 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Collections.Generic;
using bs;
namespace bs.Editor
{
/** @addtogroup GUI-Editor
* @{
*/
///
/// Helper class that creates a GUI layout with a texture background.
///
public class GUILayoutWithBackground
{
///
/// Content layout into which you should add your own GUI elements.
///
public GUILayout Layout { get; }
///
/// Root panel of the content layout, background panel and any helper backgrounds. Can be used for changing size,
/// destroying or hiding the GUI elements. You should not add or remove GUI elements from the panel.
///
public GUIPanel MainPanel { get; }
///
/// Constructs a new object.
///
/// Root panel in which all the child GUI elements of this object belong to.
/// Content layout that's to be provided to the user.
private GUILayoutWithBackground(GUIPanel mainPanel, GUILayout layout)
{
MainPanel = mainPanel;
Layout = layout;
}
///
/// Creates a new GUI layout of the specified type, with a texture background.
///
/// Type of layout to create.
/// Parent layout to add the layout to.
/// Texture to display on the background.
/// Color to apply to the background texture.
/// Optional padding to apply between element borders and content.
/// New GUI layout with background object.
public static GUILayoutWithBackground Create(GUILayout layout, SpriteTexture background, Color backgroundColor,
RectOffset padding = new RectOffset()) where T : GUILayout, new()
{
GUIPanel mainPanel = layout.AddPanel();
GUILayoutX mainLayout = mainPanel.AddLayoutX();
GUILayout contentLayout;
if (padding.top > 0 || padding.bottom > 0)
{
GUILayoutY paddingVertLayout = mainLayout.AddLayoutY();
if (padding.top > 0)
paddingVertLayout.AddSpace(padding.top);
if (padding.left > 0 || padding.right > 0)
{
GUILayoutX paddingHorzLayout = paddingVertLayout.AddLayoutX();
if (padding.left > 0)
paddingHorzLayout.AddSpace(padding.left);
contentLayout = new T();
paddingHorzLayout.AddElement(contentLayout);
if (padding.right > 0)
paddingHorzLayout.AddSpace(padding.right);
}
else
{
contentLayout = new T();
paddingVertLayout.AddElement(contentLayout);
}
if (padding.bottom > 0)
paddingVertLayout.AddSpace(padding.bottom);
}
else
{
if (padding.left > 0 || padding.right > 0)
{
GUILayoutX paddingHorzLayout = mainLayout.AddLayoutX();
if (padding.left > 0)
paddingHorzLayout.AddSpace(padding.left);
contentLayout = new T();
paddingHorzLayout.AddElement(contentLayout);
if (padding.right > 0)
paddingHorzLayout.AddSpace(padding.right);
}
else
{
contentLayout = new T();
mainLayout.AddElement(contentLayout);
}
}
GUIPanel bgPanel = mainPanel.AddPanel(1);
GUITexture bgTexture = new GUITexture(Builtin.WhiteTexture);
bgTexture.SetTint(backgroundColor);
bgPanel.AddElement(bgTexture);
return new GUILayoutWithBackground(mainPanel, contentLayout);
}
}
/** @} */
}