1 /*
2     Copyright © 2020, Inochi2D Project
3     Distributed under the 2-Clause BSD License, see LICENSE file.
4     
5     Authors: Luna Nielsen
6 */
7 module creator.panels.actionhistory;
8 import creator.panels;
9 import bindbc.imgui;
10 import creator.core.actionstack;
11 import std.string;
12 import creator.widgets;
13 import std.format;
14 import i18n;
15 
16 /**
17     The logger panel
18 */
19 class ActionHistoryPanel : Panel {
20 private:
21 
22 protected:
23     override
24     void onUpdate() {
25 
26         igText("Undo History");
27         igSeparator();
28 
29         ImVec2 avail;
30         igGetContentRegionAvail(&avail);
31 
32         igBeginChild("##ActionList", ImVec2(0, avail.y-30));
33             if (incActionHistory().length > 0) {
34                 foreach(i, action; incActionHistory()) {
35                     igPushID(cast(int)i);
36                         if (i == 0) {
37                             igPushID("ASBEGIN");
38                                 if (igSelectable(action.describeUndo().toStringz, i <= cast(ptrdiff_t)incActionIndex())) {
39                                     incActionSetIndex(0);
40                                 }
41                             igPopID();
42                         }
43                         if (igSelectable(action.describe().toStringz, i+1 <= incActionIndex())) {
44                             incActionSetIndex(i+1);
45                         }
46                     igPopID();
47                 }
48             }
49         igEndChild();
50         
51 
52         igSeparator();
53         igSpacing();
54         if (igButton("Clear History", ImVec2(0, 0))) {
55             incActionClearHistory();
56         }
57         igSameLine(0, 0);
58 
59         // Ugly hack to please imgui
60         string count = (_("%d of %d")~"\0").format(incActionHistory().length, incActionGetUndoHistoryLength());
61         ImVec2 len = incMeasureString(count);
62         incDummy(ImVec2(-(len.x-8), 1));
63         igSameLine(0, 0);
64         igText(count.ptr);
65     }
66 
67 public:
68     this() {
69         super("History", _("History"), true);
70         flags |= ImGuiWindowFlags.NoScrollbar;
71     }
72 }
73 
74 /**
75     Generate logger frame
76 */
77 mixin incPanel!ActionHistoryPanel;
78 
79