Enzo
Loading...
Searching...
No Matches
Template.h
1#pragma once
2#include "Engine/Core/Types.h"
3#include "Engine/Parameter/Default.h"
4#include "Engine/Parameter/PrmName.h"
5#include "Engine/Parameter/Range.h"
6#include <any>
7#include <memory>
8#include <optional>
9#include <string>
10#include <unordered_map>
11#include <unordered_set>
12#include <utility>
13#include <vector>
14
15namespace enzo::prm {
16
18{
19 public:
20 Template(enzo::prm::Type type, prm::Name name);
21 Template(enzo::prm::Type type, prm::Name name, unsigned int vectorSize);
23 enzo::prm::Type type,
24 prm::Name name,
25 std::vector<prm::Default> defaults,
26 unsigned int vectorSize = 1,
27 std::vector<prm::Range> ranges = std::vector<prm::Range>()
28 );
30 enzo::prm::Type type,
31 prm::Name name,
32 prm::Default theDefault,
33 unsigned int vectorSize = 1,
34 Range range = Range()
35 );
36 // get name and get token are identical
37 enzo::String getName() const;
38 enzo::String getToken() const;
39 enzo::String getLabel() const;
40 const prm::Default getDefault(unsigned int index = 0) const;
41 const prm::Range& getRange(unsigned int index = 0) const;
52 const std::vector<prm::Name>& getOptions() const;
53 bool hasOptions() const;
54
56 intT getNumOptions() const;
57
58 const prm::Type getType() const;
59 const unsigned int getSize() const;
60 const unsigned int getNumDefaults() const;
61
62 Direction getDirection() const;
63 const std::vector<Template>& getChildren() const;
64
67 const Template& getChild(const enzo::String& token) const;
68
69 const bool isContainer() const;
70 bool isMultiParm() const;
71
72 enzo::String getTooltip() const;
73 enzo::String getDocumentation() const;
76 enzo::String getDisableCondition() const;
79 enzo::String getHideCondition() const;
80 bool isLabelHidden() const;
81 bool isBackgroundEnabled() const;
82
83 // Chainable setters. Mutate in place and return *this so a Template can
84 // be configured inline at construction.
85 Template& setTooltip(String tooltip);
86 Template& setDocumentation(String documentation);
87 Template& setDisableCondition(String condition);
88 Template& setHideCondition(String condition);
89 Template& setDirection(Direction direction);
90 Template& setOptions(std::vector<prm::Name> options);
91 Template& addParm(Template child);
92 // Supplies the per instance default for a multiparm field, one Default per
93 // instance. Entries past the live count are ignored, missing ones fall back
94 // to the field's own default.
95 Template& setInstanceDefault(std::string fieldToken, std::vector<Default> defaults);
98 std::optional<Default>
99 getInstanceDefault(const std::string& fieldToken, unsigned int instanceIndex) const;
100 Template& setLabelHidden(bool hidden);
101 Template& setBackgroundEnabled(bool enabled);
102
103 // Style structs may hold parameters with change signals, which cannot
104 // be copied. Wrapping in a shared pointer lets the style live inside
105 // the std::any without ever being copied.
106 template <typename T> Template& setStyle(T style)
107 {
108 style_ = std::make_shared<T>(std::move(style));
109 return *this;
110 }
111
112 const std::any& getStyle() const;
113
114 private:
115 enzo::prm::Type type_;
116 std::vector<prm::Default> defaults_;
117 std::vector<prm::Range> ranges_;
118 std::vector<prm::Name> options_;
119 prm::Name name_;
120 unsigned int vectorSize_;
121
122 String tooltip_;
123 String documentation_;
124 String disableCondition_;
125 String hideCondition_;
126
127 bool labelHidden_ = false;
128 bool backgroundEnabled_ = true;
129
130 Direction direction_ = Direction::HORIZONTAL;
131 std::vector<Template> children_;
132 std::unordered_map<std::string, std::vector<Default>> instanceDefaults_;
133 std::any style_;
134 inline const static std::unordered_set<prm::Type> containerTypes_ = {prm::Type::GROUP};
135 // Types whose children are the per instance template duplicated by the
136 // parameter count.
137 inline const static std::unordered_set<prm::Type> multiParmTypes_ = {prm::Type::RAMP};
138 inline const static std::unordered_set<prm::Type> backgroundDisabledByDefault_ =
139 {prm::Type::GROUP, prm::Type::XYZ, prm::Type::SPACER};
140 // Types that render without a label, such as blank spacers.
141 inline const static std::unordered_set<prm::Type> labelHiddenByDefault_ = {prm::Type::SPACER};
142};
143
144} // namespace enzo::prm
Basic attribute, parameter, and node types for Enzo.
Definition Default.h:7
Definition PrmName.h:6
Definition Range.h:13
Definition Template.h:18
const Template & getChild(const enzo::String &token) const
Returns the child template with the given token.
Definition Template.cpp:121
const std::vector< prm::Name > & getOptions() const
The set of named values this parameter can be set to.
Definition Template.cpp:103
std::optional< Default > getInstanceDefault(const std::string &fieldToken, unsigned int instanceIndex) const
The default for a multiparm field at a given instance.
Definition Template.cpp:198
enzo::String getDisableCondition() const
A condition that greys the parameter out, such as "applyscale == 0".
Definition Template.cpp:132
enzo::String getHideCondition() const
A condition that hides the parameter, such as "profileshape != 1".
Definition Template.cpp:134
intT getNumOptions() const
The number of available options.
Definition Template.cpp:107