Syntax:
void initButton( LovyanGFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h, const T& outline, const T& fill,
const T& textcolor, const char *label, float textsize_x = 1.0f, float textsize_y = 0.0f)
Description:
Parameters:
Return:
Example:
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void) {
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButton(&M5.Lcd, w / 2, h / 2, 100, 50, TFT_RED, TFT_YELLOW, TFT_BLACK, "Btn", 2, 2);
button.drawButton();
}
void loop(void) {
}
Syntax:
void initButtonUL( LovyanGFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h, const T& outline, const T& fill,
const T& textcolor, const char *label, float textsize_x = 1.0f, float textsize_y = 0.0f)
Description:
Parameters:
Return:
Example:
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void) {
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButtonUL(&M5.Lcd, w / 2, h / 2, 100, 50, TFT_RED, TFT_YELLOW, TFT_BLACK, "Btn", 2, 2);
button.drawButton();
}
void loop(void) {
}
Syntax:
void setLabelText(const char* label)
Description:
Parameters:
Return:
Example:
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void) {
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButton(&M5.Lcd, w / 2, h / 2, 100, 50, TFT_RED, TFT_YELLOW, TFT_BLACK, "null", 2, 2);
button.setLabelText("BTN");
button.drawButton();
}
void loop(void) {
}
Syntax:
void setLabelDatum(int16_t x_delta, int16_t y_delta, textdatum_t datum = middle_center)
Description:
Parameters:
Return:
Example:
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void) {
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButtonUL(&M5.Lcd, 0, 0, 100, 50, TFT_RED, TFT_YELLOW, TFT_BLACK, "Btn", 2, 2);
button.setLabelDatum(0,0,middle_left);
button.drawButton();
}
void loop(void) {
}
Syntax:
void setOutlineColor(const T& clr)
Description:
Parameters:
Return:
Syntax:
void setFillColor(const T& clr)
Description:
Parameters:
Return:
Syntax:
void setTextColor(const T& clr)
Description:
Parameters:
Return:
Syntax:
void drawButton(bool inverted = false, const char* long_name = nullptr)
Description:
Parameters:
Return:
Example:
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void) {
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButton(&M5.Lcd, w / 2, h / 2, 100, 50, TFT_RED, TFT_YELLOW, TFT_BLACK, "BTN", 2, 2);
button.setOutlineColor(TFT_WHITE);//set button outline color
button.setFillColor(TFT_BLUE);//set button color
button.setTextColor(TFT_DARKGRAY);//set button text color
button.drawButton();//draw button
}
void loop(void) {
}
Syntax:
bool contains(int16_t x, int16_t y)
Description:
Parameters:
Return:
Example:
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void) {
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButton(&M5.Lcd, w / 2, h / 2, 100, 50, TFT_RED, TFT_YELLOW, TFT_BLACK, "BTN", 2, 2);
button.drawButton();
M5.Display.setTextDatum(middle_center);
M5.Display.setTextFont(&fonts::FreeSans12pt7b);
M5.Display.setTextSize(1);
M5.Display.drawString("Coordinate Contained ? : \n", M5.Display.width() / 2, M5.Display.height() - 50);
const char *con_str = button.contains(w / 2, h / 2) ? "Yes" : "No";// coordinate: (w / 2, h / 2)
M5.Display.drawString(con_str, M5.Display.width() / 2, M5.Display.height() - 20);
}
void loop(void) {
}
Syntax:
void press(bool p)
Description:
Parameters:
Return:
Syntax:
bool isPressed(void)
Description:
Parameters:
Return:
Syntax:
bool justPressed(void)
Description:
Parameters:
Return:
Syntax:
bool justReleased(void)
Description:
Parameters:
Return:
Example:
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void) {
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButton(&M5.Lcd, w / 2, h / 2, 100, 50, TFT_RED, TFT_YELLOW,
TFT_BLACK, "null", 2, 2);
button.drawButton();
}
void loop(void) {
M5.update();
if (M5.BtnA.isPressed()) {
button.press(true);
button.drawButton(true, "BtnA");
M5.Lcd.drawString("Button A Pressed ", 0, 0, &fonts::lgfxJapanGothic_16);
}
else if (M5.BtnB.isPressed()) {
button.press(true);
button.drawButton(true, "BtnB");
M5.Lcd.drawString("Button B Pressed ", 0, 0, &fonts::lgfxJapanGothic_16);
}
else if (M5.BtnC.isPressed()) {
button.press(true);
button.drawButton(true, "BtnC");
M5.Lcd.drawString("Button C Pressed ", 0, 0, &fonts::lgfxJapanGothic_16);
}
else {
button.press(false);
button.drawButton(false, "Test");
M5.Lcd.drawString("Button Released", 0, 0, &fonts::lgfxJapanGothic_16);
}
delay(100);
}
The example program runs as follows: