瀏覽代碼

Better way of dealing with GUI layout clipping

Marko Pintera 12 年之前
父節點
當前提交
d8914ff7fe
共有 2 個文件被更改,包括 8 次插入2 次删除
  1. 6 2
      BansheeEngine/Source/BsGUILayoutX.cpp
  2. 2 0
      TODO.txt

+ 6 - 2
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -183,10 +183,14 @@ namespace BansheeEngine
 
 				UINT32 yOffset = (UINT32)Math::CeilToInt((height - child.element->_getHeight()) * 0.5f);
 
-				child.element->_setOffset(Int2(x + xOffset, y + yOffset));
+				Int2 offset(x + xOffset, y + yOffset);
+				child.element->_setOffset(offset);
 				child.element->_setDepth(depth);
 
-				child.element->_setClipRect(Rect(0, 0, child.element->_getWidth(), child.element->_getHeight()));
+				UINT32 clippedWidth = (UINT32)std::min((INT32)child.element->_getWidth(), (INT32)width - offset.x);
+				UINT32 clippedHeight = (UINT32)std::min((INT32)child.element->_getHeight(), (INT32)height - offset.y);
+
+				child.element->_setClipRect(Rect(0, 0, clippedWidth, clippedHeight));
 
 				xOffset += child.element->_getWidth();
 			}

+ 2 - 0
TODO.txt

@@ -23,6 +23,8 @@ GUIWidget::updateMeshes leaks. If I leave the game running I can see memory cont
 
 IMMEDIATE:
  - Implement GUILayoutY
+ - Clip rect: Fixed size (or min clamped) elements that don't fit within the layout?!
+   - Imagine two vertical layouts next to each other, each 100 pixels, and the left one has 200 pix wide elements which crosses over to the next layout.
 
  Test multiple layout elements
 Test nested elements