Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
MathOpPropertyPanel.h
Go to the documentation of this file.
1/**
2 * @file MathOpPropertyPanel.h
3 * @brief UI Properties panel for a MathOp node – operand editor.
4 * @author Olympe Engine
5 * @date 2026-03-18
6 *
7 * @details
8 * MathOpPropertyPanel renders the Properties panel for a selected MathOp node.
9 * It provides inline editors for:
10 * - Left operand (Variable/Const/Pin mode selector + value)
11 * - Operator (dropdown: "+", "-", "*", "/", "%", "^")
12 * - Right operand (Variable/Const/Pin mode selector + value)
13 *
14 * Changes are immediately applied and trigger callbacks to regenerate
15 * dynamic pins and update the canvas.
16 *
17 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
18 */
19
20#pragma once
21
22#include <string>
23#include <vector>
24#include <functional>
25
26#include "../ConditionPreset/ConditionPresetRegistry.h"
27#include "../ConditionPreset/DynamicDataPinManager.h"
28#include "../ConditionPreset/DynamicDataPin.h"
29#include "../../BlueprintEditor/MathOpOperand.h"
30
31namespace Olympe {
32
33/**
34 * @class MathOpPropertyPanel
35 * @brief ImGui sub-panel for editing MathOp operands and operator.
36 *
37 * @details
38 * The panel does NOT own the data — it holds references.
39 * The caller is responsible for persisting changes from GetMathOpRef()
40 * back to the node definition.
41 *
42 * Dependency injection:
43 * MathOpPropertyPanel panel(registry, dynamicPinManager);
44 * panel.SetMathOpRef(node.mathOpRef);
45 * panel.SetDynamicPins(node.dynamicPins);
46 * panel.SetNodeName(node.NodeName);
47 * panel.Render();
48 * if (panel.IsDirty()) {
49 * node.mathOpRef = panel.GetMathOpRef();
50 * panel.ClearDirty();
51 * }
52 */
54public:
55
56 /**
57 * @brief Constructs the panel bound to a preset registry.
58 * @param registry Global ConditionPresetRegistry (must outlive this panel).
59 * @param dynamicPinMgr DynamicDataPinManager for Pin-mode generation.
60 */
61 explicit MathOpPropertyPanel(
64
66
67 // Non-copyable
70
71 // -----------------------------------------------------------------------
72 // State accessors
73 // -----------------------------------------------------------------------
74
75 /**
76 * @brief Sets the MathOpRef to edit.
77 * @param ref MathOpRef from node.mathOpRef.
78 */
79 void SetMathOpRef(const MathOpRef& ref);
80
81 /**
82 * @brief Returns the current (possibly modified) MathOpRef.
83 */
84 const MathOpRef& GetMathOpRef() const;
85
86 /**
87 * @brief Provides the read-only list of dynamic pins for display.
88 * @param pins Current dynamic pins associated with this MathOp node.
89 */
90 void SetDynamicPins(const std::vector<DynamicDataPin>& pins);
91
92 /**
93 * @brief Sets the node name displayed in the title section.
94 * @param name Human-readable node name (e.g., "MathOp_1").
95 */
96 void SetNodeName(const std::string& name);
97
98 /**
99 * @brief Returns true if the operand or operator has been modified
100 * since the last call to ClearDirty().
101 */
102 bool IsDirty() const { return m_dirty; }
103
104 /**
105 * @brief Resets the dirty flag.
106 */
107 void ClearDirty() { m_dirty = false; }
108
109 /**
110 * @brief Registers a callback to be invoked when Pin-mode operands change.
111 *
112 * The callback should regenerate dynamic pins via DynamicDataPinManager
113 * and trigger a canvas refresh.
114 *
115 * @param cb Callback function.
116 */
117 void SetOnOperandChange(std::function<void()> cb)
118 {
120 }
121
122 // -----------------------------------------------------------------------
123 // Rendering
124 // -----------------------------------------------------------------------
125
126 /**
127 * @brief Renders the panel into the current ImGui context.
128 *
129 * Must be called between ImGui::Begin() / ImGui::End() or within
130 * a child window. Handles layout, operand editors, and state synchronization.
131 */
132 void Render();
133
134private:
135
136 // -----------------------------------------------------------------------
137 // Private rendering methods
138 // -----------------------------------------------------------------------
139
140 /// Renders the title section (node name in blue background).
141 void RenderTitleSection();
142
143 /// Renders the operand editor (collapsible section with 3 rows).
145
146 /// Renders one operand row with mode selector and value input.
147 /// @param rowIndex 0 = left operand, 1 = right operand
148 /// @param operand MathOpOperand to edit
150
151 /// Renders the operator dropdown ("+", "-", "*", "/", "%", "^").
153
154 /// Renders the dynamic pins section (read-only display).
156
157 // -----------------------------------------------------------------------
158 // Private helpers
159 // -----------------------------------------------------------------------
160
161 /// Helper to render Variable mode input field.
163
164 /// Helper to render Const mode input field.
166
167 /// Helper to render Pin mode selector (list of available pins).
169
170 // -----------------------------------------------------------------------
171 // Data members
172 // -----------------------------------------------------------------------
173
174 ConditionPresetRegistry& m_registry; ///< Global preset registry
175 DynamicDataPinManager& m_dynamicPinMgr; ///< Pin generation manager
176
177 std::string m_nodeName; ///< Node name for display
178 MathOpRef m_mathOpRef; ///< Current operand configuration
179 std::vector<DynamicDataPin> m_dynamicPins; ///< Read-only dynamic pins display
180
181 bool m_operandEditorOpen = true; ///< Collapsible section state
182 bool m_dirty = false; ///< Changed since last ClearDirty()
183
184 std::function<void()> m_onOperandChange; ///< Callback when operands change
185};
186
187} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Manages the global pool of ConditionPreset objects.
Generates, tracks, and invalidates DynamicDataPin objects for a node.
ImGui sub-panel for editing MathOp operands and operator.
MathOpPropertyPanel(const MathOpPropertyPanel &)=delete
bool m_dirty
Changed since last ClearDirty()
void SetNodeName(const std::string &name)
Sets the node name displayed in the title section.
bool IsDirty() const
Returns true if the operand or operator has been modified since the last call to ClearDirty().
void SetDynamicPins(const std::vector< DynamicDataPin > &pins)
Provides the read-only list of dynamic pins for display.
MathOpRef m_mathOpRef
Current operand configuration.
void RenderPinModeSelector(MathOpOperand &operand)
Helper to render Pin mode selector (list of available pins).
std::string m_nodeName
Node name for display.
void RenderVariableModeInput(MathOpOperand &operand)
Helper to render Variable mode input field.
void RenderOperatorSelector()
Renders the operator dropdown ("+", "-", "*", "/", "%", "^").
void SetMathOpRef(const MathOpRef &ref)
Sets the MathOpRef to edit.
void RenderTitleSection()
Renders the title section (node name in blue background).
void RenderDynamicPinsSection()
Renders the dynamic pins section (read-only display).
void RenderConstModeInput(MathOpOperand &operand)
Helper to render Const mode input field.
const MathOpRef & GetMathOpRef() const
Returns the current (possibly modified) MathOpRef.
void SetOnOperandChange(std::function< void()> cb)
Registers a callback to be invoked when Pin-mode operands change.
bool m_operandEditorOpen
Collapsible section state.
void RenderInlineOperandEditor()
Renders the operand editor (collapsible section with 3 rows).
void ClearDirty()
Resets the dirty flag.
DynamicDataPinManager & m_dynamicPinMgr
Pin generation manager.
void RenderOperandRow(int rowIndex, MathOpOperand &operand)
Renders one operand row with mode selector and value input.
std::vector< DynamicDataPin > m_dynamicPins
Read-only dynamic pins display.
MathOpPropertyPanel & operator=(const MathOpPropertyPanel &)=delete
ConditionPresetRegistry & m_registry
Global preset registry.
std::function< void()> m_onOperandChange
Callback when operands change.
void Render()
Renders the panel into the current ImGui context.
< Provides AssetID and INVALID_ASSET_ID
Represents one arithmetic operand (left A, right B) in a MathOp node.
Complete reference for a MathOp node: left operand, operator, right operand.