1313
1414namespace eclipse ::components {
1515 enum class ComponentType {
16- Label, Toggle
16+ Label, Toggle, Button, InputFloat
1717 };
1818
1919 template <ComponentType T>
@@ -22,27 +22,49 @@ namespace eclipse::components {
2222 constexpr ComponentType getType () const { return T; }
2323 size_t getUniqueID () const { return m_uniqueID; }
2424 explicit Component (size_t id) : m_uniqueID(id) {}
25- private:
25+ protected:
26+ void setDescriptionImpl (const std::string& description) const ;
2627 size_t m_uniqueID = 0 ;
2728 };
2829
29- using Label = Component<ComponentType::Label>;
30+ class Label final : public Component<ComponentType::Label> {
31+ public:
32+ explicit Label (size_t uid) : Component(uid) {}
33+ Label& setText (const std::string& text);
34+ Label const & setText (const std::string& text) const ;
35+ };
36+
3037 class Toggle final : public Component<ComponentType::Toggle> {
3138 public:
3239 Toggle (size_t uid, std::string id) : Component(uid), m_id(std::move(id)) {}
3340 const std::string& getID () const { return m_id; }
34- Toggle& setDescription (const std::string& description);
35- // Toggle& addOptions(const std::function<void()>& options);
41+ Toggle& setDescription (const std::string& description) { setDescriptionImpl (description); return *this ; }
42+
43+ bool getValue () const ;
3644 private:
3745 std::string m_id;
3846 };
39- class Button final : public Component<ComponentType::Label> {
47+
48+ class Button final : public Component<ComponentType::Button> {
4049 public:
4150 explicit Button (size_t uid) : Component(uid) {}
42- Button& setDescription (const std::string& description);
43- // Button& setText(const std::string& text);
51+ Button& setDescription (const std::string& description) { setDescriptionImpl (description); return *this ; }
4452 };
4553
54+ class InputFloat final : public Component<ComponentType::InputFloat> {
55+ public:
56+ InputFloat (size_t uid, std::string id) : Component(uid), m_id(std::move(id)) {}
57+ const std::string& getID () const { return m_id; }
58+ InputFloat& setDescription (const std::string& description) { setDescriptionImpl (description); return *this ; }
59+
60+ float getValue () const ;
61+
62+ InputFloat& setMinValue (float value);
63+ InputFloat& setMaxValue (float value);
64+ InputFloat& setFormat (const std::string& format);
65+ private:
66+ std::string m_id;
67+ };
4668}
4769
4870namespace eclipse {
@@ -54,6 +76,7 @@ namespace eclipse {
5476 components::Toggle addToggle (const std::string& id, const std::string& title, const std::function<void (bool )> &callback) const ;
5577 components::Toggle addModSettingToggle (std::shared_ptr<geode::Setting> const & setting) const ;
5678 components::Button addButton (const std::string& title, const std::function<void ()>& callback) const ;
79+ components::InputFloat addInputFloat (const std::string& id, const std::string& title, const std::function<void (float )>& callback) const ;
5780
5881 const std::string& getName () const { return m_name; }
5982 private:
@@ -96,6 +119,7 @@ namespace eclipse::events {
96119 using AddLabelEvent = AddComponentEvent<>;
97120 using AddToggleEvent = AddComponentEvent<std::function<void (bool )>>;
98121 using AddButtonEvent = AddComponentEvent<std::function<void ()>>;
122+ using AddInputFloatEvent = AddComponentEvent<std::function<void (float )>>;
99123
100124 class SetComponentDescriptionEvent : public geode ::Event {
101125 public:
@@ -107,6 +131,32 @@ namespace eclipse::events {
107131 size_t m_id;
108132 std::string m_description;
109133 };
134+
135+ class SetLabelTextEvent : public geode ::Event {
136+ public:
137+ SetLabelTextEvent (size_t id, std::string text)
138+ : m_id(id), m_text(std::move(text)) {}
139+ size_t getID () const { return m_id; }
140+ const std::string& getText () const { return m_text; }
141+ private:
142+ size_t m_id;
143+ std::string m_text;
144+ };
145+
146+ class SetInputFloatParamsEvent : public geode ::Event {
147+ public:
148+ SetInputFloatParamsEvent (size_t id, std::optional<float > min, std::optional<float > max, std::optional<std::string> format)
149+ : m_id(id), m_min(min), m_max(max), m_format(std::move(format)) {}
150+ size_t getID () const { return m_id; }
151+ std::optional<float > getMin () const { return m_min; }
152+ std::optional<float > getMax () const { return m_max; }
153+ const std::optional<std::string>& getFormat () const { return m_format; }
154+ private:
155+ size_t m_id;
156+ std::optional<float > m_min;
157+ std::optional<float > m_max;
158+ std::optional<std::string> m_format;
159+ };
110160}
111161
112162namespace eclipse {
@@ -169,21 +219,68 @@ namespace eclipse {
169219 return components::Button (event.getUniqueID ());
170220 }
171221
222+ // / @brief Add an input float to the tab.
223+ // / @param id The ID of the input float.
224+ // / @param title The title of the input float.
225+ // / @param callback The callback function to call when the input float is changed.
226+ inline components::InputFloat MenuTab::addInputFloat (const std::string& id, const std::string& title, const std::function<void (float )>& callback) const {
227+ events::AddInputFloatEvent event (this , id, title, callback);
228+ event.post ();
229+ return components::InputFloat (event.getUniqueID (), id);
230+ }
231+
172232 namespace components {
173- // / @brief Set the description of the toggle .
233+ // / @brief Set the description of the component .
174234 // / @param description The description to set.
175- inline Toggle& Toggle::setDescription (const std::string& description) {
235+ template <ComponentType T>
236+ void Component<T>::setDescriptionImpl(const std::string& description) const {
176237 events::SetComponentDescriptionEvent (getUniqueID (), description).post ();
238+ }
239+
240+ // / @brief Set the text of the label.
241+ // / @param text The text to set.
242+ inline Label& Label::setText (const std::string& text) {
243+ events::SetLabelTextEvent (getUniqueID (), text).post ();
177244 return *this ;
178245 }
179246
180- // / @brief Set the description of the button.
181- // / @param description The description to set.
182- inline Button& Button::setDescription (const std::string& description) {
183- events::SetComponentDescriptionEvent (getUniqueID (), description).post ();
247+ // / @brief Set the text of the label.
248+ // / @param text The text to set.
249+ inline Label const & Label::setText (const std::string& text) const {
250+ events::SetLabelTextEvent (getUniqueID (), text).post ();
251+ return *this ;
252+ }
253+
254+ // / @brief Get the value of the toggle.
255+ inline bool Toggle::getValue () const {
256+ return config::get<bool >(m_id, false );
257+ }
258+
259+ // / @brief Get the value of the input float.
260+ inline float InputFloat::getValue () const {
261+ return config::get<float >(m_id, 0 .f );
262+ }
263+
264+ // / @brief Set the minimum allowed value of the input float.
265+ // / @param value The value to set.
266+ inline InputFloat& InputFloat::setMinValue (float value) {
267+ events::SetInputFloatParamsEvent (getUniqueID (), value, std::nullopt , std::nullopt ).post ();
184268 return *this ;
185269 }
186270
271+ // / @brief Set the maximum allowed value of the input float.
272+ // / @param value The value to set.
273+ inline InputFloat& InputFloat::setMaxValue (float value) {
274+ events::SetInputFloatParamsEvent (getUniqueID (), std::nullopt , value, std::nullopt ).post ();
275+ return *this ;
276+ }
277+
278+ // / @brief Set the format string of the input float.
279+ // / @param format The format string to set. (e.g. "%.2f")
280+ inline InputFloat& InputFloat::setFormat (const std::string& format) {
281+ events::SetInputFloatParamsEvent (getUniqueID (), std::nullopt , std::nullopt , format).post ();
282+ return *this ;
283+ }
187284 }
188285}
189286
0 commit comments