-
Notifications
You must be signed in to change notification settings - Fork 375
Allow SVG XML data to be passed in RML markup directly #777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
ff88e14
f36f3a2
2a73129
c4e9202
dde84fe
e0be108
d8d58d2
6979d3a
faba0bd
15a13fc
a9c9d26
a1daa50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| height: 225px; | ||
| margin: auto; | ||
| left: 400px; | ||
| top: -400px; | ||
| } | ||
|
|
||
| div.tiger { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| height: 225px; | ||
| margin: auto; | ||
| left: -400px; | ||
| top: -400px; | ||
| } | ||
|
|
||
| svg { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <rml> | ||
| <head> | ||
| <title>Demo</title> | ||
| <link type="text/template" href="/assets/window.rml" /> | ||
| <style> | ||
| body { | ||
| width: 300px; | ||
| height: 225px; | ||
| margin: auto; | ||
| left: -400px; | ||
| top: 200px; | ||
| } | ||
|
|
||
| svg { | ||
| display: block; | ||
| margin: 0 auto; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body template="window"> | ||
| <svg xmlns="http://www.w3.org/2000/svg" width="50" height="50"> | ||
| <circle cx="25" cy="25" r="20" stroke="black" stroke-width="3" fill="red" /> | ||
| </svg> | ||
| <button id="svg_inline_button">Click Me</button> | ||
| </body> | ||
| </rml> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,40 @@ | |
| #include <RmlUi_Backend.h> | ||
| #include <Shell.h> | ||
|
|
||
| class ButtonClickEventListener final : public Rml::EventListener { | ||
| public: | ||
| void ProcessEvent(Rml::Event& event) override; | ||
| }; | ||
|
|
||
| static ButtonClickEventListener click_listener; | ||
|
|
||
| void ButtonClickEventListener::ProcessEvent(Rml::Event& event) | ||
| { | ||
| if (event == Rml::EventId::Click) | ||
| { | ||
| Rml::Element* current_element = event.GetCurrentElement(); | ||
| Rml::ElementDocument* document = current_element->GetOwnerDocument(); | ||
| if (document) | ||
| { | ||
| Rml::ElementList elements; | ||
| document->GetElementsByTagName(elements, "svg"); | ||
| for (size_t i = 0; i < elements.size(); i++) | ||
| { | ||
| if (elements[i]->GetAttribute<std::string>("_toggle", "").empty()) | ||
| { | ||
| elements[i]->SetInnerRML("<circle cx=\"25\" cy=\"25\" r=\"20\" stroke=\"yellow\" stroke-width=\"3\" fill=\"green\" />"); | ||
| elements[i]->SetAttribute("_toggle", "1"); | ||
| } | ||
| else | ||
| { | ||
| elements[i]->SetInnerRML("<circle cx=\"25\" cy=\"25\" r=\"20\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" />"); | ||
| elements[i]->SetAttribute("_toggle", ""); | ||
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #if defined RMLUI_PLATFORM_WIN32 | ||
| #include <RmlUi_Include_Windows.h> | ||
| int APIENTRY WinMain(HINSTANCE /*instance_handle*/, HINSTANCE /*previous_instance_handle*/, char* /*command_line*/, int /*command_show*/) | ||
|
|
@@ -73,12 +107,19 @@ int main(int /*argc*/, char** /*argv*/) | |
| Shell::LoadFonts(); | ||
|
|
||
| // Load and show the documents. | ||
| for (const char* filename : {"basic/svg/data/svg_element.rml", "basic/svg/data/svg_decorator.rml"}) | ||
| std::vector<std::pair<std::string, std::string>> rml_docs = {{"basic/svg/data/svg_element.rml", "SVG Element"}, | ||
| {"basic/svg/data/svg_decorator.rml", "SVG Decorator"}, {"basic/svg/data/svg_inline.rml", "SVG Inline"}}; | ||
| for (const auto& rml_doc : rml_docs) | ||
| { | ||
| if (Rml::ElementDocument* document = context->LoadDocument(filename)) | ||
| if (Rml::ElementDocument* document = context->LoadDocument(rml_doc.first)) | ||
| { | ||
| document->Show(); | ||
| document->GetElementById("title")->SetInnerRML("SVG"); | ||
| document->GetElementById("title")->SetInnerRML(rml_doc.second); | ||
| Rml::Element* e = document->GetElementById("svg_inline_button"); | ||
| if (e != nullptr) | ||
| { | ||
| e->AddEventListener("click", &click_listener, false); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,11 @@ void BaseXMLParser::RegisterCDATATag(const String& tag) | |
| cdata_tags.insert(StringUtilities::ToLower(tag)); | ||
| } | ||
|
|
||
| bool BaseXMLParser::IsCDATATag(const String& tag) | ||
| { | ||
| return cdata_tags.find(StringUtilities::ToLower(tag)) != cdata_tags.end(); | ||
| } | ||
|
|
||
| void BaseXMLParser::RegisterInnerXMLAttribute(const String& attribute_name) | ||
| { | ||
| attributes_for_inner_xml_data.insert(attribute_name); | ||
|
|
@@ -268,16 +273,15 @@ bool BaseXMLParser::ReadOpenTag() | |
| if (section_opened) | ||
| { | ||
| const String lcase_tag_name = StringUtilities::ToLower(tag_name); | ||
| bool is_cdata_tag = (cdata_tags.find(lcase_tag_name) != cdata_tags.end()); | ||
|
|
||
| if (is_cdata_tag) | ||
| if (IsCDATATag(lcase_tag_name)) | ||
|
||
| { | ||
| if (ReadCDATA(lcase_tag_name.c_str())) | ||
| { | ||
| open_tag_depth--; | ||
| if (!data.empty()) | ||
| { | ||
| HandleDataInternal(data, XMLDataType::CData); | ||
| HandleDataInternal(data, XMLDataType::CDATA); | ||
| data.clear(); | ||
| } | ||
| HandleElementEndInternal(tag_name); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,6 +354,12 @@ ElementPtr Factory::InstanceElement(Element* parent, const String& instancer_nam | |
| bool Factory::InstanceElementText(Element* parent, const String& in_text) | ||
| { | ||
| RMLUI_ASSERT(parent); | ||
| XMLParser parser(parent); | ||
| if (parser.IsCDATATag(parent->GetTagName())) | ||
| { | ||
| parser.HandleData(in_text, XMLDataType::CDATA); | ||
| return true; | ||
| } | ||
|
||
|
|
||
| String text; | ||
| if (SystemInterface* system_interface = GetSystemInterface()) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.