MCPcopy Create free account
hub / github.com/christophhart/HISE / fromJSON

Method fromJSON

hi_scripting/scripting/api/DynamicComponentContainer.cpp:713–749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

711}
712
713ValueTree Data::fromJSON(const var& obj, Rectangle<int> position)
714{
715 auto v = ValueTreeConverters::convertDynamicObjectToContentProperties(obj);
716
717 v.setProperty(dcid::x, position.getX(), nullptr);
718 v.setProperty(dcid::y, position.getY(), nullptr);
719 v.setProperty(dcid::width, position.getWidth(), nullptr);
720 v.setProperty(dcid::height, position.getHeight(), nullptr);
721
722 std::map<String, String> typesToConvert = {
723 { "ScriptButton", "Button" },
724 { "ScriptSlider", "Slider" },
725 { "ScriptComboBox", "ComboBox" },
726 { "ScriptLabel", "Label" },
727 { "ScriptPanel", "Panel" }
728 };
729
730 valuetree::Helpers::forEach(v, [&](ValueTree& c)
731 {
732 auto type = c[dcid::type].toString();
733
734 if(typesToConvert.find(type) != typesToConvert.end())
735 c.setProperty(dcid::type, typesToConvert[type], nullptr);
736
737 if(!c.hasProperty(dcid::width))
738 c.setProperty(dcid::width, 128, nullptr);
739 if(!c.hasProperty(dcid::height))
740 c.setProperty(dcid::height, 50, nullptr);
741
742 auto pid = c.getParent()[dcid::id];
743 c.setProperty(dcid::parentComponent, pid, nullptr);
744
745 return false;
746 });
747
748 return v;
749}
750
751ReferenceCountedObjectPtr<Base> Data::create(const ValueTree& v)
752{

Callers 4

ScriptNetworkTestMethod · 0.45
setTestPropertyMethod · 0.45
setTimestretchOptionsMethod · 0.45

Calls 11

forEachFunction · 0.50
setPropertyMethod · 0.45
getXMethod · 0.45
getYMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
toStringMethod · 0.45
findMethod · 0.45
endMethod · 0.45
hasPropertyMethod · 0.45
getParentMethod · 0.45

Tested by 2

ScriptNetworkTestMethod · 0.36
setTestPropertyMethod · 0.36