开发者

Mosync: Why wont this display my Layout

I am delving into Layouts & trying to understand how they work. Is a Layout anything like a JPanel in Java Swing? Ie, where we declare a main panel & add all out widgets to that?

One thing I do not understand is when we create a mobile app, we create a Layout & a Listbox. What is the relationship between those 2 objects?

  • Does the Layout object contain the Listbox, then we add all the widgets to the listbox?
  • Or does the Listbox have a Layout defined, the开发者_运维知识库n we add the widgets to the Listbox & they aligned according to the Layout
  • Or do we add all widgets to the layout like in Java Swing?

PS: With my experimentation below, my widgets are not shown? Its just a blank black screen. Why does this happen?

#include <MAUtil/Moblet.h>
#include <MAUI/Layout.h>
#include <MAUI/ListBox.h>
#include <MAUI/Label.h>
#include <MAUI/EditBox.h>
#include <MAUI/Screen.h>
#include <MAUtil/Environment.h>
#include <madmath.h>
#include <conprint.h>


using namespace MAUtil;
using namespace MAUI;

class TemperatureScreen : public Screen  //, public PointerListener
{
    public:
        TemperatureScreen()
        {
            MAExtent screenDim = maGetScrSize();
            Layout* mainLayout  = new Layout( 0, 0, EXTENT_X(screenDim), EXTENT_Y(screenDim), NULL, 1, 3 );
            ListBox* mainListBox = new ListBox( 0, 0, 100, 200, mainLayout,
                                       ListBox::LBO_VERTICAL, ListBox::LBA_LINEAR,
                                       true );
            mainListBox -> setPaddingLeft( 10 );
            mainListBox -> setPaddingRight( 10 );
            mainListBox -> setPaddingTop( 10 );
            mainListBox -> setPaddingBottom( 10 );
            mainListBox -> setBackgroundColor( 900 );
            mainLayout  -> setBackgroundColor( 300 );

            Label *celLabel     = new Label( 10, 300, 50, 20, mainLayout );
            Label *fahLabel     = new Label( 10, 300, 50, 20, mainLayout );
            EditBox *celEdit    = new EditBox( 10, 300, 50, 20, mainLayout );
            EditBox *fahEdit    = new EditBox( 10, 300, 50, 20, mainLayout );
            Label *toCelsiusRb  = new Label( 10, 300, 50, 20, mainLayout );
            Label *toFahRb      = new Label( 10, 300, 50, 20, mainLayout );
            Label *convertLabel = new Label( 10, 300, 50, 20, mainLayout );
            Label *exitLabel    = new Label( 10, 300, 50, 20, mainLayout );

            celLabel     -> setCaption( "Celcius" );
            fahLabel     -> setCaption( "Fahrenheit" );
            convertLabel -> setCaption( "Convert" );
            exitLabel    -> setCaption( "Exit" );
            /*celLabel   -> addPointerListener( this );
            fahLabel     -> addPointerListener( this );
            convertLabel -> addPointerListener( this );
            exitLabel    -> addPointerListener( this );*/

            mainLayout -> add( celLabel );
            mainLayout -> add( fahLabel );
            mainLayout -> add( convertLabel );
            mainLayout -> add( exitLabel );
        }

};

class TemperatureMoblet : public Moblet
{
    public:
        TemperatureMoblet()
        {
            instance = new TemperatureScreen();
            instance -> show();
        }

        ~TemperatureMoblet()
        {
            delete instance;
        }

        void keyPressEvent(int keyCode, int nativeCode)
        {
            // todo: handle key presses
            printf( "Blah" );
        }

        void keyReleaseEvent(int keyCode, int nativeCode)
        {
            // todo: handle key releases
        }

    private:
        TemperatureScreen *instance;
};

extern "C" int MAMain()
{
    Moblet::run(new TemperatureMoblet());
    return 0;
};


Try putting an maUpdateScreen() in a timer event or in the key listener, just to see what happens.

If you need more help just get back to me.

You could try the new version 2.6 of mosync at:

http://www.mosync.com/documentation/manualpages/whats-new-mosync-26-pyramid

/Tony

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜