Getting started with ardUI

A note about code examplesAll code examples on this site are written in .cpp format instead of .ino used in Arduino for better compatibility. Code in the .cpp format will run in Arduino IDE as well.

Starting out with ardUI is extremely easy! Consider this example:

#include <Arduino.h>
#include "ardUI.h"
void setup() {
}
void loop() {
}

This might not look like much, but this is actually a functional ardUI program! This is because ardUI starts working the moment you include it so you don't have to worry about calling it yourself.

Okay, let's actually draw something now:

#include <Arduino.h>
#include "ardUI.h"
#include "TextView.h"
#include "Activity.h"
class MainActivity: public Activity {
using Activity::Activity;
void onCreate() override {
auto t = new TextView("Hello world!");
setRootView(t);
}
};
void setup() {
ardUI::startActivity<MainActivity>();
}
void loop() {
}

As you can see, this example is a bit more involved. Let's see what it does line by line. On line 3 we are including a TextView, a widgets for displaying text that we'll be using later. On the next line we include an Activity, or "a screen" that we will place all our widgets on. ardUI allows you to create multiple screens and switch between them at any time.

We actually define our Activity on line 6. For this, we define a new class that extends a base Activity class (why?) which ardUI will then start for us. When creating an Activity, don't forget to add a using directive (see line 7) or otherwise ardUI won't be able to start your Activity. Your Activity is required to have a single method: onCreate(). This method will be called when ardUI will be starting your Activity. This is also a good place to create and add your widgets to the Activity.

In our onCreate method we will start adding our widgets to the Activity we've just created. On line 10 we are creating a new TextView, a simple widget for just displaying text. On the next line we are adding this newly created widget to our Activity so that ardUI can draw it when we start an Activity.

In the setup() function we then need to tell ardUI to start our Activity by calling ardUI::startActivity<>() method. ardUI will then start the Activity and draw all the widgets on its own!

On this page