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.windows.paramprop;
8 import creator.windows;
9 import creator.widgets;
10 import creator.core;
11 import std.string;
12 import creator.utils.link;
13 import i18n;
14 import inochi2d;
15 
16 class ParamPropWindow : Window {
17 private:
18     Parameter param;
19 
20 protected:
21     override
22     void onBeginUpdate() {
23         flags |= ImGuiWindowFlags.NoResize;
24         igSetNextWindowSize(ImVec2(384, 192), ImGuiCond.Appearing);
25         igSetNextWindowSizeConstraints(ImVec2(384, 192), ImVec2(float.max, float.max));
26         super.onBeginUpdate();
27     }
28 
29     override
30     void onUpdate() {
31         igPushID(cast(void*)param);
32             if (igBeginChild("###MainSettings", ImVec2(0, -28))) {
33                 igText(__("Parameter Name"));
34                 igIndent();
35                     if (incInputText("Name", param.name)) {
36                         param.makeIndexable();
37                     }
38                 igUnindent();
39 
40                 igText(__("Parameter Constraints"));
41                 igIndent();
42                     igSetNextItemWidth(256);
43 
44                     if (param.isVec2) igText("X");
45                     if (param.isVec2) igIndent();
46                         
47                         // X MINIMUM
48                         igSetNextItemWidth(64);
49                         igPushID(0);
50                                 incDragFloat("adj_x_min", &param.min.vector[0], 1, -float.max, param.max.x-1, "%.2f", ImGuiSliderFlags.NoRoundToFormat);
51                         igPopID();
52 
53                         igSameLine(0, 4);
54 
55                         // X MAXIUMUM
56                         igSetNextItemWidth(64);
57                         igPushID(1);
58                             incDragFloat("adj_x_max", &param.max.vector[0], 1, param.min.x+1, float.max, "%.2f", ImGuiSliderFlags.NoRoundToFormat);
59                         igPopID();
60                     if (param.isVec2) igUnindent();
61                         
62                     if (param.isVec2) {
63 
64                         igText("Y");
65 
66                         igIndent();
67 
68                             // Y MINIMUM
69                             igSetNextItemWidth(64);
70                             igPushID(2);
71                                 incDragFloat("adj_y_min", &param.min.vector[1], 1, -float.max, param.min.y-1, "%.2f", ImGuiSliderFlags.NoRoundToFormat);
72                             igPopID();
73 
74                             igSameLine(0, 4);
75 
76                             // Y Maximum
77                             igSetNextItemWidth(64);
78                             igPushID(3);
79                                 incDragFloat("adj_y_max", &param.max.vector[1], 1, param.min.y+1, float.max, "%.2f", ImGuiSliderFlags.NoRoundToFormat);
80                             igPopID();
81                         igUnindent();
82                     }
83                 igUnindent();
84             }
85             igEndChild();
86 
87             if (igBeginChild("###SettingsBtns", ImVec2(0, 0))) {
88                 incDummy(ImVec2(-64, 0));
89                 igSameLine(0, 0);
90 
91                 // Settings are autosaved, but in case the user
92                 // feels more safe with a save button then we have
93                 // it here.
94                 if (igButton(__("Save"), ImVec2(64, 24))) {
95                     this.close();
96                 }
97             }
98             igEndChild();
99 
100         igPopID();
101     }
102 
103 public:
104     this(ref Parameter param) {
105         this.param = param;
106 
107         // Title for the parameter properties window.
108         super(_("Parameter Properties"));
109     }
110 }