Adafruit GFX Library
Public Member Functions | List of all members
Adafruit_GFX_Button Class Reference

A simple drawn button UI element. More...

#include <Adafruit_GFX.h>

Public Member Functions

 Adafruit_GFX_Button (void)
 Create a simple drawn button UI element.
 
void initButton (Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t outline, uint16_t fill, uint16_t textcolor, char *label, uint8_t textsize)
 Initialize button with our desired color/size/settings. More...
 
void initButton (Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t outline, uint16_t fill, uint16_t textcolor, char *label, uint8_t textsize_x, uint8_t textsize_y)
 Initialize button with our desired color/size/settings. More...
 
void initButtonUL (Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h, uint16_t outline, uint16_t fill, uint16_t textcolor, char *label, uint8_t textsize)
 Initialize button with our desired color/size/settings, with upper-left coordinates. More...
 
void initButtonUL (Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h, uint16_t outline, uint16_t fill, uint16_t textcolor, char *label, uint8_t textsize_x, uint8_t textsize_y)
 Initialize button with our desired color/size/settings, with upper-left coordinates. More...
 
void drawButton (bool inverted=false)
 Draw the button on the screen. More...
 
bool contains (int16_t x, int16_t y)
 Helper to let us know if a coordinate is within the bounds of the button. More...
 
void press (bool p)
 Sets button state, should be done by some touch function. More...
 
bool justPressed ()
 Query whether the button was pressed since we last checked state. More...
 
bool justReleased ()
 Query whether the button was released since we last checked state. More...
 
bool isPressed (void)
 Query whether the button is currently pressed. More...
 

Detailed Description

A simple drawn button UI element.

Member Function Documentation

◆ initButton() [1/2]

void Adafruit_GFX_Button::initButton ( Adafruit_GFX gfx,
int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  outline,
uint16_t  fill,
uint16_t  textcolor,
char *  label,
uint8_t  textsize 
)

Initialize button with our desired color/size/settings.

Parameters
gfxPointer to our display so we can draw to it!
xThe X coordinate of the center of the button
yThe Y coordinate of the center of the button
wWidth of the buttton
hHeight of the buttton
outlineColor of the outline (16-bit 5-6-5 standard)
fillColor of the button fill (16-bit 5-6-5 standard)
textcolorColor of the button label (16-bit 5-6-5 standard)
labelAscii string of the text inside the button
textsizeThe font magnification of the label text

◆ initButton() [2/2]

void Adafruit_GFX_Button::initButton ( Adafruit_GFX gfx,
int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  outline,
uint16_t  fill,
uint16_t  textcolor,
char *  label,
uint8_t  textsize_x,
uint8_t  textsize_y 
)

Initialize button with our desired color/size/settings.

Parameters
gfxPointer to our display so we can draw to it!
xThe X coordinate of the center of the button
yThe Y coordinate of the center of the button
wWidth of the buttton
hHeight of the buttton
outlineColor of the outline (16-bit 5-6-5 standard)
fillColor of the button fill (16-bit 5-6-5 standard)
textcolorColor of the button label (16-bit 5-6-5 standard)
labelAscii string of the text inside the button
textsize_xThe font magnification in X-axis of the label text
textsize_yThe font magnification in Y-axis of the label text

◆ initButtonUL() [1/2]

void Adafruit_GFX_Button::initButtonUL ( Adafruit_GFX gfx,
int16_t  x1,
int16_t  y1,
uint16_t  w,
uint16_t  h,
uint16_t  outline,
uint16_t  fill,
uint16_t  textcolor,
char *  label,
uint8_t  textsize 
)

Initialize button with our desired color/size/settings, with upper-left coordinates.

Parameters
gfxPointer to our display so we can draw to it!
x1The X coordinate of the Upper-Left corner of the button
y1The Y coordinate of the Upper-Left corner of the button
wWidth of the buttton
hHeight of the buttton
outlineColor of the outline (16-bit 5-6-5 standard)
fillColor of the button fill (16-bit 5-6-5 standard)
textcolorColor of the button label (16-bit 5-6-5 standard)
labelAscii string of the text inside the button
textsizeThe font magnification of the label text

◆ initButtonUL() [2/2]

void Adafruit_GFX_Button::initButtonUL ( Adafruit_GFX gfx,
int16_t  x1,
int16_t  y1,
uint16_t  w,
uint16_t  h,
uint16_t  outline,
uint16_t  fill,
uint16_t  textcolor,
char *  label,
uint8_t  textsize_x,
uint8_t  textsize_y 
)

Initialize button with our desired color/size/settings, with upper-left coordinates.

Parameters
gfxPointer to our display so we can draw to it!
x1The X coordinate of the Upper-Left corner of the button
y1The Y coordinate of the Upper-Left corner of the button
wWidth of the buttton
hHeight of the buttton
outlineColor of the outline (16-bit 5-6-5 standard)
fillColor of the button fill (16-bit 5-6-5 standard)
textcolorColor of the button label (16-bit 5-6-5 standard)
labelAscii string of the text inside the button
textsize_xThe font magnification in X-axis of the label text
textsize_yThe font magnification in Y-axis of the label text

◆ drawButton()

void Adafruit_GFX_Button::drawButton ( bool  inverted = false)

Draw the button on the screen.

Parameters
invertedWhether to draw with fill/text swapped to indicate 'pressed'

◆ contains()

bool Adafruit_GFX_Button::contains ( int16_t  x,
int16_t  y 
)

Helper to let us know if a coordinate is within the bounds of the button.

Parameters
xThe X coordinate to check
yThe Y coordinate to check
Returns
True if within button graphics outline

◆ press()

void Adafruit_GFX_Button::press ( bool  p)
inline

Sets button state, should be done by some touch function.

Parameters
pTrue for pressed, false for not.

◆ justPressed()

bool Adafruit_GFX_Button::justPressed ( )

Query whether the button was pressed since we last checked state.

Returns
True if was not-pressed before, now is.

◆ justReleased()

bool Adafruit_GFX_Button::justReleased ( )

Query whether the button was released since we last checked state.

Returns
True if was pressed before, now is not.

◆ isPressed()

bool Adafruit_GFX_Button::isPressed ( void  )
inline

Query whether the button is currently pressed.

Returns
True if pressed

The documentation for this class was generated from the following files: