Categories: Symbian C++ | S60 | UI | Code Examples | How To
This page was last modified 19:44, 20 January 2008.
How to Create a Scrollable Container
From Forum Nokia Wiki
Contents |
Need for a scrollable container
Now a days many controls are present in a single view making the visibility of the control an point to argue on due to the limited screen dimensions. One way to overcome the problem is by placing all the controls over the container and when you want to bring the particular control in the view you can just move all the controls by the offset value upwards and downwards But doing this is tedious and might be difficult to maintain in the future and not a good logic . The other way around is to use the property of CCoeControl to move entirely up and down along with its contents( moving the entire container up and down ) instead of moving all the controls. Below is the way to do it.
Note :- for simplicity functions related to scrolling are only implemented.
Creating the scrollable container
You need to create two compound controls CParentContainer & CChildContainer.
class CParentContainer:public CCoeControl { public: TKeyResponse OfferKeyEventL(const TKeyEvent &aKeyEvent,TEventCode aType); Private: RPointerArray<CCoeControl> iParentArray; CChildContainer* iChildContainer; }; class CChildContainer:public CCoeControl { public: TKeyResponse OfferKeyEventL(const TKeyEvent &aKeyEvent,TEventCode aType); Private : RPointerArray<CCoeControl> iChildArray; CParentContainer* iParent };
ConstructL function of CParentContainer & CChildContainer
/* * @ param aRect :- Rect passed for the application */ void CParentContainer :: ConstructL(TRect &aRect) { CreateWindowL(); iChildContainer = CChildContainer::NewL( aRect); iParentArray.Append(iChildContainer); ActivateL(); } /* * @param aRect :- Rect with in which all controls should be shown */ void CChildContainer::ConstructL(TRect & aRect,CParentContainer& aParent) { iParent = aParent; // Create 1st control iChildArray.Append(iControl1); // Create 2st control iChildArray.Append(iControl2); // Create nth control iChildArray.Append(iControln); }
Performing the layout of Containers
void CParentContainer ::SetLayout() { SetExtent(Rect().iTl,Rect().Size()); iChildContainer-> SetLayout(Rect(),Rect().Width()); } void CChildContainer::SetLayout(TPoint aPoint, TInt aWidth) { TInt newHeight = 0; newHeight = iControl1.Size().iHeight + iControl2.Size().iHeight +.... .....+ iControln.Size().iHeight // set the extent of the container to the new height SetExtent(aPoint, TSize(aWidth, newHeight)); }
Scrolling Calculation
/** Scroll the page up and down */ void CChildContainer :: ScrollTheContainer(TScrollDirection aDirection, TInt aMovePixels) { /** Get the current position */ TPoint iPosition = Position(); /** If user press Up Key */ if(aDirection == EPageMovementUp) { /** move the container upward by adding aMovePixels to Container Y co-ordinate */ } /** if user press down key */ else if(aDirection == EPageMovementDown) { /** move the container downward by subtracting aMovePixels to Container Y co-ordinate */ } /** Set the position */ SetPosition(iPosition); } TBool CChildContainer :: UpMovementPossible() { if(Position().iY >= iParent.Rect().iTl.iY) return EFalse; else return ETrue; } TBool CChildContainer:: DownMovementPossible() { if(Rect().Height() + Position().iY < iParent.Rect().iBr.iY ) return EFalse; else return ETrue; }
OfferKeyEventL
TKeyResponse CChildContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) { if(aType != EEventKey) { return EKeyWasNotConsumed; } switch (aKeyEvent.iScanCode) { case EStdKeyUpArrow : { if(!UpMovementPossible()) { return EKeyWasNotConsumed; } else { TInt move_pixels = iParent.Rect().Height()* 0.10; ScrollTheContainer(EPageMovementUp, move_pixels); return EKeyWasConsumed; } break; } case EStdKeyDownArrow : { if(!DownMovementPossible()) { return EKeyWasNotConsumed; } else { TInt move_pixels = iParent.Rect().Height()* 0.12; ScrollTheContainer(EPageMovementDown, move_pixels); return EKeyWasConsumed; } break; } }; return EKeyWasNotConsumed; } /* Offer KeyEventL of Parent Container*/ TKeyResponse CParentContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType ) { TKeyResponse keyRes = EKeyWasNotConsumed; if(aType != EEventKey) { return EKeyWasNotConsumed; } keyRes = iChildContainer->OfferKeyEventL(aKeyEvent,aType); return keyRes; // nothing to do here }
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| changing scrollbar appearance | ahti123 | Symbian User Interface | 0 | 2005-12-09 07:55 |
| Not able to create CAknIntegerEdwin/CAknNumericEdwin | gpalvia | Symbian User Interface | 2 | 2004-03-05 11:02 |
| Drawing a Edwin | rkuppala | Symbian User Interface | 3 | 2003-05-10 11:35 |
| calling listbox in the view | soumaya | Symbian User Interface | 8 | 2007-04-19 13:22 |
| How to create a screen with iimage and text? | nomadph | Symbian User Interface | 8 | 2007-10-04 13:52 |
