LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
yesno.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2020, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
28 #ifndef _LCDGFX_YESNO_H_
29 #define _LCDGFX_YESNO_H_
30 
31 #include "nano_gfx_types.h"
32 #include "button.h"
33 #include "canvas/point.h"
34 #include "canvas/rect.h"
35 #include "canvas/font.h"
36 
46 {
47 public:
54  explicit LcdGfxYesNo(const char *text, const NanoRect &rect = {});
55 
61  template <typename D> void show(D &d)
62  {
63  updateSize(d);
64  d.invertColors();
65  d.fillRect(m_rect);
66  d.invertColors();
67  d.drawRect(m_rect);
68  d.printFixed(m_rect.p1.x + 4, m_rect.p1.y + 8, m_text);
69  m_yes.show(d);
70  m_no.show(d);
71  }
72 
77  void swapToYes();
78 
83  void swapToNo();
84 
88  bool isYes();
89 
93  template <typename D> void updateSize(D &d)
94  {
95  if ( !m_rect.p2.x )
96  {
97  m_rect.p2.x = d.width() - m_rect.p1.x - 1;
98  m_rect.p2.y = d.height() - m_rect.p1.y - 1;
99  locateButtons(d);
100  }
101  }
102 
103 private:
104  const char *m_text;
105  NanoRect m_rect;
106  LcdGfxButton m_yes;
107  LcdGfxButton m_no;
108 
109  template <typename D> void locateButtons(D &d)
110  {
111  m_yes.updateSize(d);
112  m_no.updateSize(d);
113  NanoPoint size = m_yes.getSize();
114  m_yes.setRect({{m_rect.center().x - size.x - 4, m_rect.p2.y - size.y - 8}, {0, 0}});
115  m_no.setRect({{m_rect.center().x + 4, m_rect.p2.y - size.y - 8}, {0, 0}});
116  }
117 };
118 
123 #endif
Class implements YesNo dialog for lcdgfx library.
Definition: yesno.h:45
Describes point.
Definition: point.h:39
NanoRect structure describes rectangle area.
Definition: rect.h:42
Point class.
NanoPoint p2
right-bottom point of the rectangle area
Definition: rect.h:48
void updateSize(D &d)
Calculates size for GUI component if it was not set before.
Definition: yesno.h:93
Button object definition.
void swapToYes()
Changes selection to Yes.
const NanoPoint center() const
returns center point of NanoRect
Definition: rect.h:63
lcdint_t y
y position in pixels
Definition: point.h:44
Rectangle class.
bool isYes()
Returns true if yes button is active.
Basic structures of nano gfx library.
LcdGfxYesNo(const char *text, const NanoRect &rect={})
Creates yes/no dialog with the provided text.
void swapToNo()
Changes selection to No Redraw element using show() method.
NanoPoint p1
top-left point of the rectangle area
Definition: rect.h:45
void show(D &d)
Shows button on the display.
Definition: button.h:60
lcdint_t x
x position in pixels
Definition: point.h:42
void setRect(const NanoRect &rect)
Sets new area for the button.
void show(D &d)
Shows button on the display.
Definition: yesno.h:61
Class implements button object for lcdgfx library.
Definition: button.h:44
Font class.
void updateSize(D &d)
Auto updates buttons size if it is not set.
Definition: button.h:119
const NanoPoint getSize()
Returns size of button in pixels.