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         incText(_("Undo History"));
27         igSeparator();
28 
29         ImVec2 avail;
30         igGetContentRegionAvail(&avail);
31 
32         if (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 
50         }
51         igEndChild();
52         
53 
54         igSeparator();
55         igSpacing();
56         if (igButton(__("Clear History"), ImVec2(0, 0))) {
57             incActionClearHistory();
58         }
59         igSameLine(0, 0);
60 
61         // Ugly hack to please imgui
62         string count = _("%d of %d").format(incActionHistory().length, incActionGetUndoHistoryLength());
63         ImVec2 len = incMeasureString(count);
64         incDummy(ImVec2(-len.x, 1));
65         igSameLine(0, 0);
66         incText(count);
67     }
68 
69 public:
70     this() {
71         super("History", _("History"), true);
72         flags |= ImGuiWindowFlags.NoScrollbar;
73     }
74 }
75 
76 /**
77     Generate logger frame
78 */
79 mixin incPanel!ActionHistoryPanel;
80 
81