×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Wink Solution for right to left issues

    Hi All :)

    Here is a solution that might work in many RTL (right to left) situations:

    My problem was that I wanted a right to left label (displaying hebrew/arabic) But First character had to be in English.
    What happened is that the label (same thing happen in All Eik controls) changed the alignment of the text to left to right, just because of that first character (which HAD to be English).

    Solution is (and I am very proud of myself for this finding ;): insert unicode right-to-left direction character before text. _L("\u202B")
    of course this is an invisible character.

    Example for a derived label class:

    Code:
    class CIchsLabel : public CEikLabel
    {
    public:
        void        SetLabelAlignment( TInt alignment );
        void        SetTextL( const TDesC& sourceText );
    
    private:
        bool        iIsRightAligned;
    };
    
    void CIchsLabel::SetLabelAlignment( TInt alignment )
    {
        iIsRightAligned = alignment == ELayoutAlignRight;
        CEikLabel::SetLabelAlignment( alignment );
    }
    
    void CIchsLabel::SetTextL( const TDesC& sourceText )
    {
        TBuf<234> text;
    /*
        if( iIsRightAligned )
        {
            AknBidiTextUtils::ConvertToVisualAndClip( sourceText, text, *Font(), Rect().Width(),
                                                      Rect().Width(), AknBidiTextUtils::ELeftToRight );
        }
        else
            text.Copy( sourceText );
    */
    
        text.Copy( sourceText );
        if( iIsRightAligned )
            text.Insert( 0, _L("\u202B") );
        CEikLabel::SetTextL( text );
    }
    Enjoy!

  2. #2
    Regular Contributor
    Join Date
    May 2010
    Posts
    362

    Re: Solution for right to left issues

    Hey,

    seems like this is something you could post into the wiki?
    There it might be more easily found by others looking for the same solution?

    Also to make the solution work on virtually any length labels, you could use something like this:

    _LIT(KRightToLeft, "\u202B");
    HBufC* buf = HBufC::NewLC(sourceText.Length()+5);
    TPtr ptr(buf->Des());
    ptr.Append(KRightToLeft);
    ptr.Append(sourceText.Length());
    CEikLabel::SetTextL(*buf);
    CleanupStack::PopAndDestroy(); //buf

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: Solution for right to left issues

    Agreed, I also wanted to suggest Rubi.mazaki to create some Wiki article for this nice finding. +1 should be enough, it is a single character (or "+KRightToLeft().Length()" - the "scientific" variant).

Similar Threads

  1. Networking issues with AVL solution
    By rjcauc81hi in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2007-09-01, 03:57
  2. Replies: 3
    Last Post: 2007-03-06, 14:14
  3. Replies: 1
    Last Post: 2007-01-30, 13:05
  4. Solution to Nokia SDK / Sun ONE Studio issues
    By bubbasbits in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2003-07-15, 03:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×