add nf7::gui::ConfigPopup

This commit is contained in:
falsycat 2022-09-22 17:21:58 +09:00
parent 07b198f71e
commit e045e86b11
2 changed files with 52 additions and 0 deletions

View File

@ -45,4 +45,31 @@ void IOSocketListPopup::Update() noexcept {
}
}
void ConfigPopup::Update() noexcept {
if (nf7::gui::Popup::Begin()) {
ImGui::TextUnformatted(name());
ImGui::InputTextMultiline("##text", &text_);
if (ImGui::Button("apply")) {
try {
onApply(text_);
msg_ = "OK";
} catch (nf7::Exception& e) {
msg_ = e.msg();
}
}
ImGui::SameLine();
if (ImGui::Button("reset")) {
text_ = onOpen();
}
if (msg_.size()) {
ImGui::Bullet();
ImGui::TextUnformatted(msg_.c_str());
}
ImGui::EndPopup();
}
}
} // namespace nf7::gui

View File

@ -29,6 +29,8 @@ class Popup {
return ImGui::BeginPopup(name_, flags_);
}
const char* name() const noexcept { return name_; }
private:
const char* name_;
ImGuiWindowFlags flags_;
@ -36,6 +38,7 @@ class Popup {
std::optional<ImGuiPopupFlags> open_flags_;
};
class IOSocketListPopup final :
public nf7::FileBase::Feature, private Popup {
public:
@ -61,4 +64,26 @@ class IOSocketListPopup final :
std::string is_, os_;
};
class ConfigPopup final :
public nf7::FileBase::Feature, private Popup {
public:
ConfigPopup(const char* name = "ConfigPopup") noexcept : Popup(name) {
}
void Open() noexcept {
msg_ = "";
text_ = onOpen();
nf7::gui::Popup::Open();
}
void Update() noexcept override;
std::function<std::string()> onOpen;
std::function<void(const std::string&)> onApply;
private:
std::string msg_;
std::string text_;
};
} // namespace nf7::gui