Polyphase Game Engine
Loading...
Searching...
No Matches
EditorWidgets.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include "EngineTypes.h" // PropertyOwnerType, TypeId
6#include "imgui.h"
7
8#include <cstdint>
9
10class AssetRef;
11class Object;
12
13namespace Polyphase
14{
15 // Default visual size (in pixels) for editor checkboxes. Matches the Scene
16 // Inspector "Active" toggle button so checkboxes feel consistent across the
17 // editor regardless of the active theme's FramePadding. Themes may override
18 // this at theme-apply time (see EditorTheme.cpp / CssThemeParser.cpp).
19 extern float gCheckboxSize;
20
21 // Drop-in replacement for ImGui::Checkbox that constrains the frame height
22 // to gCheckboxSize for the duration of the call. All theming (checkmark
23 // color, hover, active, rounding) is preserved.
24 bool Checkbox(const char* label, bool* v);
25
26 // ---------------------------------------------------------------------
27 // Unified asset-reference picker
28 // ---------------------------------------------------------------------
29 //
30 // One widget for every "drop / pick / clear an Asset here" affordance in
31 // the editor. Renders, left-to-right:
32 //
33 // [Browse] [autocomplete InputText] [X clear] [Inspect] [Reveal]
34 //
35 // The hand-rolled drop targets that used to live in InputPromptMap,
36 // PaintManager, MaterialEditor, etc., each lost or kept different subsets
37 // of those buttons — this widget unifies them. Each affordance can be
38 // suppressed via a flag for compact table cells.
39 //
40 // `ref` is read AND written by the widget. When `undo != nullptr` and the
41 // owner is a Node or Asset, the assignment is routed through
42 // ActionManager so Ctrl+Z restores the previous reference; otherwise the
43 // AssetRef is mutated directly. Callers that have no Property/owner
44 // (custom panels) simply pass `undo = nullptr`.
45 //
46 // `typeFilter` is a TypeId — pass `Texture::GetStaticType()` to constrain
47 // the picker to textures, `0` to allow any asset. Material polymorphism
48 // (Material accepts MaterialBase / MaterialInstance / MaterialLite) is
49 // handled internally.
50 //
51 // Returns true on the frame the AssetRef changed.
52 enum AssetPickerFlags_ : uint32_t
53 {
54 AssetPickerFlags_None = 0,
55 AssetPickerFlags_NoAutocomplete = 1 << 0, // hide InputText + dropdown — use a labelled button slot instead
56 AssetPickerFlags_NoBrowse = 1 << 1, // hide Download/Upload/Info modifier button + hover-delete shortcut
57 AssetPickerFlags_NoInspect = 1 << 2,
58 AssetPickerFlags_NoReveal = 1 << 3,
59 AssetPickerFlags_NoDragDrop = 1 << 4,
60 AssetPickerFlags_NoColorTint = 1 << 5,
61 };
62 using AssetPickerFlags = uint32_t;
63
64 // Optional undo wrapping. When supplied, the widget routes the assignment
65 // through ActionManager::EXE_EditPropertyOnSelection — mirrors what the
66 // inspector's DrawAssetProperty does for Node / Asset owners. Hand-rolled
67 // call sites (no Property context) pass nullptr and the widget mutates
68 // the AssetRef directly.
69 struct AssetPickerUndoCtx
70 {
71 Object* mOwner = nullptr;
73 const char* mPropName = nullptr;
74 uint32_t mIndex = 0;
75 };
76
77 bool AssetRefPicker(const char* label,
78 AssetRef& ref,
79 TypeId typeFilter = 0,
80 AssetPickerFlags flags = 0,
81 const AssetPickerUndoCtx* undo = nullptr);
82}
83
84#endif
PropertyOwnerType
Definition EngineTypes.h:155
uint32_t TypeId
Definition EngineTypes.h:71
Definition AssetRef.h:18
Definition Object.h:13