Explorar el Código

Cleaned up ListView content resize in regard to automatic scrollbar visibility.

Lasse Öörni hace 12 años
padre
commit
97a30bbe78
Se han modificado 4 ficheros con 12 adiciones y 17 borrados
  1. 2 14
      Engine/UI/ListView.cpp
  2. 0 2
      Engine/UI/ListView.h
  3. 8 1
      Engine/UI/ScrollView.cpp
  4. 2 0
      Engine/UI/ScrollView.h

+ 2 - 14
Engine/UI/ListView.cpp

@@ -68,6 +68,8 @@ ListView::ListView(Context* context) :
     doubleClickInterval_(500),
     doubleClickInterval_(500),
     lastClickedItem_(M_MAX_UNSIGNED)
     lastClickedItem_(M_MAX_UNSIGNED)
 {
 {
+    resizeContentWidth_ = true;
+    
     UIElement* container = new UIElement(context_);
     UIElement* container = new UIElement(context_);
     container->SetInternal(true);
     container->SetInternal(true);
     container->SetActive(true);
     container->SetActive(true);
@@ -194,20 +196,6 @@ void ListView::OnKey(int key, int buttons, int qualifiers)
     SendEvent(E_UNHANDLEDKEY, eventData);
     SendEvent(E_UNHANDLEDKEY, eventData);
 }
 }
 
 
-void ListView::OnResize()
-{
-    ScrollView::OnResize();
-    
-    // Set the content element width to match the scrollpanel minus clipping
-    IntRect panelBorder = scrollPanel_->GetClipBorder();
-    contentElement_->SetWidth(scrollPanel_->GetWidth() - panelBorder.left_ - panelBorder.right_);
-    
-    // If scrollbar autovisibility is enabled, need one final pass to correct the view
-    /// \todo Rework, this is inefficient
-    if (scrollBarsAutoVisible_)
-        ScrollView::OnResize();
-}
-
 void ListView::AddItem(UIElement* item)
 void ListView::AddItem(UIElement* item)
 {
 {
     InsertItem(contentElement_->GetNumChildren(), item);
     InsertItem(contentElement_->GetNumChildren(), item);

+ 0 - 2
Engine/UI/ListView.h

@@ -54,8 +54,6 @@ public:
     
     
     /// React to a key press.
     /// React to a key press.
     virtual void OnKey(int key, int buttons, int qualifiers);
     virtual void OnKey(int key, int buttons, int qualifiers);
-    /// React to resize.
-    virtual void OnResize();
     
     
     /// Add item to the end of the list.
     /// Add item to the end of the list.
     void AddItem(UIElement* item);
     void AddItem(UIElement* item);

+ 8 - 1
Engine/UI/ScrollView.cpp

@@ -44,7 +44,8 @@ ScrollView::ScrollView(Context* context) :
     viewPositionAttr_(IntVector2::ZERO),
     viewPositionAttr_(IntVector2::ZERO),
     pageStep_(1.0f),
     pageStep_(1.0f),
     scrollBarsAutoVisible_(true),
     scrollBarsAutoVisible_(true),
-    ignoreEvents_(false)
+    ignoreEvents_(false),
+    resizeContentWidth_(false)
 {
 {
     clipChildren_ = true;
     clipChildren_ = true;
     active_ = true;
     active_ = true;
@@ -279,6 +280,12 @@ void ScrollView::UpdatePanelSize()
     horizontalScrollBar_->SetWidth(scrollPanel_->GetWidth());
     horizontalScrollBar_->SetWidth(scrollPanel_->GetWidth());
     verticalScrollBar_->SetHeight(scrollPanel_->GetHeight());
     verticalScrollBar_->SetHeight(scrollPanel_->GetHeight());
     
     
+    if (resizeContentWidth_ && contentElement_)
+    {
+        IntRect panelBorder = scrollPanel_->GetClipBorder();
+        contentElement_->SetWidth(scrollPanel_->GetWidth() - panelBorder.left_ - panelBorder.right_);
+    }
+    
     ignoreEvents_ = false;
     ignoreEvents_ = false;
 }
 }
 
 

+ 2 - 0
Engine/UI/ScrollView.h

@@ -117,6 +117,8 @@ protected:
     bool scrollBarsAutoVisible_;
     bool scrollBarsAutoVisible_;
     /// Ignore scrollbar events flag. Used to prevent possible endless loop when resizing.
     /// Ignore scrollbar events flag. Used to prevent possible endless loop when resizing.
     bool ignoreEvents_;
     bool ignoreEvents_;
+    /// Resize content widget width to match panel. Internal flag, used by the ListView class.
+    bool resizeContentWidth_;
     
     
 private:
 private:
     /// Handle scrollbar value changed.
     /// Handle scrollbar value changed.