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
|
#if defined(Hiro_NameDialog)
NameDialog::NameDialog() {
layout.setPadding(5_sx, 5_sy);
typeIcon.setCollapsible();
nameValue.onActivate([&] { acceptButton.doActivate(); });
acceptButton.onActivate([&] {
response = nameValue.text();
window.doClose();
});
cancelButton.setText("Cancel").onActivate([&] { window.doClose(); });
window.onClose([&] {
window.setModal(false);
window.setVisible(false);
});
window.setDismissable();
}
auto NameDialog::create(string name) -> string {
return show("Create", name);
}
auto NameDialog::rename(string name) -> string {
return show("Rename", name);
}
auto NameDialog::setAlignment(Alignment alignment) -> type& {
state.alignment = alignment;
state.relativeTo = {};
return *this;
}
auto NameDialog::setAlignment(sWindow relativeTo, Alignment alignment) -> type& {
state.alignment = alignment;
state.relativeTo = relativeTo;
return *this;
}
auto NameDialog::setIcon(const multiFactorImage& icon) -> type& {
state.icon = icon;
return *this;
}
auto NameDialog::setText(const string& text) -> type& {
state.text = text;
return *this;
}
auto NameDialog::setTitle(const string& title) -> type& {
state.title = title;
return *this;
}
auto NameDialog::show(string mode, string name) -> string {
response = {};
setTitle(state.title);
if(!state.title && mode == "Create") setTitle("Create");
if(!state.title && mode == "Rename") setTitle({"Rename ", name});
textLabel.setText(state.text ? state.text : "Enter a name:");
if(state.icon) {
image icon{state.icon};
icon.scale(16_sx, 16_sy);
typeIcon.setIcon(icon);
} else {
typeIcon.setVisible(false);
}
nameValue.setText(name);
acceptButton.setText(mode);
window.setTitle(state.title);
window.setSize({400_sx, layout.minimumSize().height()});
window.setAlignment(state.relativeTo, state.alignment);
window.setVisible();
nameValue.setFocused();
window.setModal();
return response;
}
#endif
|