yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_panel.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_EDITOR_PANEL_H_
2#define YAZE_APP_EDITOR_SYSTEM_EDITOR_PANEL_H_
3
4#include <any>
5#include <functional>
6#include <string>
7#include <unordered_map>
8
9namespace yaze {
10namespace editor {
11
21enum class PanelCategory {
25};
26
37enum class PanelContextScope : uint8_t {
38 kNone = 0,
39 kRoom,
41};
42
50enum class PanelScope {
53};
54
91 public:
92 virtual ~EditorPanel() = default;
93
94 // ==========================================================================
95 // Identity (Required)
96 // ==========================================================================
97
107 virtual std::string GetId() const = 0;
108
113 virtual std::string GetDisplayName() const = 0;
114
119 virtual std::string GetIcon() const = 0;
120
125 virtual std::string GetEditorCategory() const = 0;
126
127 // ==========================================================================
128 // Drawing (Required)
129 // ==========================================================================
130
139 virtual void Draw(bool* p_open) = 0;
140
141 // ==========================================================================
142 // Lifecycle Hooks (Optional)
143 // ==========================================================================
144
155 virtual void OnFirstDraw() {}
156
164 virtual bool RequiresLazyInit() const { return false; }
165
172 void InvalidateLazyInit(); // Implementation below private member
173
180 virtual void OnOpen() {}
181
188 virtual void OnClose() {}
189
195 virtual void OnFocus() {}
196
197 // ==========================================================================
198 // Behavior (Optional)
199 // ==========================================================================
200
209 }
210
217 }
218
225 virtual PanelScope GetScope() const { return PanelScope::kSession; }
226
234 virtual bool IsEnabled() const { return true; }
235
240 virtual std::string GetDisabledTooltip() const { return ""; }
241
246 virtual std::string GetShortcutHint() const { return ""; }
247
252 virtual int GetPriority() const { return 50; }
253
261 virtual float GetPreferredWidth() const { return 0.0f; }
262
270 virtual bool IsVisibleByDefault() const { return false; }
271
272 // ==========================================================================
273 // Relationships (Optional)
274 // ==========================================================================
275
283 virtual std::string GetParentPanelId() const { return ""; }
284
291 virtual bool CascadeCloseChildren() const { return false; }
292
293 // ==========================================================================
294 // Internal State (Managed by PanelManager)
295 // ==========================================================================
296
303 void DrawWithLazyInit(bool* p_open) {
305 OnFirstDraw();
306 lazy_init_done_ = true;
307 }
308 Draw(p_open);
309 }
310
311 protected:
312 // ==========================================================================
313 // Caching Infrastructure (For Derived Panels)
314 // ==========================================================================
315
325 void InvalidateCache() { cache_valid_ = false; }
326
347 template <typename T>
348 T& GetCached(const std::string& key, std::function<T()> compute) {
349 if (!cache_valid_ || cache_.find(key) == cache_.end()) {
350 cache_[key] = compute();
351 cache_valid_ = true; // Mark valid after first successful computation
352 }
353 return std::any_cast<T&>(cache_[key]);
354 }
355
360 bool IsCacheValid() const { return cache_valid_; }
361
369 void ClearCache() {
370 cache_.clear();
371 cache_valid_ = false;
372 }
373
374 private:
375 bool lazy_init_done_ = false;
376
377 // Cache infrastructure
378 bool cache_valid_ = false;
379 std::unordered_map<std::string, std::any> cache_;
380};
381
382// Inline implementation (requires private member to be declared first)
384
385} // namespace editor
386} // namespace yaze
387
388#endif // YAZE_APP_EDITOR_SYSTEM_EDITOR_PANEL_H_
Base interface for all logical panel components.
void InvalidateLazyInit()
Reset lazy init state so OnFirstDraw() runs again.
virtual void OnClose()
Called when panel is hidden.
virtual std::string GetId() const =0
Unique identifier for this panel.
bool IsCacheValid() const
Check if cache has been invalidated.
virtual bool CascadeCloseChildren() const
Whether closing this panel should close child panels.
virtual bool RequiresLazyInit() const
Whether this panel uses lazy initialization.
virtual bool IsVisibleByDefault() const
Whether this panel should be visible by default.
T & GetCached(const std::string &key, std::function< T()> compute)
Get or compute a cached value.
virtual std::string GetIcon() const =0
Material Design icon for this panel.
virtual ~EditorPanel()=default
void DrawWithLazyInit(bool *p_open)
Execute lazy initialization if needed, then call Draw()
virtual float GetPreferredWidth() const
Get preferred width for this panel (optional)
void ClearCache()
Clear all cached values (more aggressive than InvalidateCache)
void InvalidateCache()
Invalidate all cached computations.
virtual void OnFocus()
Called when panel receives focus.
virtual PanelScope GetScope() const
Get the registration scope for this panel.
virtual std::string GetDisabledTooltip() const
Get tooltip text when panel is disabled.
virtual int GetPriority() const
Get display priority for menu ordering.
virtual std::string GetShortcutHint() const
Get keyboard shortcut hint for display.
virtual std::string GetDisplayName() const =0
Human-readable name shown in menus and title bars.
virtual std::string GetParentPanelId() const
Get parent panel ID for cascade behavior.
virtual PanelContextScope GetContextScope() const
Optional context binding for this panel (room/selection/etc)
virtual PanelCategory GetPanelCategory() const
Get the lifecycle category for this panel.
virtual void OnFirstDraw()
Called once before the first Draw() in a session.
virtual void Draw(bool *p_open)=0
Draw the panel content.
std::unordered_map< std::string, std::any > cache_
virtual std::string GetEditorCategory() const =0
Editor category this panel belongs to.
virtual bool IsEnabled() const
Check if this panel is currently enabled.
virtual void OnOpen()
Called when panel becomes visible.
PanelCategory
Defines lifecycle behavior for editor panels.
@ Persistent
Always visible once shown.
@ EditorBound
Hidden when switching editors (default)
@ CrossEditor
User can pin to persist across editors.
PanelScope
Defines whether a panel is session-scoped or global.
PanelContextScope
Optional context binding for a panel's behavior within an editor.