From 19b7fa703ea63dac755bd2d43bef29c5eb20966e Mon Sep 17 00:00:00 2001 From: spartanj Date: Mon, 15 Nov 2010 03:06:50 -0300 Subject: [PATCH] Some minor fixes on the ListBox. --- src/test/ee.cpp | 4 +++- src/ui/cuilistbox.cpp | 34 ++++++++++++++++++++++++++++++---- src/ui/cuilistbox.hpp | 4 ++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/test/ee.cpp b/src/test/ee.cpp index e9a8d3d31..ca6c30bfb 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -555,7 +555,7 @@ void cEETest::CreateUI() { mListBox->Visible( true ); mListBox->Enabled( true ); - for ( Int32 i = 1; i <= 25; i++ ) + for ( Int32 i = 1; i <= 12; i++ ) mListBox->AddListBoxItem( L"Test ListBox " + toWStr(i) + L" testing it right now!" ); mBuda = L"El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde."; @@ -587,6 +587,8 @@ void cEETest::ButtonClick( const cUIEvent * Event ) { Gfx->StartRotation( 0, 2500, 2500 ); Gfx->StartMovement( eeVector2i( eeRandi( 0, EE->GetWidth() ), -64 ), eeVector2i( eeRandi( 0, EE->GetWidth() ), EE->GetHeight() + 64 ), 2500 ); Gfx->CloseFadeOut( 3500 ); + + mListBox->AddListBoxItem( L"Test ListBox " + toWStr( mListBox->Size()+1 ) + L" testing it right now!" ); } } diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index 516fd6779..1dd9b13cd 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -110,10 +110,16 @@ Uint32 cUIListBox::AddListBoxItem( cUIListBoxItem * Item ) { if ( !mDisableScrollUpdate ) UpdateScroll(); + Uint32 tMaxTextWidth = mMaxTextWidth; + ItemUpdateSize( Item ); - Item->Visible( false ); - Item->Enabled( false ); + if ( tMaxTextWidth != mMaxTextWidth ) { + UpdateListBoxItemsSize(); + + if ( !mDisableScrollUpdate ) + UpdateScroll(); + } return mItems.size() - 1; } @@ -178,6 +184,7 @@ void cUIListBox::RemoveListBoxItems( std::vector ItemsIndex ) { mItems = ItemsCpy; UpdateScroll(); + FindMaxWidth(); UpdateListBoxItemsSize(); } } @@ -262,11 +269,23 @@ void cUIListBox::SetRowHeight() { } } -void cUIListBox::UpdateListBoxItemsSize() { +void cUIListBox::FindMaxWidth() { Uint32 size = mItems.size(); + Int32 width; mMaxTextWidth = 0; + for ( Uint32 i = 0; i < size; i++ ) { + width = mItems[i]->GetTextCache().GetTextWidth(); + + if ( width > (Int32)mMaxTextWidth ) + mMaxTextWidth = (Uint32)width; + } +} + +void cUIListBox::UpdateListBoxItemsSize() { + Uint32 size = mItems.size(); + for ( Uint32 i = 0; i < size; i++ ) { ItemUpdateSize( mItems[i] ); } @@ -276,7 +295,7 @@ void cUIListBox::ItemUpdateSize( cUIListBoxItem * Item ) { Int32 width = Item->GetTextCache().GetTextWidth(); if ( width > (Int32)mMaxTextWidth ) - mMaxTextWidth = width; + mMaxTextWidth = (Uint32)width; if ( !mHScrollBar->Visible() ) { if ( width < mContainer->Size().Width() ) @@ -284,6 +303,8 @@ void cUIListBox::ItemUpdateSize( cUIListBoxItem * Item ) { if ( ( mItemsNotVisible > 0 || mScrollAlwaysVisible ) ) width -= mScrollBar->Size().Width(); + } else { + width = mMaxTextWidth; } Item->Size( width, mRowHeight ); @@ -520,6 +541,7 @@ void cUIListBox::Font( cFont * Font ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) mItems[i]->Font( mFont ); + FindMaxWidth(); UpdateListBoxItemsSize(); UpdateScroll(); } @@ -591,4 +613,8 @@ const bool& cUIListBox::AllowHorizontalScroll() const { return mAllowHorizontalScroll; } +Uint32 cUIListBox::Size() { + return mItems.size(); +} + }} diff --git a/src/ui/cuilistbox.hpp b/src/ui/cuilistbox.hpp index 40c317635..c245958b1 100644 --- a/src/ui/cuilistbox.hpp +++ b/src/ui/cuilistbox.hpp @@ -113,6 +113,8 @@ class EE_API cUIListBox : public cUIControlAnim { void AllowHorizontalScroll( const bool& allow ); const bool& AllowHorizontalScroll() const; + + Uint32 Size(); protected: friend class cUIListBoxItem; @@ -163,6 +165,8 @@ class EE_API cUIListBox : public cUIControlAnim { void ItemUpdateSize( cUIListBoxItem * Item ); void AutoPadding(); + + void FindMaxWidth(); }; }}