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 <cstdint>
6#include <functional>
7#include <string>
8#include <unordered_map>
9
10namespace yaze {
11namespace editor {
12
25enum class WindowLifecycle {
28};
29
40enum class WindowContextScope : uint8_t {
41 kNone = 0,
42 kRoom,
44};
45
54
91 public:
92 virtual ~WindowContent() = 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
210
218
225 virtual WindowScope GetScope() const { return WindowScope::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
258 virtual std::string GetWorkflowGroup() const { return ""; }
259
264 virtual std::string GetWorkflowLabel() const { return GetDisplayName(); }
265
269 virtual std::string GetWorkflowDescription() const { return ""; }
270
274 virtual int GetWorkflowPriority() const { return GetPriority(); }
275
283 virtual float GetPreferredWidth() const { return 0.0f; }
284
292 virtual float GetPreferredHeight() const { return 0.0f; }
293
302 virtual bool PreferAutoHideTabBar() const { return false; }
303
311 virtual bool IsVisibleByDefault() const { return false; }
312
313 // ==========================================================================
314 // Relationships (Optional)
315 // ==========================================================================
316
324 virtual std::string GetParentPanelId() const { return ""; }
325
332 virtual bool CascadeCloseChildren() const { return false; }
333
334 // ==========================================================================
335 // Internal State (Managed by WorkspaceWindowManager)
336 // ==========================================================================
337
344 void DrawWithLazyInit(bool* p_open) {
346 OnFirstDraw();
347 lazy_init_done_ = true;
348 }
349 Draw(p_open);
350 }
351
352 protected:
353 // ==========================================================================
354 // Caching Infrastructure (For Derived Panels)
355 // ==========================================================================
356
366 void InvalidateCache() { cache_valid_ = false; }
367
388 template <typename T>
389 T& GetCached(const std::string& key, std::function<T()> compute) {
390 if (!cache_valid_ || cache_.find(key) == cache_.end()) {
391 cache_[key] = compute();
392 cache_valid_ = true; // Mark valid after first successful computation
393 }
394 return std::any_cast<T&>(cache_[key]);
395 }
396
401 bool IsCacheValid() const { return cache_valid_; }
402
410 void ClearCache() {
411 cache_.clear();
412 cache_valid_ = false;
413 }
414
415 private:
416 bool lazy_init_done_ = false;
417
418 // Cache infrastructure
419 bool cache_valid_ = false;
420 std::unordered_map<std::string, std::any> cache_;
421};
422
423// Inline implementation (requires private member to be declared first)
425 lazy_init_done_ = false;
426}
427
428} // namespace editor
429} // namespace yaze
430
431#endif // YAZE_APP_EDITOR_SYSTEM_EDITOR_PANEL_H_
Base interface for all logical window content components.
virtual bool IsEnabled() const
Check if this panel is currently enabled.
virtual std::string GetWorkflowDescription() const
Optional workflow description for menus/command palette.
bool IsCacheValid() const
Check if cache has been invalidated.
virtual bool CascadeCloseChildren() const
Whether closing this panel should close child panels.
virtual std::string GetParentPanelId() const
Get parent panel ID for cascade behavior.
virtual std::string GetDisabledTooltip() const
Get tooltip text when panel is disabled.
std::unordered_map< std::string, std::any > cache_
virtual int GetWorkflowPriority() const
Optional workflow ordering priority (lower sorts first).
virtual bool IsVisibleByDefault() const
Whether this panel should be visible by default.
virtual bool PreferAutoHideTabBar() const
Whether the dock node hosting this panel should auto-hide its tab bar.
virtual std::string GetDisplayName() const =0
Human-readable name shown in menus and title bars.
virtual WindowLifecycle GetWindowLifecycle() const
Get the lifecycle category for this window.
void InvalidateCache()
Invalidate all cached computations.
virtual void OnOpen()
Called when panel becomes visible.
virtual std::string GetEditorCategory() const =0
Editor category this panel belongs to.
virtual int GetPriority() const
Get display priority for menu ordering.
virtual void OnClose()
Called when panel is hidden.
virtual void OnFirstDraw()
Called once before the first Draw() in a session.
virtual WindowScope GetScope() const
Get the registration scope for this window.
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 float GetPreferredHeight() const
Get preferred height for this panel (optional)
virtual void OnFocus()
Called when panel receives focus.
virtual ~WindowContent()=default
virtual void Draw(bool *p_open)=0
Draw the panel content.
virtual float GetPreferredWidth() const
Get preferred width for this panel (optional)
virtual WindowContextScope GetContextScope() const
Optional context binding for this window (room/selection/etc)
virtual std::string GetWorkflowLabel() const
Optional workflow label for menus/command palette.
virtual bool RequiresLazyInit() const
Whether this panel uses lazy initialization.
void DrawWithLazyInit(bool *p_open)
Execute lazy initialization if needed, then call Draw()
virtual std::string GetId() const =0
Unique identifier for this panel.
virtual std::string GetWorkflowGroup() const
Optional workflow group for hack-centric actions.
void ClearCache()
Clear all cached values (more aggressive than InvalidateCache)
void InvalidateLazyInit()
Reset lazy init state so OnFirstDraw() runs again.
virtual std::string GetShortcutHint() const
Get keyboard shortcut hint for display.
WindowContextScope
Optional context binding for a window's behavior within an editor.
WindowLifecycle
Defines lifecycle behavior for editor windows.
@ EditorBound
Hidden when switching editors (default)
@ CrossEditor
User can pin to persist across editors.
WindowScope
Defines whether a window is session-scoped or global.