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
menu_items.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2019-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 _NANO_MENU_ITEMS_H_
29 #define _NANO_MENU_ITEMS_H_
30 
31 #include "menu.h"
32 #include "nano_gfx_types.h"
33 
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 
41 template <class T> class NanoTestMenuItem: public NanoMenuItem<T>
42 {
43 public:
44  NanoTestMenuItem()
45  : NanoMenuItem<T>({0, 0}, {48, 8})
46  {
47  }
48 
49  void draw() override
50  {
51  if ( this->isFocused() )
52  {
53  this->getTiler().getCanvas().setColor(0xFFFF);
54  this->getTiler().getCanvas().fillRect(this->m_rect);
55  }
56  else
57  {
58  this->getTiler().getCanvas().setColor(0);
59  this->getTiler().getCanvas().fillRect(this->m_rect);
60  this->getTiler().getCanvas().setColor(0xFFFF);
61  this->getTiler().getCanvas().drawRect(this->m_rect);
62  }
63  }
64 };
65 
66 #endif
67 
71 template <class T> class NanoTextMenuItem: public NanoMenuItem<T>
72 {
73 public:
79  explicit NanoTextMenuItem(const char *name)
80  : NanoMenuItem<T>({0, 0})
81  , m_name(name)
82  {
83  }
84 
89  void update() override
90  {
91  if ( this->m_rect.height() <= 1 )
92  {
93  if ( this->hasTiler() )
94  {
95  lcduint_t height;
96  lcduint_t width = this->getTiler().getDisplay().getFont().getTextSize(m_name, &height);
97  this->setSize({width, height});
98  }
99  else
100  {
101  // At this point we don't know font to be used by a user
102  this->setSize({this->width(), (lcduint_t)8});
103  }
104  }
105  }
106 
110  void draw() override
111  {
112  if ( this->isFocused() )
113  {
114  this->getTiler().getCanvas().setMode(CANVAS_MODE_TRANSPARENT);
115  this->getTiler().getCanvas().setColor(0xFFFF);
116  this->getTiler().getCanvas().fillRect(this->m_rect);
117  this->getTiler().getCanvas().setColor(0x0000);
118  this->getTiler().getCanvas().printFixed(this->m_rect.p1.x, this->m_rect.p1.y, m_name);
119  }
120  else
121  {
122  this->getTiler().getCanvas().setMode(CANVAS_MODE_BASIC);
123  this->getTiler().getCanvas().setColor(0xFFFF);
124  this->getTiler().getCanvas().printFixed(this->m_rect.p1.x, this->m_rect.p1.y, m_name);
125  }
126  }
127 
128 protected:
130  const char *m_name;
131 };
132 
137 #endif
uint8_t lcduint_t
internal int type, used by the library.
Definition: canvas_types.h:79
const char * m_name
Menu item text.
Definition: menu_items.h:130
This flag make bitmaps transparent (Black color)
Definition: canvas_types.h:101
NanoTextMenuItem(const char *name)
Creates instance of test menu item.
Definition: menu_items.h:79
void draw() override
Draws nano object Engine canvas.
Definition: object.h:77
Menu class.
Basic structures of nano gfx library.
T & getTiler()
Returns reference to NanoEngine.
Definition: tiler.h:148
void update() override
Updates menu item state.
Definition: menu_items.h:89
Template class for font menu item with user-defined font.
Definition: menu_items.h:71
void draw() override
Draws text menu item in the NanoEngine buffer.
Definition: menu_items.h:110
bool isFocused()
Returns true if logic focus points to the object.
Definition: tiler.h:131