Browse Source

Added optional clearing of selection on defocus to ListView.
Added -uitest switch to GraphicsTest script, which will instantiate test UI layouts.

Lasse Öörni 15 years ago
parent
commit
63ccafc437
4 changed files with 32 additions and 3 deletions
  1. 12 2
      Bin/Data/Scripts/GraphicsTest.as
  2. 2 0
      Engine/Engine/RegisterUI.cpp
  3. 11 0
      Engine/UI/ListView.cpp
  4. 7 1
      Engine/UI/ListView.h

+ 12 - 2
Bin/Data/Scripts/GraphicsTest.as

@@ -325,7 +325,17 @@ void initUI()
     cursor.setPosition(renderer.getWidth() / 2, renderer.getHeight() / 2);
     ui.setCursor(cursor);
 
-	/*
+    bool uiTest = false;
+    array<string> arguments = getArguments();
+    for (uint i = 0; i < arguments.length(); ++i)
+    {
+        if (arguments[i] == "-uitest")
+            uiTest = true;
+    }
+
+    if (!uiTest)
+        return;
+    
     XMLFile@ uiLayout = cache.getResource("XMLFile", "UI/TestLayout.xml");
     UIElement@ layoutRoot = ui.loadLayout(uiLayout, uiStyle);
     uiRoot.addChild(layoutRoot);
@@ -343,7 +353,7 @@ void initUI()
     fileSelector.setFilters(filters, 0);
 
     subscribeToEvent(fileSelector, "FileSelected", "handleFileSelected");
-    */
+
 }
 
 void handleFileSelected(StringHash eventType, VariantMap& eventData)

+ 2 - 0
Engine/Engine/RegisterUI.cpp

@@ -247,6 +247,7 @@ static void registerListView(asIScriptEngine* engine)
     engine->RegisterObjectMethod("ListView", "void setHighlightMode(HighlightMode)", asMETHOD(ListView, setHighlightMode), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void setMultiselect(bool)", asMETHOD(ListView, setMultiselect), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void setHierarchyMode(bool)", asMETHOD(ListView, setHierarchyMode), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ListView", "void setClearSelectionOnDefocus(bool)", asMETHOD(ListView, setClearSelectionOnDefocus), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void setDoubleClickInterval(float)", asMETHOD(ListView, setDoubleClickInterval), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void setChildItemsVisible(uint, bool)", asMETHOD(ListView, setChildItemsVisible), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void toggleChildItemsVisible(uint)", asMETHOD(ListView, toggleChildItemsVisible), asCALL_THISCALL);
@@ -269,6 +270,7 @@ static void registerListView(asIScriptEngine* engine)
     engine->RegisterObjectMethod("ListView", "HighlightMode getHighlightMode() const", asMETHOD(ListView, getHighlightMode), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "bool getMultiselect() const", asMETHOD(ListView, getMultiselect), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "bool getHierarchyMode() const", asMETHOD(ListView, getHierarchyMode), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ListView", "bool getClearSelectionOnDefocus() const", asMETHOD(ListView, getClearSelectionOnDefocus), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "float getDoubleClickInterval() const", asMETHOD(ListView, getDoubleClickInterval), asCALL_THISCALL);
     registerRefCasts<UIElement, ListView>(engine, "UIElement", "ListView");
 }

+ 11 - 0
Engine/UI/ListView.cpp

@@ -52,6 +52,7 @@ ListView::ListView(const std::string& name) :
     mHighlightMode(HM_FOCUS),
     mMultiselect(false),
     mHierarchyMode(false),
+    mClearSelectionOnDefocus(false),
     mDoubleClickInterval(0.5f),
     mDoubleClickTimer(0.0f),
     mLastClickedItem(M_MAX_UNSIGNED)
@@ -98,6 +99,8 @@ void ListView::setStyle(const XMLElement& element, ResourceCache* cache)
         setMultiselect(element.getChildElement("multiselect").getBool("enable"));
     if (element.hasChildElement("hierarchymode"))
         setHierarchyMode(element.getChildElement("hierarchymode").getBool("enable"));
+    if (element.hasChildElement("clearselection"))
+        setClearSelectionOnDefocus(element.getChildElement("clearselection").getBool("enable"));
     if (element.hasChildElement("doubleclickinterval"))
         setDoubleClickInterval(element.getChildElement("doubleclickinterval").getFloat("value"));
     
@@ -249,6 +252,9 @@ void ListView::onFocus()
 
 void ListView::onDefocus()
 {
+    if (mClearSelectionOnDefocus)
+        clearSelection();
+    
     updateSelectionEffect();
 }
 
@@ -487,6 +493,11 @@ void ListView::setHierarchyMode(bool enable)
     mHierarchyMode = enable;
 }
 
+void ListView::setClearSelectionOnDefocus(bool enable)
+{
+    mClearSelectionOnDefocus = enable;
+}
+
 void ListView::setDoubleClickInterval(float interval)
 {
     mDoubleClickInterval = interval;

+ 7 - 1
Engine/UI/ListView.h

@@ -39,7 +39,7 @@ enum HighlightMode
     HM_ALWAYS
 };
 
-//! A scrollable list
+//! A scrollable list of items
 class ListView : public ScrollView
 {
     DEFINE_TYPE(ListView);
@@ -91,6 +91,8 @@ public:
     void setMultiselect(bool enable);
     //! Enable hierarchy mode. Allows hiding/showing items that have "indent" userdata
     void setHierarchyMode(bool enable);
+    //! Enable clearing of selection on defocus
+    void setClearSelectionOnDefocus(bool enable);
     //! Set item doubleclick interval in seconds
     void setDoubleClickInterval(float interval);
     //! Show or hide child items starting from index. Only has effect in hierarchy mode
@@ -116,6 +118,8 @@ public:
     HighlightMode getHighlightMode() const { return mHighlightMode; }
     //! Return whether multiselect enabled
     bool getMultiselect() const { return mMultiselect; }
+    //! Return whether selection is cleared on defocus
+    bool getClearSelectionOnDefocus() const { return mClearSelectionOnDefocus; }
     //! Return whether hierarchy mode enabled
     bool getHierarchyMode() const { return mHierarchyMode; }
     //! Return item doubleclick interval in seconds
@@ -135,6 +139,8 @@ protected:
     bool mMultiselect;
     //! Hierarchy mode flag
     bool mHierarchyMode;
+    //! Clear selection on defocus flag
+    bool mClearSelectionOnDefocus;
     //! Doubleclick interval
     float mDoubleClickInterval;
     //! Doubleclick timer