LCDGFX LCD display driver  1.1.5
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
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
Definition: rect.h:42
NanoPoint p2
Definition: rect.h:48
void updateSize(D &d)
Definition: yesno.h:93
void swapToYes()
const NanoPoint center() const
Definition: rect.h:63
lcdint_t y
Definition: point.h:44
bool isYes()
LcdGfxYesNo(const char *text, const NanoRect &rect={})
void swapToNo()
NanoPoint p1
Definition: rect.h:45
void show(D &d)
Definition: button.h:60
lcdint_t x
Definition: point.h:42
void setRect(const NanoRect &rect)
void show(D &d)
Definition: yesno.h:61
void updateSize(D &d)
Definition: button.h:119
const NanoPoint getSize()