浏览代码

GUIPanelContainer used in C# and working

Marko Pintera 11 年之前
父节点
当前提交
eee0e6bbf4

+ 2 - 0
BansheeEditor/Source/BsEditorGUI.cpp

@@ -349,6 +349,8 @@ namespace BansheeEngine
 
 
 		GUIElementStyle foldoutBackgroundStyle;
 		GUIElementStyle foldoutBackgroundStyle;
 		foldoutBackgroundStyle.normal.texture = getTexture(FoldoutBackgroundTex);
 		foldoutBackgroundStyle.normal.texture = getTexture(FoldoutBackgroundTex);
+		foldoutBackgroundStyle.fixedHeight = true;
+		foldoutBackgroundStyle.height = 8;
 
 
 		mSkin.setStyle("FoldoutBackground", foldoutBackgroundStyle);
 		mSkin.setStyle("FoldoutBackground", foldoutBackgroundStyle);
 
 

+ 2 - 2
BansheeEditor/Source/BsGUIFoldout.cpp

@@ -14,7 +14,7 @@ namespace BansheeEngine
 
 
 	GUIFoldout::GUIFoldout(const PrivatelyConstruct& dummy, const String& toggleStyle, 
 	GUIFoldout::GUIFoldout(const PrivatelyConstruct& dummy, const String& toggleStyle, 
 		const String& backgroundStyle, const GUILayoutOptions& layoutOptions)
 		const String& backgroundStyle, const GUILayoutOptions& layoutOptions)
-		:GUIElementContainer(layoutOptions), mToggle(nullptr), mBackground(nullptr), mIsExpanded(false)
+		:GUIElementContainer(layoutOptions, backgroundStyle), mToggle(nullptr), mBackground(nullptr), mIsExpanded(false)
 	{
 	{
 		mToggle = GUIToggle::create(HString(L""), toggleStyle);
 		mToggle = GUIToggle::create(HString(L""), toggleStyle);
 		mBackground = GUITexture::create(backgroundStyle);
 		mBackground = GUITexture::create(backgroundStyle);
@@ -125,7 +125,7 @@ namespace BansheeEngine
 
 
 	const String& GUIFoldout::getGUITypeName()
 	const String& GUIFoldout::getGUITypeName()
 	{
 	{
-		static String typeName = "GUIFoldout";
+		static String typeName = "Foldout";
 		return typeName;
 		return typeName;
 	}
 	}
 }
 }

+ 8 - 0
BansheeEngine/Include/BsGUIElement.h

@@ -101,6 +101,14 @@ namespace BansheeEngine
 		 */
 		 */
 		void setFocus(bool enabled);
 		void setFocus(bool enabled);
 
 
+		/**
+		 * @brief	Sets new layout options for the element.
+		 *
+		 * @param	layoutOptions	Options that allows you to control how is the element positioned in
+		 *							GUI layout. This will override any similar options set by style.
+		 */
+		void setLayoutOptions(const GUIOptions& layoutOptions);
+
 		/**
 		/**
 		 * @brief	Gets internal element style representing the exact type of GUI element
 		 * @brief	Gets internal element style representing the exact type of GUI element
 		 *			in this object.
 		 *			in this object.

+ 1 - 1
BansheeEngine/Include/BsGUIElementContainer.h

@@ -12,7 +12,7 @@ namespace BansheeEngine
 	class BS_EXPORT GUIElementContainer : public GUIElement
 	class BS_EXPORT GUIElementContainer : public GUIElement
 	{
 	{
 	protected:
 	protected:
-		GUIElementContainer(const GUILayoutOptions& layoutOptions);
+		GUIElementContainer(const GUILayoutOptions& layoutOptions, const String& style = StringUtil::BLANK);
 		virtual ~GUIElementContainer();
 		virtual ~GUIElementContainer();
 
 
 		/**
 		/**

+ 8 - 0
BansheeEngine/Source/BsGUIElement.cpp

@@ -203,6 +203,14 @@ namespace BansheeEngine
 		GUIManager::instance().setFocus(this, enabled);
 		GUIManager::instance().setFocus(this, enabled);
 	}
 	}
 
 
+	void GUIElement::setLayoutOptions(const GUIOptions& layoutOptions)
+	{
+		mLayoutOptions = GUILayoutOptions::create(layoutOptions);
+		mLayoutOptions.updateWithStyle(mStyle);
+
+		markContentAsDirty();
+	}
+
 	RectI GUIElement::getVisibleBounds() const
 	RectI GUIElement::getVisibleBounds() const
 	{
 	{
 		RectI bounds = _getClippedBounds();
 		RectI bounds = _getClippedBounds();

+ 2 - 2
BansheeEngine/Source/BsGUIElementContainer.cpp

@@ -3,8 +3,8 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	GUIElementContainer::GUIElementContainer(const GUILayoutOptions& layoutOptions)
-		:GUIElement(StringUtil::BLANK, layoutOptions)
+	GUIElementContainer::GUIElementContainer(const GUILayoutOptions& layoutOptions, const String& style)
+		:GUIElement(style, layoutOptions)
 	{ }
 	{ }
 
 
 	GUIElementContainer::~GUIElementContainer()
 	GUIElementContainer::~GUIElementContainer()

+ 3 - 2
Inspector.txt

@@ -38,8 +38,9 @@ KEEP IN MIND:
  - Modify C++ Editor fields so that calling setValue doesn't update the visual value until focus is lost
  - Modify C++ Editor fields so that calling setValue doesn't update the visual value until focus is lost
   - When user is currently writing in an input box I don't want refresh to overwrite that value.
   - When user is currently writing in an input box I don't want refresh to overwrite that value.
 
 
-
-
+BUGS
+ - Composite GUI elements like Vector3Field need to set a style with min/max or fixed bounds to their GUIElementContainer
+   otherwise they get clipped when their parent layout is too small
 
 
 
 
 
 

+ 6 - 4
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -9,7 +9,7 @@ namespace BansheeEditor
         private class InspectorData
         private class InspectorData
         {
         {
             public GUIFoldout foldout;
             public GUIFoldout foldout;
-            public GUIFixedSpace space;
+            public GUIPanelContainer container;
             public Inspector inspector;
             public Inspector inspector;
         }
         }
 
 
@@ -28,13 +28,15 @@ namespace BansheeEditor
             for (int i = 0; i < allComponents.Length; i++)
             for (int i = 0; i < allComponents.Length; i++)
             {
             {
                 InspectorData data = new InspectorData();
                 InspectorData data = new InspectorData();
+                GUIPanel inspectorPanel = CreatePanel(0, 0, 0, 0);
 
 
                 data.foldout = new GUIFoldout(allComponents[i].GetType().Name);
                 data.foldout = new GUIFoldout(allComponents[i].GetType().Name);
                 inspectorLayout.AddElement(data.foldout);
                 inspectorLayout.AddElement(data.foldout);
-                data.space = inspectorLayout.AddSpace(0);
+                data.container = new GUIPanelContainer(inspectorPanel);
+                inspectorLayout.AddElement(data.container);
 
 
                 data.inspector = GetInspector(allComponents[i].GetType());
                 data.inspector = GetInspector(allComponents[i].GetType());
-                data.inspector.Initialize(CreatePanel(0, 0, 0, 0), allComponents[i]);
+                data.inspector.Initialize(inspectorPanel, allComponents[i]);
 
 
                 data.foldout.OnToggled += (bool expanded) => Foldout_OnToggled(data.inspector, expanded);
                 data.foldout.OnToggled += (bool expanded) => Foldout_OnToggled(data.inspector, expanded);
 
 
@@ -96,7 +98,7 @@ namespace BansheeEditor
                 int inspectorHeight = inspectorData[i].inspector.GetOptimalHeight();
                 int inspectorHeight = inspectorData[i].inspector.GetOptimalHeight();
 
 
                 inspectorData[i].inspector.SetArea(0, curPosition, width, inspectorHeight);
                 inspectorData[i].inspector.SetArea(0, curPosition, width, inspectorHeight);
-                inspectorData[i].space.SetSize(inspectorHeight);
+                inspectorData[i].container.SetLayoutOptions(GUIOption.FixedHeight(inspectorHeight));
                 curPosition += inspectorHeight;
                 curPosition += inspectorHeight;
             } 
             } 
         }
         }

+ 8 - 0
MBansheeEngine/GUI/GUIElement.cs

@@ -45,9 +45,17 @@ namespace BansheeEngine
             Internal_SetVisible(mCachedPtr, visible);
             Internal_SetVisible(mCachedPtr, visible);
         }
         }
 
 
+        public void SetLayoutOptions(params GUIOption[] options)
+        {
+            Internal_SetLayoutOptions(mCachedPtr, options);
+        }
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetParent(IntPtr nativeInstance, GUILayout parent);
         private static extern void Internal_SetParent(IntPtr nativeInstance, GUILayout parent);
 
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetLayoutOptions(IntPtr nativeInstance, GUIOption[] options);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
         private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
 
 

+ 2 - 4
SBansheeEditor/Include/BsScriptGUIPanelContainer.h

@@ -1,13 +1,13 @@
 #pragma once
 #pragma once
 
 
 #include "BsScriptEditorPrerequisites.h"
 #include "BsScriptEditorPrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 #include "BsGUIPanelContainer.h"
 #include "BsGUIPanelContainer.h"
 #include "BsScriptGUIPanel.h"
 #include "BsScriptGUIPanel.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	class BS_SCR_BED_EXPORT ScriptGUIPanelContainer : public ScriptObject<ScriptGUIPanelContainer>
+	class BS_SCR_BED_EXPORT ScriptGUIPanelContainer : public TScriptGUIElement<ScriptGUIPanelContainer>
 	{
 	{
 	public:
 	public:
 		SCRIPT_OBJ(BansheeEditorAssemblyName, "BansheeEditor", "GUIPanelContainer")
 		SCRIPT_OBJ(BansheeEditorAssemblyName, "BansheeEditor", "GUIPanelContainer")
@@ -17,7 +17,5 @@ namespace BansheeEngine
 		static void internal_setPanel(ScriptGUIPanelContainer* nativeInstance, MonoObject* panel);
 		static void internal_setPanel(ScriptGUIPanelContainer* nativeInstance, MonoObject* panel);
 
 
 		ScriptGUIPanelContainer(MonoObject* instance, GUIPanelContainer* panelContainer);
 		ScriptGUIPanelContainer(MonoObject* instance, GUIPanelContainer* panelContainer);
-
-		GUIPanelContainer* mGUIPanelContainer;
 	};
 	};
 }
 }

+ 1 - 0
SBansheeEditor/Source/BsGUIPanelContainer.cpp

@@ -1,5 +1,6 @@
 #include "BsGUIPanelContainer.h"
 #include "BsGUIPanelContainer.h"
 #include "BsGUIArea.h"
 #include "BsGUIArea.h"
+#include "BsScriptGUIPanel.h"
 #include "BsGUILayout.h"
 #include "BsGUILayout.h"
 #include "BsGUIWidget.h"
 #include "BsGUIWidget.h"
 #include "BsScriptGUIArea.h"
 #include "BsScriptGUIArea.h"

+ 3 - 2
SBansheeEditor/Source/BsScriptGUIPanelContainer.cpp

@@ -10,7 +10,7 @@
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUIPanelContainer::ScriptGUIPanelContainer(MonoObject* instance, GUIPanelContainer* panelContainer)
 	ScriptGUIPanelContainer::ScriptGUIPanelContainer(MonoObject* instance, GUIPanelContainer* panelContainer)
-		:ScriptObject(instance), mGUIPanelContainer(panelContainer)
+		:TScriptGUIElement(instance, panelContainer)
 	{
 	{
 
 
 	}
 	}
@@ -39,6 +39,7 @@ namespace BansheeEngine
 	{
 	{
 		ScriptGUIPanel* guiPanel = ScriptGUIPanel::toNative(panel);
 		ScriptGUIPanel* guiPanel = ScriptGUIPanel::toNative(panel);
 
 
-		nativeInstance->mGUIPanelContainer->setPanel(*guiPanel);
+		GUIPanelContainer* panelContainer = static_cast<GUIPanelContainer*>(nativeInstance->getGUIElement());
+		panelContainer->setPanel(*guiPanel);
 	}
 	}
 }
 }

+ 4 - 0
SBansheeEngine/Include/BsScriptGUIElement.h

@@ -2,6 +2,7 @@
 
 
 #include "BsScriptEnginePrerequisites.h"
 #include "BsScriptEnginePrerequisites.h"
 #include "BsScriptObject.h"
 #include "BsScriptObject.h"
+#include "BsGUIOptions.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -15,6 +16,7 @@ namespace BansheeEngine
 
 
 		virtual void destroy() = 0;
 		virtual void destroy() = 0;
 		virtual void setParent(GUILayout* layout) = 0;
 		virtual void setParent(GUILayout* layout) = 0;
+		virtual void setLayoutOptions(GUIOptions options) { }
 
 
 	protected:
 	protected:
 		void initialize(GUIElementBase* element);
 		void initialize(GUIElementBase* element);
@@ -55,6 +57,7 @@ namespace BansheeEngine
 
 
 		virtual void destroy();
 		virtual void destroy();
 		virtual void setParent(GUILayout* layout);
 		virtual void setParent(GUILayout* layout);
+		virtual void setLayoutOptions(GUIOptions options);
 	};
 	};
 
 
 	template <class Type>
 	template <class Type>
@@ -90,6 +93,7 @@ namespace BansheeEngine
 		static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
 		static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
 		static void internal_setParent(ScriptGUIElementBaseTBase* nativeInstance, MonoObject* parentLayout);
 		static void internal_setParent(ScriptGUIElementBaseTBase* nativeInstance, MonoObject* parentLayout);
+		static void internal_setLayoutOptions(ScriptGUIElementBaseTBase* nativeInstance, MonoArray* guiOptions);
 
 
 		ScriptGUIElement(MonoObject* instance);
 		ScriptGUIElement(MonoObject* instance);
 	};
 	};

+ 1 - 0
SBansheeEngine/Include/BsScriptGUIPanel.h

@@ -21,6 +21,7 @@ namespace BansheeEngine
 		void unregisterArea(ScriptGUIArea* area);
 		void unregisterArea(ScriptGUIArea* area);
 
 
 		const Vector<ScriptGUIArea*>& getAreas() const { return mAreas; }
 		const Vector<ScriptGUIArea*>& getAreas() const { return mAreas; }
+		RectI getArea() const { return mMyArea; }
 
 
 	protected:
 	protected:
 		ScriptGUIPanel(MonoObject* instance);
 		ScriptGUIPanel(MonoObject* instance);

+ 18 - 0
SBansheeEngine/Source/BsScriptGUIElement.cpp

@@ -47,6 +47,12 @@ namespace BansheeEngine
 		layout->addElement((GUIElement*)mElement);
 		layout->addElement((GUIElement*)mElement);
 	}
 	}
 
 
+	void ScriptGUIElementTBase::setLayoutOptions(GUIOptions options)
+	{
+		GUIElement* element = static_cast<GUIElement*>(mElement);
+		element->setLayoutOptions(options);
+	}
+
 	ScriptGUIElement::ScriptGUIElement(MonoObject* instance)
 	ScriptGUIElement::ScriptGUIElement(MonoObject* instance)
 		:ScriptObject(instance)
 		:ScriptObject(instance)
 	{
 	{
@@ -58,6 +64,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIElement::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIElement::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIElement::internal_setVisible);
 		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIElement::internal_setVisible);
 		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIElement::internal_setParent);
 		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIElement::internal_setParent);
+		metaData.scriptClass->addInternalCall("Internal_SetLayoutOptions", &ScriptGUIElement::internal_setLayoutOptions);
 	}
 	}
 
 
 	void ScriptGUIElement::internal_destroy(ScriptGUIElementBaseTBase* nativeInstance)
 	void ScriptGUIElement::internal_destroy(ScriptGUIElementBaseTBase* nativeInstance)
@@ -80,4 +87,15 @@ namespace BansheeEngine
 
 
 		nativeInstance->setParent(nativeLayout);
 		nativeInstance->setParent(nativeLayout);
 	}
 	}
+
+	void ScriptGUIElement::internal_setLayoutOptions(ScriptGUIElementBaseTBase* nativeInstance, MonoArray* guiOptions)
+	{
+		GUIOptions options;
+
+		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
+		for (UINT32 i = 0; i < arrayLen; i++)
+			options.addOption(mono_array_get(guiOptions, GUIOption, i));
+
+		nativeInstance->setLayoutOptions(options);
+	}
 }
 }