Commit 64f728ca authored by jan.koester's avatar jan.koester
Browse files

test

parent 6e2039ef
Loading
Loading
Loading
Loading
+79 −0
Changes for editor/widgets/textbox/textbox.cpp: 79 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -72,6 +72,10 @@ extern "C" {
            std::string fontStyle    = "normal";
            std::string whiteSpace   = "normal";

            // Icon
            std::string icon         = "none";
            std::string iconColor    = "";

            // Dimensions
            std::string width        = "";
            std::string height       = "";
@@ -147,6 +151,32 @@ extern "C" {
                }
                settings.appendChild(taSelect);

                // Icon
                libhtmlpp::HtmlElement iconLabel("label");
                iconLabel.appendChild(libhtmlpp::TextElement("Icon: "));
                settings.appendChild(iconLabel);
                libhtmlpp::HtmlElement iconSelect("select");
                iconSelect.setAttribute("name", "icon");
                const char* icons[] = {"none", "phone", "address", "email", "arrow_left", "arrow_right", "arrow_up", "arrow_down"};
                for (const char* i : icons) {
                    libhtmlpp::HtmlElement opt("option");
                    opt.setAttribute("value", i);
                    if (icon == i) opt.setAttribute("selected", "selected");
                    opt.appendChild(libhtmlpp::TextElement(i));
                    iconSelect.appendChild(opt);
                }
                settings.appendChild(iconSelect);

                // Icon color
                libhtmlpp::HtmlElement icLabel("label");
                icLabel.appendChild(libhtmlpp::TextElement("Icon Color: "));
                settings.appendChild(icLabel);
                libhtmlpp::HtmlElement icInput("input");
                icInput.setAttribute("type", "color");
                icInput.setAttribute("name", "icon_color");
                icInput.setAttribute("value", iconColor.c_str());
                settings.appendChild(icInput);

                // Content textarea
                libhtmlpp::HtmlElement cLabel("label");
                cLabel.appendChild(libhtmlpp::TextElement("Content: "));
@@ -235,6 +265,8 @@ extern "C" {
                addField("font_weight", "Font Weight", "select", nullptr, "all", mkOpts({"normal","bold","lighter","bolder"}));
                addField("font_style", "Font Style", "select", nullptr, "all", mkOpts({"normal","italic","oblique"}));
                addField("white_space", "Zeilenumbruch", "select", nullptr, "all", mkOpts({"normal","nowrap","pre","pre-wrap","pre-line","break-spaces"}));
                addField("icon", "Icon", "select", nullptr, "all", mkOpts({"none","phone","address","email","arrow_left","arrow_right","arrow_up","arrow_down"}));
                addField("icon_color", "Icon Color", "color_var", nullptr, "all");
                addField("hidden", "Hidden", "checkbox", nullptr, "desktop");
                {
                    json_object *hf = json_object_array_get_idx(arr, json_object_array_length(arr) - 1);
@@ -267,6 +299,8 @@ extern "C" {
                element->SetAttribute("font_weight", fontWeight.c_str());
                element->SetAttribute("font_style", fontStyle.c_str());
                element->SetAttribute("white_space", whiteSpace.c_str());
                element->SetAttribute("icon", icon.c_str());
                element->SetAttribute("icon_color", iconColor.c_str());

                // Dimensions
                element->SetAttribute("width", width.c_str());
@@ -326,6 +360,12 @@ extern "C" {
                val = xml_data->Attribute("white_space");
                if (val) whiteSpace = val;

                val = xml_data->Attribute("icon");
                if (val) icon = val;

                val = xml_data->Attribute("icon_color");
                if (val) iconColor = val;

                // Dimensions
                val = xml_data->Attribute("width");
                if (val) width = val;
@@ -372,6 +412,8 @@ extern "C" {
                json_object_object_add(obj, "font_weight", json_object_new_string(fontWeight.c_str()));
                json_object_object_add(obj, "font_style", json_object_new_string(fontStyle.c_str()));
                json_object_object_add(obj, "white_space", json_object_new_string(whiteSpace.c_str()));
                json_object_object_add(obj, "icon", json_object_new_string(icon.c_str()));
                json_object_object_add(obj, "icon_color", json_object_new_string(iconColor.c_str()));
                json_object_object_add(obj, "width", json_object_new_string(width.c_str()));
                json_object_object_add(obj, "height", json_object_new_string(height.c_str()));
                json_object_object_add(obj, "content", json_object_new_string(content.c_str()));
@@ -426,6 +468,14 @@ extern "C" {
                    val = json_object_get_string(val_obj);
                    if (val) whiteSpace = val;
                }
                if (json_object_object_get_ex(obj, "icon", &val_obj)) {
                    val = json_object_get_string(val_obj);
                    if (val) icon = val;
                }
                if (json_object_object_get_ex(obj, "icon_color", &val_obj)) {
                    val = json_object_get_string(val_obj);
                    if (val) iconColor = val;
                }
                if (json_object_object_get_ex(obj, "width", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) width = val;
                }
@@ -539,6 +589,35 @@ extern "C" {
                    el.appendChild(cssStyle);
                }

                if (icon != "none" && !icon.empty()) {
                    std::string fill = iconColor.empty() ? "currentColor" : iconColor;
                    std::string svg_base = "<svg style=\"vertical-align: middle; margin-right: 8px;\" width=\"1em\" height=\"1em\" viewBox=\"0 0 24 24\" fill=\"" + fill + "\" xmlns=\"http://www.w3.org/2000/svg\">";
                    std::string iconHtml = "";
                    if (icon == "phone") {
                        iconHtml = svg_base + "<path d=\"M6.62 10.79c1.44 2.83 3.76 5.15 6.59 6.59l2.2-2.2c.28-.28.67-.36 1.02-.25 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z\"/></svg>";
                    } else if (icon == "address") {
                        iconHtml = svg_base + "<path d=\"M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z\"/></svg>";
                    } else if (icon == "email") {
                        iconHtml = svg_base + "<path d=\"M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z\"/></svg>";
                    } else if (icon == "arrow_left") {
                        iconHtml = svg_base + "<path d=\"M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z\"/></svg>";
                    } else if (icon == "arrow_right") {
                        iconHtml = svg_base + "<path d=\"M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z\"/></svg>";
                    } else if (icon == "arrow_up") {
                        iconHtml = svg_base + "<path d=\"M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6 1.41 1.41z\"/></svg>";
                    } else if (icon == "arrow_down") {
                        iconHtml = svg_base + "<path d=\"M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z\"/></svg>";
                    }
                    if (!iconHtml.empty()) {
                        try {
                            libhtmlpp::HtmlString htmlBuf("<span class=\"we-icon\">" + iconHtml + "</span>");
                            libhtmlpp::Element &parsed = htmlBuf.parse();
                            box.appendChild(parsed);
                        } catch (...) {
                        }
                    }
                }

                if (!content.empty()) {
                    // Content contains HTML markup from the rich text editor;
                    // parse it into an element tree and append to the box.