forked from DanNixon/NeoNextion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INextionFontStyleable.cpp
119 lines (110 loc) · 3.08 KB
/
INextionFontStyleable.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
/*! \file */
#include "INextionFontStyleable.h"
/*!
* \copydoc INextionWidget::INextionWidget
*/
INextionFontStyleable::INextionFontStyleable(Nextion &nex, uint8_t page,
uint8_t component,
const char *name)
: INextionWidget(nex, page, component, name)
{
}
/*!
* \brief Sets the active font for the text.
* \param id Font ID
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionFontStyleable::getFont
*/
bool INextionFontStyleable::setFont(uint8_t id, bool refresh)
{
return afterSet(setNumberProperty("font", id), refresh);
}
/*!
* \brief Gets the active font for the text.
* \return Font ID (may return 0 in event of error)
* \see INextionFontStyleable::setFont
*/
uint8_t INextionFontStyleable::getFont()
{
return getNumberProperty("font");
}
/*!
* \brief Sets the horizontal alignment of the text.
* \param align Alignment
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionFontStyleable::getHAlignment
*/
bool INextionFontStyleable::setHAlignment(NextionFontAlignment align,
bool refresh)
{
return afterSet(setNumberProperty("xcen", align), refresh);
}
/*!
* \brief Gets the horizontal alignment of the text.
* \return Alignment
* \see INextionFontStyleable::setHAlignment
*/
NextionFontAlignment INextionFontStyleable::getHAlignment()
{
size_t commandLen = 10 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "get %s.xcen", m_name);
sendCommand(commandBuffer, false);
uint32_t align;
if (m_nextion.receiveNumber(&align))
return (NextionFontAlignment)align;
else
return NEX_FA_NONE;
}
/*!
* \brief Sets the vertical alignment of the text.
* \param align Alignment
* \param refresh If the widget should be refreshed
* \return True if successful
* \see INextionFontStyleable::getVAlignment
*/
bool INextionFontStyleable::setVAlignment(NextionFontAlignment align,
bool refresh)
{
return afterSet(setNumberProperty("ycen", align), refresh);
}
/*!
* \brief Gets the vertical alignment of the text.
* \return Alignment
* \see INextionFontStyleable::setVAlignment
*/
NextionFontAlignment INextionFontStyleable::getVAlignment()
{
size_t commandLen = 10 + strlen(m_name);
char commandBuffer[commandLen];
snprintf(commandBuffer, commandLen, "get %s.ycen", m_name);
sendCommand(commandBuffer, false);
uint32_t align;
if (m_nextion.receiveNumber(&align))
return (NextionFontAlignment)align;
else
return NEX_FA_NONE;
}
/*!
* \brief Handles refreshing the page after a style has been changed.
* \param result Success of style change
* \param refresh If the widget should be refreshed
* \return True if successful
*/
bool INextionFontStyleable::afterSet(bool result, bool refresh)
{
if (result)
{
if (refresh)
{
m_nextion.refresh(m_name);
return m_nextion.checkCommandComplete();
}
else
return true;
}
else
return false;
}