File size: 18,441 Bytes
17f5b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
#pragma once
#include <vector>
#include <memory>
#include <optional>
#include <imgui.h>
#include "uicontext.h"
#include "binding_property.h"
#include "imrad.h"
#include "IconsFontAwesome6.h"


struct PreparedString
{
    std::string label;
    ImVec2 pos;
    std::vector<std::pair<size_t, size_t>> fmtArgs;
    bool error = false;
};
PreparedString PrepareString(std::string_view s);

#define DRAW_STR(a) PrepareString(a.value()).label.c_str()

void DrawTextArgs(const PreparedString& ps, UIContext& ctx, const ImVec2& offset = { 0, 0 }, const ImVec2& size = { 0, 0 }, const ImVec2& align = { 0, 0 });

void TreeNodeProp(const char* name, ImFont* font, const std::string& label, std::function<void()> f);

//----------------------------------------------------------

struct Widget;

struct UINode
{
    struct Prop {
        std::string_view name;
        property_base* property;
        bool kbdInput = false; //this property accepts keyboard input by default
    };
    enum SnapOptions {
        SnapSides = 0x1,
        SnapInterior = 0x2,
        SnapItemInterior = 0x4,
        SnapGrandparentClip = 0x8,
        NoContextMenu = 0x100,
        NoOverlayPos = 0x200,
        HasSizeX = 0x400,
        HasSizeY = 0x800,
    };

    UINode() {}
    UINode(const UINode&) {} //shallow copy
    virtual ~UINode() {}
    virtual void Draw(UIContext& ctx) = 0;
    virtual void DrawTools(UIContext& ctx) = 0;
    virtual void TreeUI(UIContext& ctx) = 0;
    virtual auto Properties()->std::vector<Prop> = 0;
    virtual auto Events()->std::vector<Prop> = 0;
    virtual bool PropertyUI(int, UIContext& ctx) = 0;
    virtual bool EventUI(int, UIContext& ctx) = 0;
    virtual void Export(std::ostream&, UIContext& ctx) = 0;
    virtual void Import(cpp::stmt_iterator& sit, UIContext& ctx) = 0;
    virtual int Behavior() = 0;
    virtual int ColumnCount(UIContext& ctx) = 0;
    virtual const UINode& Defaults() = 0;

    void DrawInteriorRect(UIContext& ctx);
    void DrawSnap(UIContext& ctx);
    auto UsedFieldVars() -> std::vector<std::string>;
    void RenameFieldVars(const std::string& oldn, const std::string& newn);
    auto FindChild(const UINode*) -> std::optional<std::pair<UINode*, int>>;
    auto FindInRect(const ImRect& r) -> std::vector<UINode*>;
    auto GetAllChildren() -> std::vector<UINode*>;
    void CloneChildrenFrom(const UINode& node, UIContext& ctx);
    void ResetLayout();
    virtual auto GetTypeName()->std::string;
    auto GetParentIndexes(UIContext& ctx)->std::string;
    void PushError(UIContext& ctx, const std::string& err);

    struct child_iterator;

    ImVec2 cached_pos;
    ImVec2 cached_size;
    std::vector<std::unique_ptr<Widget>> children;
    std::vector<ImRad::VBox> vbox;
    std::vector<ImRad::HBox> hbox;
};

//to iterate children matching a filter e.g. free-positioned or not
struct UINode::child_iterator
{
    using children_type = std::vector<std::unique_ptr<Widget>>;

    struct iter
    {
        iter();
        iter(children_type& ch, bool freePos);
        iter& operator++ ();
        iter operator++ (int);
        bool operator== (const iter& it) const;
        bool operator!= (const iter& it) const;
        children_type::value_type& operator* ();
        const children_type::value_type& operator* () const;
        size_t index() const;

    private:
        bool end() const;
        bool valid() const;

        size_t idx;
        children_type* children;
        bool freePos;
    };

    child_iterator(children_type& children, bool freePos);
    iter begin() const;
    iter end() const;
    explicit operator bool() const;

private:
    children_type& children;
    bool freePos;
};

//--------------------------------------------------------------------

struct Widget : UINode
{
    struct Layout
    {
        enum { Topmost = 0x1, Leftmost = 0x2, Bottommost = 0x4, HLayout = 0x10, VLayout = 0x20 };
        int flags = 0;
        int colId = 0;
        int rowId = 0;
        size_t index = 0;
    };

    direct_val<bool> sameLine = false;
    direct_val<int> nextColumn = 0;
    bindable<dimension_t> size_x = 0;
    bindable<dimension_t> size_y = 0;
    bindable<bool> visible;
    bindable<bool> disabled;
    bindable<std::string> tooltip = "";
    direct_val<std::string> contextMenu = "";
    direct_val<ImGuiMouseCursor_> cursor = ImGuiMouseCursor_Arrow;
    direct_val<bool> tabStop = true;
    direct_val<bool> initialFocus = false;
    bindable<bool> forceFocus;
    direct_val<ImRad::Alignment> hasPos = ImRad::AlignNone;
    bindable<dimension_t> pos_x = 0;
    bindable<dimension_t> pos_y = 0;
    direct_val<int> indent = 0;
    direct_val<int> spacing = 0;
    direct_val<bool> allowOverlap = false;

    //not shown by default
    data_loop itemCount;
    bindable<font_name_t> style_font;
    bindable<color_t> style_text;
    bindable<color_t> style_frameBg;
    bindable<color_t> style_border;
    bindable<color_t> style_button;
    bindable<color_t> style_buttonHovered;
    bindable<color_t> style_buttonActive;
    direct_val<pzdimension_t> style_frameRounding;
    direct_val<pzdimension2_t> style_framePadding;
    direct_val<pzdimension_t> style_frameBorderSize;
    direct_val<pzdimension2_t> style_interiorPadding;

    event<> onItemClicked;
    event<> onItemDoubleClicked;
    event<> onItemHovered;
    event<> onItemFocused;
    event<> onItemActivated;
    event<> onItemDeactivated;
    event<> onItemDeactivatedAfterEdit;
    event<> onItemContextMenuClicked;
    event<> onItemLongPressed; //not shown by default
    event<> onDragDropSource;
    event<> onDragDropTarget;

    std::string userCodeBefore, userCodeAfter;

    static std::unique_ptr<Widget> Create(const std::string& s, UIContext& ctx);

    Widget();
    void Draw(UIContext& ctx);
    void DrawTools(UIContext& ctx);
    void Export(std::ostream& os, UIContext& ctx);
    void Import(cpp::stmt_iterator& sit, UIContext& ctx);
    auto Properties() -> std::vector<Prop>;
    auto Events() -> std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    void TreeUI(UIContext& ctx);
    bool EventUI(int, UIContext& ctx);
    int Behavior();
    int ColumnCount(UIContext& ctx) { return 0; }
    const Widget& Defaults() = 0;
    Layout GetLayout(UINode* parent);
    virtual std::unique_ptr<Widget> Clone(UIContext& ctx) = 0;
    virtual ImDrawList* DoDraw(UIContext& ctx) = 0;
    virtual void DoDrawTools(UIContext& ctx) {}
    virtual void DoExport(std::ostream& os, UIContext& ctx) = 0;
    virtual void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx) = 0;
    virtual void CalcSizeEx(ImVec2 p1, UIContext& ctx);
    virtual const char* GetIcon() const { return ""; }
};

struct Spacer : Widget
{
    Spacer(UIContext&);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties()->std::vector<Prop>;
    bool PropertyUI(int, UIContext& ctx);
    void DoExport(std::ostream&, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX | HasSizeY; }
    const char* GetIcon() const { return ICON_FA_LEFT_RIGHT; }
    const Spacer& Defaults() { static Spacer var(UIContext::Defaults()); return var; }
};

struct Separator : Widget
{
    bindable<std::string> label;
    direct_val<pzdimension_t> style_thickness;
    direct_val<bool> style_outerPadding = true;

    Separator(UIContext&);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    void CalcSizeEx(ImVec2 p1, UIContext& ctx);
    auto Properties()->std::vector<Prop>;
    bool PropertyUI(int, UIContext& ctx);
    void DoExport(std::ostream&, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    const char* GetIcon() const { return ICON_FA_MINUS; }
    const Separator& Defaults() { static Separator var(UIContext::Defaults()); return var; }
};

struct Text : Widget
{
    bindable<std::string> text = "text";
    direct_val<bool> alignToFrame = false;
    direct_val<bool> wrap = false;
    direct_val<bool> link = false;
    event<> onChange;

    Text(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties() ->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    void CalcSizeEx(ImVec2 p1, UIContext& ctx);
    const char* GetIcon() const { return ICON_FA_FONT; }
    const Text& Defaults() { static Text var(UIContext::Defaults()); return var; }
};

struct Selectable : Widget
{
    bindable<std::string> label = "label";
    direct_val<ImGuiSelectableFlags_> flags = ImGuiSelectableFlags_NoAutoClosePopups;
    direct_val<ImRad::Alignment> horizAlignment = ImRad::AlignLeft;
    direct_val<ImRad::Alignment> vertAlignment = ImRad::AlignTop;
    direct_val<bool> alignToFrame = false;
    direct_val<bool> readOnly = false;
    direct_val<ImRad::ModalResult> modalResult = ImRad::None;
    bindable<bool> selected = false;
    bindable<color_t> style_header;
    event<> onChange;

    Selectable(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties() ->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    void CalcSizeEx(ImVec2 p1, UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX | HasSizeY | SnapItemInterior; }
    const char* GetIcon() const { return ICON_FA_AUDIO_DESCRIPTION; }
    const Selectable& Defaults() { static Selectable var(UIContext::Defaults()); return var; }
};

struct Button : Widget
{
    bindable<std::string> label = "OK";
    direct_val<ImGuiDir> arrowDir = ImGuiDir_None;
    direct_val<bool> small = false;
    direct_val<ImRad::ModalResult> modalResult = ImRad::None;
    direct_val<shortcut_t> shortcut = "";
    direct_val<std::string> dropDownMenu = "";
    event<> onChange;

    Button(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties() ->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events() ->std::vector<Prop>;
    bool EventUI(int, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior();
    const char* GetIcon() const { return ICON_FA_CIRCLE_PLAY; }
    const Button& Defaults() { static Button var(UIContext::Defaults()); return var; }
};

struct CheckBox : Widget
{
    bindable<std::string> label = "label";
    bindable<bool> checked;
    bindable<color_t> style_check;
    event<> onChange;

    CheckBox(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties() ->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    const char* GetIcon() const { return ICON_FA_SQUARE_CHECK; }
    const CheckBox& Defaults() { static CheckBox var(UIContext::Defaults()); return var; }
};

struct RadioButton : Widget
{
    bindable<std::string> label = "label";
    direct_val<int> valueID = 0;
    bindable<color_t> style_check;
    bindable<int> value;
    event<> onChange;

    RadioButton(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties() ->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    const char* GetIcon() const { return ICON_FA_CIRCLE_DOT; }
    const RadioButton& Defaults() { static RadioButton var(UIContext::Defaults()); return var; }
};

struct Input : Widget
{
    bindable<> value;
    direct_val<std::string> label = "";
    direct_val<int, true> type = 0;
    bindable<std::string> hint = "";
    direct_val<int> imeType = ImRad::ImeText;
    direct_val<float> step = 1;
    direct_val<std::string> format = "%.3f";
    direct_val<ImGuiInputTextFlags_> flags;
    event<> onChange;
    event<> onImeAction;
    event<int(ImGuiInputTextCallbackData&)> onCallback;

    static direct_val<ImRad::ImeType> _imeClass;
    static direct_val<ImRad::ImeType> _imeAction;

    Input(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties() ->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior();
    const char* GetIcon() const { return "|a_|"; }
    const Input& Defaults() { static Input var(UIContext::Defaults()); return var; }
};

struct Combo : Widget
{
    direct_val<std::string> label = "";
    bindable<> value; //don't use bindable<string> that would force format style edit
    bindable<std::vector<std::string>> items;
    direct_val<ImGuiComboFlags_> flags;
    event<> onChange;

    Combo(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties() ->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX; }
    const char* GetIcon() const { return ICON_FA_SQUARE_CARET_DOWN; }
    const Combo& Defaults() { static Combo var(UIContext::Defaults()); return var; }
};

struct Slider : Widget
{
    direct_val<ImGuiSliderFlags_> flags;
    direct_val<std::string> label = "";
    bindable<> value;
    direct_val<int, true> type = 0;
    direct_val<float> min = 0;
    direct_val<float> max = 1;
    direct_val<std::string> format = "";
    event<> onChange;

    Slider(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties()->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX; }
    const char* GetIcon() const { return ICON_FA_SLIDERS; }
    const Slider& Defaults() { static Slider var(UIContext::Defaults()); return var; }
};

struct ProgressBar : Widget
{
    direct_val<bool> indicator = true;
    bindable<float> value;
    bindable<color_t> style_color;

    ProgressBar(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties()->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX | HasSizeY; }
    const char* GetIcon() const { return ICON_FA_BATTERY_HALF; }
    const ProgressBar& Defaults() { static ProgressBar var(UIContext::Defaults()); return var; }
};

struct ColorEdit : Widget
{
    bindable<> value;
    direct_val<std::string> label = "";
    direct_val<std::string> type = "color3";
    direct_val<ImGuiColorEditFlags_> flags;
    event<> onChange;

    ColorEdit(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties()->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX; }
    const char* GetIcon() const { return ICON_FA_CIRCLE_HALF_STROKE; }
    const ColorEdit& Defaults() { static ColorEdit var(UIContext::Defaults()); return var; }
};

struct Image : Widget
{
    bindable<std::string> fileName = "";
    bindable<ImRad::Texture> texture;
    enum StretchPolicy { None, Scale, FitIn, FitOut };
    direct_val<StretchPolicy> stretchPolicy = Scale;

    ImRad::Texture tex;

    Image(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties()->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    void RefreshTexture(UIContext& ctx);
    bool PickFileName(UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX | HasSizeY; }
    const char* GetIcon() const { return ICON_FA_IMAGE; }
    const Image& Defaults() { static Image var(UIContext::Defaults()); return var; }
};

struct CustomWidget : Widget
{
    event<void(const ImRad::CustomWidgetArgs&)> onDraw;

    CustomWidget(UIContext& ctx);
    auto Clone(UIContext& ctx)->std::unique_ptr<Widget>;
    ImDrawList* DoDraw(UIContext& ctx);
    auto Properties()->std::vector<Prop>;
    bool PropertyUI(int i, UIContext& ctx);
    auto Events()->std::vector<Prop>;
    bool EventUI(int i, UIContext& ctx);
    void DoExport(std::ostream& os, UIContext& ctx);
    void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
    int Behavior() { return Widget::Behavior() | HasSizeX | HasSizeY; }
    const char* GetIcon() const { return ICON_FA_EXPAND; }
    const CustomWidget& Defaults() { static CustomWidget var(UIContext::Defaults()); return var; }
};