1 /* 2 Copyright © 2022, Inochi2D Project 3 Distributed under the 2-Clause BSD License, see LICENSE file. 4 5 Authors: Luna Nielsen 6 */ 7 module creator.windows.rename; 8 import creator.widgets; 9 import creator.windows; 10 import creator.core; 11 import creator; 12 import std.string; 13 import creator.utils.link; 14 import inochi2d; 15 import i18n; 16 import std.stdio; 17 18 class RenameWindow : Window { 19 private: 20 string strcpy; 21 string* output; 22 23 void apply() { 24 *output = strcpy.dup; 25 this.close(); 26 } 27 28 protected: 29 override 30 void onBeginUpdate() { 31 enum WIDTH = 320; 32 enum HEIGHT = 120; 33 igSetNextWindowSize(ImVec2(WIDTH, HEIGHT), ImGuiCond.Appearing); 34 igSetNextWindowSizeConstraints(ImVec2(WIDTH, HEIGHT), ImVec2(float.max, HEIGHT)); 35 super.onBeginUpdate(); 36 } 37 38 override 39 void onUpdate() { 40 41 // Textbox 42 float doneLength = clamp(incMeasureString(_("Rename")).x, 64, float.max); 43 ImVec2 avail = incAvailableSpace(); 44 incDummy(ImVec2(0, avail.y/5)); 45 igIndent(16); 46 avail = incAvailableSpace(); 47 if (incInputText("RENAME", avail.x-16, strcpy, ImGuiInputTextFlags.EnterReturnsTrue)) { 48 this.apply(); 49 } 50 igUnindent(16); 51 52 // Done button 53 avail = incAvailableSpace(); 54 incDummy(ImVec2(0, -24)); 55 incDummy(ImVec2(avail.x-(doneLength+8), 20)); 56 igSameLine(0, 0); 57 if (igButton(__("Rename"), ImVec2(doneLength+8, 20))) { 58 this.apply(); 59 } 60 } 61 62 public: 63 this(ref string toRename) { 64 super(_("Rename %s...").format(toRename)); 65 66 output = &toRename; 67 68 // Add secret null terminator 69 strcpy = cast(string)(toRename.dup~"\0"); 70 strcpy = strcpy[0..$-1]; 71 } 72 }