GUI-Based Applications with MAUI

Using the MAUI library helps you develop powerful graphical user interface applications. You get access to a variety of ready-made user interface widgets and you can register different types of listeners with the widgets, thus responding to higher-level events.

MAUI development is based on the Moblet system, so to create an application with it you first need to make a moblet as shown in the previous example.

The fundamental building block of a MAUI application is called MAUI::Screen. Each screen has their own root widget. Each time show() is called on a screen, that screen is shown and all the others are hidden. When a screen is shown, it means that the root widget of that screen is made active. It can often be very useful to group your application into several screens in order to give your program a logical structure. When a screen is shown, key events are sent to that screen only. When a screen is hidden, each widget that belongs to it is disabled. This normally means that any timer events are unregistered.

Example: A Simple, Well-Behaved Application

Note: if you build this application in the IDE, make sure that you base it on the MAUI template or make sure that the Additional Libraries listed in the build configuration (Project > Properties > MoSync Project > Build Settings > Additional Libraries) include MAUtil.lib and MAUI.lib. You will also need to create and declare your font resources: see Working With Fonts.

#include <MAUtil/Moblet.h>
#include <MAUI/Screen.h>
#include <MAUI/Label.h>
#include "MAHeaders.h"
using namespace MAUtil;
using namespace MAUI;
class MyScreen : public Screen {
public:
	MyScreen() {
		label = new Label(
		0, // set the top-left corner
		0, // to be in the top-left corner of the lcd display.
		0, // the width and height are set to the width and height of the lcd display
		0, // automatically for the root widget in a screen.
		NULL, // this widget has no parent widget
		"Hello World!", // the caption of the label
		0, // use background color 0 (black)
		new Font(MY_FONT) // create a new instance of the font stored as the
		// resource MY_FONT and set the font of the label to that font.
		);
		setMain(label); // set the root widget to be the label we just created
	}
	void keyPressEvent(int key) {
		if(key == MAK_0) {
			maExit(0); // exit the application when key 0 has been pressed
		}
	}

private:
	Label *label;
};
class MyMoblet : public Moblet {
public:
	MyMoblet() {
		myScreen = new MyScreen();
		myScreen->show();
	}
private:
	MyScreen *myScreen;
};
// Since this is a C++ program, the main function
// needs to be declared extern "C"
extern "C" int MAMain() {
	Moblet::run(new MyMoblet());
}



Share on Facebook