开发者

Mosync: My own ComboBox wont show its contents

I am using the Mobile Devlopment API called Mosync to develop a Combobox(subclassed from Label) in Mosync, but it seems that when I run my app, the combobox label is shown but its contents (a listbox & button) are not shown.

What do you tink is happening?

class ComboBox : Label
{
    private:
        Vector <String>  options;
        ComboBoxButton *button;
        MAUI::ListBox    *optionsBox;

    public:
    ComboBox( Vector <String> nOptions, MAUI::Widget *nParent )
             : Label( 0, 0, 0 0, nParent ),
               options(nOptions)
    {
        // Constructor:

        button     = new ComboBoxButton( "", this );
        optionsBox = new MAUI::ListBox( 0, 0, 0, 0, NULL, MAUI::ListBox::LBO_VERTICAL, MAUI::ListBox::LBA_LINEAR, false );
        optionsBox -> setAutoSize( true );

        // Add blank element to CB
        optionsBox -> add( new MAUI::Label( 0, 0, 0, 0, optionsBox, "", 0, QuickApp::defFont ) );

        // Add elements to CB
        for ( int i=0; i<nOptions.size(); i++ )
        {
            optionsBox -> add( new MAUI::Label( 0, 0, 0, 0, optionsBox, nOptions[i], 0, QuickApp::defFont ) );
        }

        optionsBox -> setHeight( optionsBox->getChildren()[0]->getHeight() );
        this -> add( optionsBox );
        this -> add( button );
    }

    ComboBox()
    {
        // Destructor:


    }

    void onButtonClick( bool clicked )
    {
        // Post: Close/Open drop down options/combo box

        if ( clicked )
        {
            // Show all rows in the listbox
            int height = 0;
            for ( Vector <Widget*> rows = optionsBox->getChildren(); !rows.empty(); rows.remove(0) )
            {
                height += rows[0]->getHeight();
            }
            optionsBox -> setHeight( height );
        }
       开发者_JS百科 else
        {
            // Only show the 1st row of the listbox

            // Note: Ideally I would like to get the selected cell & make its position
            // at the top of the LB
            // But I cant find a ListBox function that allows me to either remove a
            // specific row or to add a Widget at the beginning of the Listbox (not at the end)
            optionsBox -> setHeight( optionsBox->getChildren()[0]->getHeight() );
        }
    }
};



class ComboBoxButton : Button
{
    private:
        ComboBox *parent;
        bool clickStatus;

    public: // QAButton inherits from Label & PointerListener (simple interface with virtual PointerPressEvent(), etc. functions)
    ComboBoxButton( String nCaption, ComboBox *nParent )
             : Button( "", (MAUI::Widget*)nParent ),
               parent(nParent), clickStatus(false)
    {
        // Constructor:

    }

    void pointerPressEvent( MAPoint2d point )
    {
        // Post:
        Point p;
        p.set( point.x, point.y );

        if ( this->contains(p) )
        {
            clickStatus = !clickStatus;
            parent -> onButtonClick( clickStatus );
        }
    }

    void pointerMoveEvent( MAPoint2d point )
    {
        // Post:

    }

    void pointerReleaseEvent( MAPoint2d point )
    {
        // Post:

    }
};


class Button : public Label, public PointerListener
{
    public:
    Button( String nCaption, MAUI::Widget *nParent )
             : MAUI::Label( 0, 0, 0, 0, nParent, nCaption, 0, QuickApp::defFont )
    {
        this -> setAutoSizeX();
        this -> setAutoSizeY();
        this -> setHorizontalAlignment( MAUI::Label::HA_CENTER );
        this -> setVerticalAlignment(  MAUI::Label::VA_CENTER );

        Environment &env = Environment::getEnvironment();
        env.addPointerListener( this );
    }

    protected:
};


Are you doing a ->show() somewhere, I didn't see it in you code.

Hope this helps.

/Tony

PS. There's a new version MoSync 2.6 at: http://www.mosync.com/documentation/manualpages/whats-new-mosync-26-pyramid

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜