MediaTek-Labs / Arduino-Add-On-for-LinkIt-SDK

Arduino board support package for LinkIt 7697
https://docs.labs.mediatek.com/resource/linkit7697-arduino/en
34 stars 33 forks source link

Support specifying parameter in constructor of UI components #109

Open SmallpTsai opened 5 years ago

SmallpTsai commented 5 years ago

Sample code

class Label : public LRemoteLabel {
public:
  Label(const String &text, uint8_t x, uint8_t y, uint8_t w, uint8_t h, RCColorType color = RC_GREY) : LRemoteLabel() {
    setText(text);
    setPos(x, y);
    setSize(w, h);
    setColor(color);
  }
};

Usage example

Label label1("Select leg", L_X(0), L_Y(0), L_W, L_H);

Much cleaner code

static Label label1("Select leg", L_X(0), L_Y(0), L_W, L_H);
static Label text1("", T_X(0), T_Y(0), T_W, T_H, RC_PINK);
static Button button1l(10, "<", Bl_X(0), Bl_Y(0), B_W, B_H, RC_BLUE);
static Button button1r(11, ">", Br_X(0), Br_Y(0), B_W, B_H, RC_BLUE);
...

setup() {
  ...
  LRemote_addControls({
    &label1, &text1, &button1l, &button1r,  // row1
    ...
  });
  ...
}

reference: https://github.com/SmallpTsai/hexapod-v2-7697/blob/master/software/hexapod7697/src/setting_mode.cpp