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
24enum class WindowLifecycle {
27};
28
39enum class WindowContextScope : uint8_t {
40 kNone = 0,
41 kRoom,
43};
44
53
90 public:
91 virtual ~WindowContent() = default;
92
93 // ==========================================================================
94 // Identity (Required)
95 // ==========================================================================
96
106 virtual std::string GetId() const = 0;
107
112 virtual std::string GetDisplayName() const = 0;
113
118 virtual std::string GetIcon() const = 0;
119
124 virtual std::string GetEditorCategory() const = 0;
125
126 // ==========================================================================
127 // Drawing (Required)
128 // ==========================================================================
129
138 virtual void Draw(bool* p_open) = 0;
139
140 // ==========================================================================
141 // Lifecycle Hooks (Optional)
142 // ==========================================================================
143
154 virtual void OnFirstDraw() {}
155
163 virtual bool RequiresLazyInit() const { return false; }
164
171 void InvalidateLazyInit(); // Implementation below private member
172
179 virtual void OnOpen() {}
180
187 virtual void OnClose() {}
188
194 virtual void OnFocus() {}
195
196 // ==========================================================================
197 // Behavior (Optional)
198 // ==========================================================================
199
209
217
224 virtual WindowScope GetScope() const { return WindowScope::kSession; }
225
233 virtual bool IsEnabled() const { return true; }
234
239 virtual std::string GetDisabledTooltip() const { return ""; }
240
245 virtual std::string GetShortcutHint() const { return ""; }
246
251 virtual int GetPriority() const { return 50; }
252
257 virtual std::string GetWorkflowGroup() const { return ""; }
258
263 virtual std::string GetWorkflowLabel() const { return GetDisplayName(); }
264
268 virtual std::string GetWorkflowDescription() const { return ""; }
269
273 virtual int GetWorkflowPriority() const { return GetPriority(); }
274
282 virtual float GetPreferredWidth() const { return 0.0f; }
283
292 virtual bool PreferAutoHideTabBar() const { return false; }
293
301 virtual bool IsVisibleByDefault() const { return false; }
302
303 // ==========================================================================
304 // Relationships (Optional)
305 // ==========================================================================
306
314 virtual std::string GetParentPanelId() const { return ""; }
315
322 virtual bool CascadeCloseChildren() const { return false; }
323
324 // ==========================================================================
325 // Internal State (Managed by WorkspaceWindowManager)
326 // ==========================================================================
327
334 void DrawWithLazyInit(bool* p_open) {
336 OnFirstDraw();
337 lazy_init_done_ = true;
338 }
339 Draw(p_open);
340 }
341
342 protected:
343 // ==========================================================================
344 // Caching Infrastructure (For Derived Panels)
345 // ==========================================================================
346
356 void InvalidateCache() { cache_valid_ = false; }
357
378 template <typename T>
379 T& GetCached(const std::string& key, std::function<T()> compute) {
380 if (!cache_valid_ || cache_.find(key) == cache_.end()) {
381 cache_[key] = compute();
382 cache_valid_ = true; // Mark valid after first successful computation
383 }
384 return std::any_cast<T&>(cache_[key]);
385 }
386
391 bool IsCacheValid() const { return cache_valid_; }
392
400 void ClearCache() {
401 cache_.clear();
402 cache_valid_ = false;
403 }
404
405 private:
406 bool lazy_init_done_ = false;
407
408 // Cache infrastructure
409 bool cache_valid_ = false;
410 std::unordered_map<std::string, std::any> cache_;
411};
412
413// Inline implementation (requires private member to be declared first)
415 lazy_init_done_ = false;
416}
417
418} // namespace editor
419} // namespace yaze
420
421#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 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.