浏览代码

Added flag to ScrollView / ListView whether to set scrollbar visibility automatically. Default true. Calling SetScrollBarsVisible() disables this.

Lasse Öörni 12 年之前
父节点
当前提交
07c0f7228a
共有 4 个文件被更改,包括 31 次插入7 次删除
  1. 2 0
      Docs/ScriptAPI.dox
  2. 4 0
      Engine/Engine/UIAPI.cpp
  3. 17 5
      Engine/UI/ScrollView.cpp
  4. 8 2
      Engine/UI/ScrollView.h

+ 2 - 0
Docs/ScriptAPI.dox

@@ -3916,6 +3916,7 @@ Properties:<br>
 - ScrollBar@ horizontalScrollBar (readonly)
 - ScrollBar@ horizontalScrollBar (readonly)
 - ScrollBar@ verticalScrollBar (readonly)
 - ScrollBar@ verticalScrollBar (readonly)
 - BorderImage@ scrollPanel (readonly)
 - BorderImage@ scrollPanel (readonly)
+- bool scrollBarsAutoVisible
 
 
 
 
 ListView
 ListView
@@ -4038,6 +4039,7 @@ Properties:<br>
 - ScrollBar@ horizontalScrollBar (readonly)
 - ScrollBar@ horizontalScrollBar (readonly)
 - ScrollBar@ verticalScrollBar (readonly)
 - ScrollBar@ verticalScrollBar (readonly)
 - BorderImage@ scrollPanel (readonly)
 - BorderImage@ scrollPanel (readonly)
+- bool scrollBarsAutoVisible
 - float scrollStep
 - float scrollStep
 - float pageStep
 - float pageStep
 - uint numItems (readonly)
 - uint numItems (readonly)

+ 4 - 0
Engine/Engine/UIAPI.cpp

@@ -179,6 +179,8 @@ static void RegisterScrollView(asIScriptEngine* engine)
     engine->RegisterObjectMethod("ScrollView", "ScrollBar@+ get_horizontalScrollBar() const", asMETHOD(ScrollView, GetHorizontalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ScrollView", "ScrollBar@+ get_horizontalScrollBar() const", asMETHOD(ScrollView, GetHorizontalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ScrollView", "ScrollBar@+ get_verticalScrollBar() const", asMETHOD(ScrollView, GetVerticalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ScrollView", "ScrollBar@+ get_verticalScrollBar() const", asMETHOD(ScrollView, GetVerticalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ScrollView", "BorderImage@+ get_scrollPanel() const", asMETHOD(ScrollView, GetScrollPanel), asCALL_THISCALL);
     engine->RegisterObjectMethod("ScrollView", "BorderImage@+ get_scrollPanel() const", asMETHOD(ScrollView, GetScrollPanel), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ScrollView", "void set_scrollBarsAutoVisible(bool)", asMETHOD(ScrollView, SetScrollBarsAutoVisible), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ScrollView", "bool get_scrollBarsAutoVisible() const", asMETHOD(ScrollView, GetScrollBarsAutoVisible), asCALL_THISCALL);
 }
 }
 
 
 void ListViewSetSelections(CScriptArray* selections, ListView* ptr)
 void ListViewSetSelections(CScriptArray* selections, ListView* ptr)
@@ -242,6 +244,8 @@ static void RegisterListView(asIScriptEngine* engine)
     engine->RegisterObjectMethod("ListView", "ScrollBar@+ get_horizontalScrollBar() const", asMETHOD(ListView, GetHorizontalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "ScrollBar@+ get_horizontalScrollBar() const", asMETHOD(ListView, GetHorizontalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "ScrollBar@+ get_verticalScrollBar() const", asMETHOD(ListView, GetVerticalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "ScrollBar@+ get_verticalScrollBar() const", asMETHOD(ListView, GetVerticalScrollBar), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "BorderImage@+ get_scrollPanel() const", asMETHOD(ListView, GetScrollPanel), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "BorderImage@+ get_scrollPanel() const", asMETHOD(ListView, GetScrollPanel), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ListView", "void set_scrollBarsAutoVisible(bool)", asMETHOD(ListView, SetScrollBarsAutoVisible), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ListView", "bool get_scrollBarsAutoVisible() const", asMETHOD(ListView, GetScrollBarsAutoVisible), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void set_scrollStep(float)", asMETHOD(ListView, SetScrollStep), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void set_scrollStep(float)", asMETHOD(ListView, SetScrollStep), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "float get_scrollStep() const", asMETHOD(ListView, GetScrollStep), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "float get_scrollStep() const", asMETHOD(ListView, GetScrollStep), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void set_pageStep(float)", asMETHOD(ListView, SetPageStep), asCALL_THISCALL);
     engine->RegisterObjectMethod("ListView", "void set_pageStep(float)", asMETHOD(ListView, SetPageStep), asCALL_THISCALL);

+ 17 - 5
Engine/UI/ScrollView.cpp

@@ -42,7 +42,9 @@ ScrollView::ScrollView(Context* context) :
     viewPosition_(IntVector2::ZERO),
     viewPosition_(IntVector2::ZERO),
     viewSize_(IntVector2::ZERO),
     viewSize_(IntVector2::ZERO),
     viewPositionAttr_(IntVector2::ZERO),
     viewPositionAttr_(IntVector2::ZERO),
-    pageStep_(1.0f)
+    pageStep_(1.0f),
+    scrollBarsAutoVisible_(true),
+    ignoreEvents_(false)
 {
 {
     clipChildren_ = true;
     clipChildren_ = true;
     active_ = true;
     active_ = true;
@@ -78,6 +80,7 @@ void ScrollView::RegisterObject(Context* context)
     REF_ACCESSOR_ATTRIBUTE(ScrollView, VAR_INTVECTOR2, "View Position", GetViewPosition, SetViewPositionAttr, IntVector2, IntVector2::ZERO, AM_FILE);
     REF_ACCESSOR_ATTRIBUTE(ScrollView, VAR_INTVECTOR2, "View Position", GetViewPosition, SetViewPositionAttr, IntVector2, IntVector2::ZERO, AM_FILE);
     ACCESSOR_ATTRIBUTE(ScrollView, VAR_FLOAT, "Scroll Step", GetScrollStep, SetScrollStep, float, 0.1f, AM_FILE);
     ACCESSOR_ATTRIBUTE(ScrollView, VAR_FLOAT, "Scroll Step", GetScrollStep, SetScrollStep, float, 0.1f, AM_FILE);
     ACCESSOR_ATTRIBUTE(ScrollView, VAR_FLOAT, "Page Step", GetPageStep, SetPageStep, float, 1.0f, AM_FILE);
     ACCESSOR_ATTRIBUTE(ScrollView, VAR_FLOAT, "Page Step", GetPageStep, SetPageStep, float, 1.0f, AM_FILE);
+    ACCESSOR_ATTRIBUTE(ScrollView, VAR_BOOL, "Auto Show/Hide Scrollbars", GetScrollBarsAutoVisible, SetScrollBarsAutoVisible, bool, true, AM_FILE);
     COPY_BASE_ATTRIBUTES(ScrollView, UIElement);
     COPY_BASE_ATTRIBUTES(ScrollView, UIElement);
 }
 }
 
 
@@ -221,6 +224,12 @@ void ScrollView::SetScrollBarsVisible(bool horizontal, bool vertical)
 {
 {
     horizontalScrollBar_->SetVisible(horizontal);
     horizontalScrollBar_->SetVisible(horizontal);
     verticalScrollBar_->SetVisible(vertical);
     verticalScrollBar_->SetVisible(vertical);
+    scrollBarsAutoVisible_ = false;
+}
+
+void ScrollView::SetScrollBarsAutoVisible(bool enable)
+{
+    scrollBarsAutoVisible_ = enable;
 }
 }
 
 
 void ScrollView::SetScrollStep(float step)
 void ScrollView::SetScrollStep(float step)
@@ -275,8 +284,9 @@ void ScrollView::UpdateScrollBars()
         horizontalScrollBar_->SetValue((float)viewPosition_.x_ / (float)size.x_);
         horizontalScrollBar_->SetValue((float)viewPosition_.x_ / (float)size.x_);
         horizontalScrollBar_->SetStepFactor(STEP_FACTOR / (float)size.x_);
         horizontalScrollBar_->SetStepFactor(STEP_FACTOR / (float)size.x_);
         
         
-        // Hide/Show the horizontal scroll bar as needed
-        needResize = SetScrollBarVisible(horizontalScrollBar_, range > 0.0f);
+        // Hide/show the horizontal scroll bar as needed
+        if (scrollBarsAutoVisible_)
+            needResize = SetScrollBarVisible(horizontalScrollBar_, range > 0.0f);
     }
     }
     if (verticalScrollBar_ && size.y_ > 0 && viewSize_.y_ > 0)
     if (verticalScrollBar_ && size.y_ > 0 && viewSize_.y_ > 0)
     {
     {
@@ -285,11 +295,13 @@ void ScrollView::UpdateScrollBars()
         verticalScrollBar_->SetValue((float)viewPosition_.y_ / (float)size.y_);
         verticalScrollBar_->SetValue((float)viewPosition_.y_ / (float)size.y_);
         verticalScrollBar_->SetStepFactor(STEP_FACTOR / (float)size.y_);
         verticalScrollBar_->SetStepFactor(STEP_FACTOR / (float)size.y_);
         
         
-        // Hide/Show the vertical scroll bar as needed
-        needResize = SetScrollBarVisible(verticalScrollBar_, range > 0.0f) || needResize;
+        // Hide/show the vertical scroll bar as needed
+        if (scrollBarsAutoVisible_)
+            needResize = SetScrollBarVisible(verticalScrollBar_, range > 0.0f) || needResize;
     }
     }
     
     
     ignoreEvents_ = false;
     ignoreEvents_ = false;
+    
     // Since the scrollbar visibility changed event is intentionally ignored to prevent
     // Since the scrollbar visibility changed event is intentionally ignored to prevent
     // infinite loop in the above code, call OnResize now if needed
     // infinite loop in the above code, call OnResize now if needed
     if (needResize)
     if (needResize)

+ 8 - 2
Engine/UI/ScrollView.h

@@ -58,8 +58,10 @@ public:
     void SetViewPosition(const IntVector2& position);
     void SetViewPosition(const IntVector2& position);
     /// Set view offset from the top-left corner.
     /// Set view offset from the top-left corner.
     void SetViewPosition(int x, int y);
     void SetViewPosition(int x, int y);
-    /// Set scrollbars' visibility.
+    /// Set scrollbars' visibility manually. Disables scrollbar autoshow/hide.
     void SetScrollBarsVisible(bool horizontal, bool vertical);
     void SetScrollBarsVisible(bool horizontal, bool vertical);
+    /// Set whether to automatically show/hide scrollbars. Default true.
+    void SetScrollBarsAutoVisible(bool enable);
     /// Set arrow key scroll step. Also sets it on the scrollbars.
     /// Set arrow key scroll step. Also sets it on the scrollbars.
     void SetScrollStep(float step);
     void SetScrollStep(float step);
     /// Set arrow key page step.
     /// Set arrow key page step.
@@ -75,6 +77,8 @@ public:
     ScrollBar* GetVerticalScrollBar() const { return verticalScrollBar_; }
     ScrollBar* GetVerticalScrollBar() const { return verticalScrollBar_; }
     /// Return scroll panel.
     /// Return scroll panel.
     BorderImage* GetScrollPanel() const { return scrollPanel_; }
     BorderImage* GetScrollPanel() const { return scrollPanel_; }
+    /// Return whether scrollbars are automatically shown/hidden.
+    bool GetScrollBarsAutoVisible() const { return scrollBarsAutoVisible_; }
     /// Return arrow key scroll step.
     /// Return arrow key scroll step.
     float GetScrollStep() const;
     float GetScrollStep() const;
     /// Return arrow key page step.
     /// Return arrow key page step.
@@ -107,7 +111,9 @@ protected:
     IntVector2 viewPositionAttr_;
     IntVector2 viewPositionAttr_;
     /// Arrow key page step.
     /// Arrow key page step.
     float pageStep_;
     float pageStep_;
-    /// Ignore scrollbar events flag. Used to prevent possible endless loop when setting position.
+    /// Automatically show/hide scrollbars flag.
+    bool scrollBarsAutoVisible_;
+    /// Ignore scrollbar events flag. Used to prevent possible endless loop when resizing.
     bool ignoreEvents_;
     bool ignoreEvents_;
     
     
 private:
 private: