diff --git a/examples/Elements/Elements.ino b/examples/Elements/Elements.ino
index dd874a6..55188b4 100644
--- a/examples/Elements/Elements.ino
+++ b/examples/Elements/Elements.ino
@@ -42,6 +42,7 @@ static const char PAGE_ELEMENTS[] PROGMEM = R"(
"type": "ACCheckbox",
"value": "check",
"label": "Check",
+ "labelposition": "infront",
"checked": true
},
{
diff --git a/src/AutoConnectElementBasis.h b/src/AutoConnectElementBasis.h
index 49d51bf..21d91c9 100644
--- a/src/AutoConnectElementBasis.h
+++ b/src/AutoConnectElementBasis.h
@@ -58,6 +58,11 @@ typedef enum {
AC_Tag_P = 2
} ACPosterior_t; /**< Tag to be generated following element */
+typedef enum {
+ AC_Infront,
+ AC_Behind
+} ACPosition_t; /**< Position of label subordinate to element */
+
/**
* AutoConnectAux element base.
* Placed a raw text that can be added by user sketch.
@@ -115,7 +120,7 @@ class AutoConnectButtonBasis : AC_AUTOCONNECTELEMENT_ON_VIRTUAL public AutoConne
*/
class AutoConnectCheckboxBasis : AC_AUTOCONNECTELEMENT_ON_VIRTUAL public AutoConnectElementBasis {
public:
- explicit AutoConnectCheckboxBasis(const char* name = "", const char* value = "", const char* label = "", const bool checked = false, const ACPosterior_t post = AC_Tag_BR) : AutoConnectElementBasis(name, value, post), label(String(label)), checked(checked) {
+ explicit AutoConnectCheckboxBasis(const char* name = "", const char* value = "", const char* label = "", const bool checked = false, const ACPosition_t labelPosition = AC_Behind, const ACPosterior_t post = AC_Tag_BR) : AutoConnectElementBasis(name, value, post), label(String(label)), checked(checked), labelPosition(labelPosition) {
_type = AC_Checkbox;
}
virtual ~AutoConnectCheckboxBasis() {}
@@ -123,6 +128,7 @@ class AutoConnectCheckboxBasis : AC_AUTOCONNECTELEMENT_ON_VIRTUAL public AutoCon
String label; /**< A label for a subsequent input box */
bool checked; /**< The element should be pre-selected */
+ ACPosition_t labelPosition; /**< Output label according to ACPosition_t */
};
/**
diff --git a/src/AutoConnectElementBasisImpl.h b/src/AutoConnectElementBasisImpl.h
index 484fb46..1c6f1c0 100644
--- a/src/AutoConnectElementBasisImpl.h
+++ b/src/AutoConnectElementBasisImpl.h
@@ -66,8 +66,14 @@ const String AutoConnectCheckboxBasis::toHTML(void) const {
if (checked)
html += String(F(" checked"));
if (label.length())
- html += String(F(" id=\"")) + name + String(F("\">");
+ html += String(F(" id=\"")) + name + String("\">");
+ if (label.length()) {
+ String labelTag = String(F(""));
+ if (labelPosition == AC_Infront)
+ html = labelTag + html;
+ else if (labelPosition == AC_Behind)
+ html += labelTag;
+ }
html = AutoConnectElementBasis::posterior(html);
}
return html;
diff --git a/src/AutoConnectElementJson.h b/src/AutoConnectElementJson.h
index 22fc0c2..91de8b9 100644
--- a/src/AutoConnectElementJson.h
+++ b/src/AutoConnectElementJson.h
@@ -19,6 +19,7 @@
#define AUTOCONNECT_JSON_KEY_ELEMENT "element"
#define AUTOCONNECT_JSON_KEY_FORMAT "format"
#define AUTOCONNECT_JSON_KEY_LABEL "label"
+#define AUTOCONNECT_JSON_KEY_LABELPOSITION "labelposition"
#define AUTOCONNECT_JSON_KEY_MENU "menu"
#define AUTOCONNECT_JSON_KEY_NAME "name"
#define AUTOCONNECT_JSON_KEY_OPTION "option"
@@ -42,10 +43,12 @@
#define AUTOCONNECT_JSON_TYPE_ACSTYLE "ACStyle"
#define AUTOCONNECT_JSON_TYPE_ACSUBMIT "ACSubmit"
#define AUTOCONNECT_JSON_TYPE_ACTEXT "ACText"
+#define AUTOCONNECT_JSON_VALUE_BEHIND "behind"
#define AUTOCONNECT_JSON_VALUE_BR "br"
#define AUTOCONNECT_JSON_VALUE_EXTERNAL "extern"
#define AUTOCONNECT_JSON_VALUE_FS "fs"
#define AUTOCONNECT_JSON_VALUE_HORIZONTAL "horizontal"
+#define AUTOCONNECT_JSON_VALUE_INFRONT "infront"
#define AUTOCONNECT_JSON_VALUE_NONE "none"
#define AUTOCONNECT_JSON_VALUE_PAR "par"
#define AUTOCONNECT_JSON_VALUE_SD "sd"
@@ -113,11 +116,12 @@ class AutoConnectButtonJson : public AutoConnectElementJson, public AutoConnectB
*/
class AutoConnectCheckboxJson : public AutoConnectElementJson, public AutoConnectCheckboxBasis {
public:
- explicit AutoConnectCheckboxJson(const char* name = "", const char* value = "", const char* label = "", const bool checked = false, const ACPosterior_t post = AC_Tag_BR) {
+ explicit AutoConnectCheckboxJson(const char* name = "", const char* value = "", const char* label = "", const bool checked = false, const ACPosition_t labelPosition = AC_Behind, const ACPosterior_t post = AC_Tag_BR) {
AutoConnectCheckboxBasis::name = String(name);
AutoConnectCheckboxBasis::value = String(value);
AutoConnectCheckboxBasis::label = String(label);
AutoConnectCheckboxBasis::checked = checked;
+ AutoConnectCheckboxBasis::labelPosition = labelPosition;
AutoConnectCheckboxBasis::post = post;
_defaultPost = AC_Tag_BR;
}
diff --git a/src/AutoConnectElementJsonImpl.h b/src/AutoConnectElementJsonImpl.h
index f3c0647..16d2f36 100644
--- a/src/AutoConnectElementJsonImpl.h
+++ b/src/AutoConnectElementJsonImpl.h
@@ -139,7 +139,7 @@ void AutoConnectButtonJson::serialize(JsonObject& json) {
*/
size_t AutoConnectCheckboxJson::getObjectSize(void) const {
size_t size = AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(2);
- size += sizeof(AUTOCONNECT_JSON_KEY_LABEL) + label.length() + 1 + sizeof(AUTOCONNECT_JSON_KEY_CHECKED);
+ size += sizeof(AUTOCONNECT_JSON_KEY_LABEL) + label.length() + 1 + sizeof(AUTOCONNECT_JSON_KEY_CHECKED) + sizeof(AUTOCONNECT_JSON_KEY_LABELPOSITION) + sizeof(AUTOCONNECT_JSON_VALUE_INFRONT);
return size;
}
@@ -157,6 +157,17 @@ bool AutoConnectCheckboxJson::loadMember(const JsonObject& json) {
label = json[F(AUTOCONNECT_JSON_KEY_LABEL)].as();
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED)))
checked = json[F(AUTOCONNECT_JSON_KEY_CHECKED)].as();
+ if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABELPOSITION))) {
+ String position = json[F(AUTOCONNECT_JSON_KEY_LABELPOSITION)].as();
+ if (position.equalsIgnoreCase(F(AUTOCONNECT_JSON_VALUE_BEHIND)))
+ labelPosition = AC_Behind;
+ else if (position.equalsIgnoreCase(F(AUTOCONNECT_JSON_VALUE_INFRONT)))
+ labelPosition = AC_Infront;
+ else {
+ AC_DBG("Failed to load %s element, unknown label position:%s\n", name.c_str(), position.c_str());
+ return false;
+ }
+ }
return true;
}
return false;
@@ -173,6 +184,8 @@ void AutoConnectCheckboxJson::serialize(JsonObject& json) {
json[F(AUTOCONNECT_JSON_KEY_VALUE)] = value;
json[F(AUTOCONNECT_JSON_KEY_LABEL)] = label;
json[F(AUTOCONNECT_JSON_KEY_CHECKED)] = checked;
+ if (labelPosition == AC_Infront)
+ json[F(AUTOCONNECT_JSON_KEY_LABELPOSITION)] = AUTOCONNECT_JSON_VALUE_INFRONT;
}
/**