uiObject.h (3775B)
1 #pragma once 2 3 #include <map> 4 #include <memory> 5 #include <set> 6 #include <string> 7 #include <vector> 8 9 #include "condition.h" 10 #include "controllerlink.h" 11 #include "tabgroup.h" 12 13 namespace juce 14 { 15 class HyperlinkButton; 16 class TextButton; 17 class Label; 18 class DrawableButton; 19 class ComboBox; 20 class LookAndFeel_V4; 21 class Slider; 22 class Component; 23 class DynamicObject; 24 class var; 25 } 26 27 namespace genericUI 28 { 29 class ButtonStyle; 30 class UiObjectStyle; 31 class Editor; 32 33 class UiObject 34 { 35 public: 36 explicit UiObject(UiObject* _parent, const juce::var& _json, bool _isTemplate = false); 37 ~UiObject(); 38 39 void createJuceTree(Editor& _editor); 40 void createChildObjects(Editor& _editor, juce::Component& _parent) const; 41 void createTabGroups(Editor& _editor); 42 void createControllerLinks(Editor& _editor) const; 43 void registerTemplates(Editor& _editor) const; 44 45 void apply(const Editor& _editor, juce::Component& _target); 46 void apply(Editor& _editor, juce::Slider& _target); 47 void apply(Editor& _editor, juce::ComboBox& _target); 48 void apply(Editor& _editor, juce::DrawableButton& _target); 49 50 void apply(Editor& _editor, juce::Label& _target); 51 void apply(Editor& _editor, juce::ScrollBar& _target); 52 void apply(Editor& _editor, juce::TextButton& _target); 53 void apply(Editor& _editor, juce::HyperlinkButton& _target); 54 void apply(Editor& _editor, juce::TreeView& _target); 55 void apply(Editor& _editor, juce::ListBox& _target); 56 void apply(Editor& _editor, juce::TextEditor& _target); 57 58 template<typename TComponent, typename TStyle> 59 void applyT(Editor& _editor, TComponent& _target); 60 61 void collectVariants(std::set<std::string>& _dst, const std::string& _property) const; 62 63 juce::Component* createJuceObject(Editor& _editor); 64 65 int getPropertyInt(const std::string& _key, int _default = 0) const; 66 float getPropertyFloat(const std::string& _key, float _default = 0.0f) const; 67 std::string getProperty(const std::string& _key, const std::string& _default = std::string()) const; 68 69 size_t getConditionCountRecursive() const; 70 size_t getControllerLinkCountRecursive() const; 71 72 void setCurrentPart(Editor& _editor, uint8_t _part); 73 74 const auto& getName() const { return m_name; } 75 76 void updateKeyValueConditions(const std::string& _key, const std::string& _value) const; 77 78 private: 79 bool hasComponent(const std::string& _component) const; 80 template<typename T, class... Args> T* createJuceObject(Editor& _editor, Args... _args); 81 template<typename T> T* createJuceObject(Editor& _editor, T* _object); 82 void createCondition(const Editor& _editor, juce::Component& _target); 83 84 juce::DynamicObject& applyStyle(juce::DynamicObject& _obj, const std::string& _styleName); 85 86 static bool copyPropertiesRecursive(juce::DynamicObject& _target, const juce::DynamicObject& _source); 87 88 bool parse(juce::DynamicObject* _obj); 89 90 template<typename T> void bindParameter(const Editor& _editor, T& _target) const; 91 92 void readProperties(juce::Component& _target); 93 94 template<typename Target, typename Style> 95 void createStyle(Editor& _editor, Target& _target, Style* _style); 96 97 bool m_isTemplate; 98 std::string m_name; 99 std::map<std::string, std::map<std::string, std::string>> m_components; 100 std::vector<std::unique_ptr<UiObject>> m_children; 101 UiObject* m_parent = nullptr; 102 103 std::vector<std::shared_ptr<UiObject>> m_templates; 104 105 std::vector<std::unique_ptr<juce::Component>> m_juceObjects; 106 std::unique_ptr<UiObjectStyle> m_style; 107 108 std::map<std::string, juce::var> m_styles; 109 110 std::unique_ptr<Condition> m_condition; 111 112 TabGroup m_tabGroup; 113 std::vector<std::unique_ptr<ControllerLink>> m_controllerLinks; 114 }; 115 116 inline bool UiObject::hasComponent(const std::string& _component) const 117 { 118 return m_components.find(_component) != m_components.end(); 119 } 120 }