LCDGFX LCD display driver  1.0.5
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
menu_items.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2019, 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>
42 class NanoTestMenuItem: public NanoMenuItem<T>
43 {
44 public:
45  NanoTestMenuItem()
46  : NanoMenuItem<T>( {0, 0}, {48, 8} )
47  {
48  }
49 
50  void draw() override
51  {
52  if ( this->isFocused() )
53  {
54  this->getTiler().getCanvas().setColor( 0xFFFF );
55  this->getTiler().getCanvas().fillRect( this->m_rect );
56  }
57  else
58  {
59  this->getTiler().getCanvas().setColor( 0 );
60  this->getTiler().getCanvas().fillRect( this->m_rect );
61  this->getTiler().getCanvas().setColor( 0xFFFF );
62  this->getTiler().getCanvas().drawRect( this->m_rect );
63  }
64  }
65 };
66 
67 #endif
68 
72 template<class T>
74 {
75 public:
81  NanoTextMenuItem(const char *name)
82  : NanoMenuItem<T>( {0, 0} )
83  , m_name( name )
84  {
85  }
86 
91  void update() override
92  {
93  if ( this->m_rect.height() <= 1 )
94  {
95  if ( this->hasTiler() )
96  {
97  lcduint_t height;
98  lcduint_t width = this->getTiler().getDisplay().getFont().getTextSize(m_name, &height);
99  this->setSize( {width, height} );
100  }
101  else
102  {
103  // At this point we don't know font to be used by a user
104  this->setSize( { this->width(), (lcduint_t)8 } );
105  }
106  }
107  }
108 
112  void draw() override
113  {
114  if ( this->isFocused() )
115  {
116  this->getTiler().getCanvas().setMode( CANVAS_MODE_TRANSPARENT );
117  this->getTiler().getCanvas().setColor( 0xFFFF );
118  this->getTiler().getCanvas().fillRect( this->m_rect );
119  this->getTiler().getCanvas().setColor( 0x0000 );
120  this->getTiler().getCanvas().printFixed( this->m_rect.p1.x, this->m_rect.p1.y, m_name );
121  }
122  else
123  {
124  this->getTiler().getCanvas().setMode( CANVAS_MODE_BASIC );
125  this->getTiler().getCanvas().setColor( 0xFFFF );
126  this->getTiler().getCanvas().printFixed( this->m_rect.p1.x, this->m_rect.p1.y, m_name );
127  }
128  }
129 
130 protected:
132  const char *m_name;
133 
134 };
135 
136 
141 #endif
142 
uint8_t lcduint_t
Definition: canvas_types.h:81
const char * m_name
Definition: menu_items.h:132
NanoTextMenuItem(const char *name)
Definition: menu_items.h:81
void draw() override
Definition: object.h:79
T & getTiler()
Definition: tiler.h:147
void update() override
Definition: menu_items.h:91
void draw() override
Definition: menu_items.h:112
bool isFocused()
Definition: tiler.h:133