Added the labelPosition attribute with AutoConnectCheckbox

pull/110/head
Hieromon Ikasamo 5 years ago
parent 478815d1d7
commit af998981ee
  1. 1
      examples/Elements/Elements.ino
  2. 8
      src/AutoConnectElementBasis.h
  3. 10
      src/AutoConnectElementBasisImpl.h
  4. 6
      src/AutoConnectElementJson.h
  5. 15
      src/AutoConnectElementJsonImpl.h

@ -42,6 +42,7 @@ static const char PAGE_ELEMENTS[] PROGMEM = R"(
"type": "ACCheckbox",
"value": "check",
"label": "Check",
"labelposition": "infront",
"checked": true
},
{

@ -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 */
};
/**

@ -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("\"><label for=\"")) + name + String("\">") + label + String(F("</label"));
html += String(">");
html += String(F(" id=\"")) + name + String("\">");
if (label.length()) {
String labelTag = String(F("<label for=\"")) + name + String(F("\">")) + label + String(F("</label>"));
if (labelPosition == AC_Infront)
html = labelTag + html;
else if (labelPosition == AC_Behind)
html += labelTag;
}
html = AutoConnectElementBasis::posterior(html);
}
return html;

@ -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"
@ -163,11 +166,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;
}

@ -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<String>();
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED)))
checked = json[F(AUTOCONNECT_JSON_KEY_CHECKED)].as<bool>();
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABELPOSITION))) {
String position = json[F(AUTOCONNECT_JSON_KEY_LABELPOSITION)].as<String>();
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;
}
/**

Loading…
Cancel
Save