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#include <utility>
10
11namespace yaze {
12namespace editor {
13
26enum class WindowLifecycle {
29};
30
41enum class WindowContextScope : uint8_t {
42 kNone = 0,
43 kRoom,
45};
46
55
82
83enum class WindowDefaultHost : uint8_t {
86};
87
89 switch (role) {
91 return "CoreWorkspace";
93 return "EmbeddedTool";
95 return "OptionalPopOut";
97 return "Diagnostic";
98 }
99 return "Unknown";
100}
101
106 bool allow_popout = true;
108 std::function<bool()> capability_condition;
109
114 bool declared = false;
115
120 std::string host;
121
122 bool IsAdmitted() const {
124 }
125
127 [[nodiscard]] WindowPresentationPolicy WithHost(std::string host_name) const {
128 WindowPresentationPolicy copy = *this;
129 copy.host = std::move(host_name);
130 return copy;
131 }
132
134 return {.role = WindowPresentationRole::kCoreWorkspace, .declared = true};
135 }
136
138 std::string capability = std::string()) {
139 return {
141 .default_host = WindowDefaultHost::kEmbedded,
142 .list_in_window_browser = false,
143 .allow_popout = true,
144 .required_capability = std::move(capability),
145 .declared = true,
146 };
147 }
148
150 return {.role = WindowPresentationRole::kOptionalPopOut, .declared = true};
151 }
152
154 return {
156 .default_host = WindowDefaultHost::kEmbedded,
157 .list_in_window_browser = false,
158 .allow_popout = true,
159 .declared = true,
160 };
161 }
162};
163
200 public:
201 virtual ~WindowContent() = default;
202
203 // ==========================================================================
204 // Identity (Required)
205 // ==========================================================================
206
216 virtual std::string GetId() const = 0;
217
222 virtual std::string GetDisplayName() const = 0;
223
228 virtual std::string GetIcon() const = 0;
229
234 virtual std::string GetEditorCategory() const = 0;
235
236 // ==========================================================================
237 // Drawing (Required)
238 // ==========================================================================
239
248 virtual void Draw(bool* p_open) = 0;
249
250 // ==========================================================================
251 // Lifecycle Hooks (Optional)
252 // ==========================================================================
253
264 virtual void OnFirstDraw() {}
265
273 virtual bool RequiresLazyInit() const { return false; }
274
281 void InvalidateLazyInit(); // Implementation below private member
282
289 virtual void OnOpen() {}
290
297 virtual void OnClose() {}
298
304 virtual void OnFocus() {}
305
306 // ==========================================================================
307 // Behavior (Optional)
308 // ==========================================================================
309
319
327
334 virtual WindowScope GetScope() const { return WindowScope::kSession; }
335
350
358 virtual bool IsEnabled() const { return true; }
359
364 virtual std::string GetDisabledTooltip() const { return ""; }
365
370 virtual std::string GetShortcutHint() const { return ""; }
371
376 virtual int GetPriority() const { return 50; }
377
382 virtual std::string GetWorkflowGroup() const { return ""; }
383
388 virtual std::string GetWorkflowLabel() const { return GetDisplayName(); }
389
393 virtual std::string GetWorkflowDescription() const { return ""; }
394
398 virtual int GetWorkflowPriority() const { return GetPriority(); }
399
407 virtual float GetPreferredWidth() const { return 0.0f; }
408
417 virtual bool HasExactPreferredWidth() const { return false; }
418
426 virtual float GetPreferredHeight() const { return 0.0f; }
427
429 virtual bool PrefersFloating() const { return false; }
430
439 virtual bool PreferAutoHideTabBar() const { return false; }
440
448 virtual bool IsVisibleByDefault() const { return false; }
449
450 // ==========================================================================
451 // Relationships (Optional)
452 // ==========================================================================
453
461 virtual std::string GetParentPanelId() const { return ""; }
462
469 virtual bool CascadeCloseChildren() const { return false; }
470
471 // ==========================================================================
472 // Internal State (Managed by WorkspaceWindowManager)
473 // ==========================================================================
474
481 void DrawWithLazyInit(bool* p_open) {
483 OnFirstDraw();
484 lazy_init_done_ = true;
485 }
486 Draw(p_open);
487 }
488
489 protected:
490 // ==========================================================================
491 // Caching Infrastructure (For Derived Panels)
492 // ==========================================================================
493
503 void InvalidateCache() { cache_valid_ = false; }
504
525 template <typename T>
526 T& GetCached(const std::string& key, std::function<T()> compute) {
527 if (!cache_valid_ || cache_.find(key) == cache_.end()) {
528 cache_[key] = compute();
529 cache_valid_ = true; // Mark valid after first successful computation
530 }
531 return std::any_cast<T&>(cache_[key]);
532 }
533
538 bool IsCacheValid() const { return cache_valid_; }
539
547 void ClearCache() {
548 cache_.clear();
549 cache_valid_ = false;
550 }
551
552 private:
553 bool lazy_init_done_ = false;
554
555 // Cache infrastructure
556 bool cache_valid_ = false;
557 std::unordered_map<std::string, std::any> cache_;
558};
559
560// Inline implementation (requires private member to be declared first)
562 lazy_init_done_ = false;
563}
564
565} // namespace editor
566} // namespace yaze
567
568#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 WindowPresentationPolicy GetPresentationPolicy() const
How this content is hosted and advertised by workspace chrome.
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 bool HasExactPreferredWidth() const
Whether GetPreferredWidth() is an exact content width.
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 bool PrefersFloating() const
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.
WindowPresentationRole
Product role for a registered workspace surface.
WindowScope
Defines whether a window is session-scoped or global.
const char * WindowPresentationRoleName(WindowPresentationRole role)
static WindowPresentationPolicy Diagnostic()
static WindowPresentationPolicy CoreWorkspace()
std::function< bool()> capability_condition
static WindowPresentationPolicy EmbeddedTool(std::string capability=std::string())
WindowPresentationPolicy WithHost(std::string host_name) const
Returns a copy that names the hosting surface.
static WindowPresentationPolicy OptionalPopOut()