forked from DanNixon/NeoNextion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INextionColourable.cpp
146 lines (133 loc) · 3.71 KB
/
INextionColourable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*! \file */
#include "INextionColourable.h"
/*!
* \copydoc INextionWidget::INextionWidget
*/
INextionColourable::INextionColourable(Nextion &nex, uint8_t page,
uint8_t component, const char *name)
: INextionWidget(nex, page, component, name)
{
}
/*!
* \brief Sets the normal foreground colour.
* \param colour Colour
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionColourable::getForegroundColour
*/
bool INextionColourable::setForegroundColour(uint32_t colour, bool refresh)
{
return setColour("pco", colour, refresh);
}
/*!
* \brief Gets the normal foreground colour.
* \return Colour (may also return 0 in case of error)
* \see INextionColourable::setForegroundColour
*/
uint32_t INextionColourable::getForegroundColour()
{
return getColour("pco");
}
/*!
* \brief Sets the foreground colour when a touch event is active.
* \param colour Colour
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionColourable::getEventForegroundColour
*/
bool INextionColourable::setEventForegroundColour(uint32_t colour, bool refresh)
{
return setColour("pco2", colour, refresh);
}
/*!
* \brief Gets the foreground colour when a touch event is active.
* \return Colour (may also return 0 in case of error)
* \see INextionColourable::setEventForegroundColour
*/
uint32_t INextionColourable::getEventForegroundColour()
{
return getColour("pco2");
}
/*!
* \brief Sets the normal background colour.
* \param colour Colour
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionColourable::getBackgroundColour
*/
bool INextionColourable::setBackgroundColour(uint32_t colour, bool refresh)
{
return setColour("bco", colour, refresh);
}
/*!
* \brief Gets the normal background colour.
* \return Colour (may also return 0 in case of error)
* \see INextionColourable::setBackgroundColour
*/
uint32_t INextionColourable::getBackgroundColour()
{
return getColour("bco");
}
/*!
* \brief Sets the background colour when a touch event is active.
* \param colour Colour
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionColourable::getEventBackgroundColour
*/
bool INextionColourable::setEventBackgroundColour(uint32_t colour, bool refresh)
{
return setColour("bco2", colour, refresh);
}
/*!
* \brief Sets the background colour when a touch event is active.
* \return Colour (may also return 0 in case of error)
* \see INextionColourable::setEventBackgroundColour
*/
uint32_t INextionColourable::getEventBackgroundColour()
{
return getColour("bco2");
}
/*!
* \brief Sets a colour by its property name.
* \param type Property name
* \param colour Colour
* \param refresh If the widget should be refreshed
* \return True if successful
*/
bool INextionColourable::setColour(char *type, uint32_t colour, bool refresh)
{
return afterSet(setNumberProperty(type, colour), refresh);
}
/*!
* \brief Gets a colour by its property name.
* \param type Property name
* \return Colour (may also return 0 in case of error)
* \see INextionColourable::setColour
*/
uint32_t INextionColourable::getColour(char *type)
{
return getNumberProperty(type);
}
/*!
* \brief Handles refreshing the page after a colour has been changed.
* \param result Success of colour set
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionColourable::getColour
*/
bool INextionColourable::afterSet(bool result, bool refresh)
{
if (result)
{
if (refresh)
{
m_nextion.refresh(m_name);
return m_nextion.checkCommandComplete();
}
else
return true;
}
else
return false;
}