replace nf7::gui::Config to nf7::gui::ConfigEditor
This commit is contained in:
parent
2ec4422c56
commit
0d60b2401a
@ -87,7 +87,6 @@ target_sources(nf7
|
||||
common/gl_shader_preproc.hh
|
||||
common/gui.hh
|
||||
common/gui.cc
|
||||
common/gui_config.hh
|
||||
common/gui_dnd.hh
|
||||
common/gui_timeline.hh
|
||||
common/gui_timeline.cc
|
||||
|
@ -133,4 +133,39 @@ void NodeOutputSockets(std::span<const std::string> names) noexcept {
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
|
||||
void ConfigEditor::operator()(nf7::Config& config) noexcept {
|
||||
if (ImGui::IsWindowAppearing()) {
|
||||
text_ = config.Stringify();
|
||||
msg_ = "";
|
||||
mod_ = false;
|
||||
}
|
||||
|
||||
mod_ |= ImGui::InputTextMultiline("##config", &text_);
|
||||
|
||||
ImGui::BeginDisabled(!mod_);
|
||||
if (ImGui::Button("apply")) {
|
||||
try {
|
||||
config.Parse(text_);
|
||||
msg_ = "";
|
||||
mod_ = false;
|
||||
} catch (nf7::Exception& e) {
|
||||
msg_ = e.msg();
|
||||
} catch (std::exception& e) {
|
||||
msg_ = e.what();
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("restore")) {
|
||||
text_ = config.Stringify();
|
||||
msg_ = "";
|
||||
mod_ = false;
|
||||
}
|
||||
|
||||
if (msg_.size()) {
|
||||
ImGui::Bullet();
|
||||
ImGui::TextUnformatted(msg_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nf7::gui
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "nf7.hh"
|
||||
|
||||
#include "common/config.hh"
|
||||
|
||||
|
||||
namespace nf7::gui {
|
||||
|
||||
@ -18,6 +20,16 @@ void NodeSocket() noexcept;
|
||||
void NodeInputSockets(std::span<const std::string>) noexcept;
|
||||
void NodeOutputSockets(std::span<const std::string>) noexcept;
|
||||
|
||||
struct ConfigEditor {
|
||||
public:
|
||||
void operator()(nf7::Config&) noexcept;
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
std::string msg_;
|
||||
bool mod_;
|
||||
};
|
||||
|
||||
|
||||
// stringify utility
|
||||
inline std::string GetContextDisplayName(const nf7::Context& ctx) noexcept {
|
||||
|
@ -1,61 +0,0 @@
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_stdlib.h>
|
||||
|
||||
#include "nf7.hh"
|
||||
|
||||
#include "common/generic_memento.hh"
|
||||
|
||||
|
||||
namespace nf7::gui {
|
||||
|
||||
template <typename T>
|
||||
concept ConfigData = requires (T& x) {
|
||||
{ x.Stringify() } -> std::convertible_to<std::string>;
|
||||
x.Parse(std::string {});
|
||||
};
|
||||
|
||||
template <ConfigData T>
|
||||
void Config(nf7::GenericMemento<T>& mem) noexcept {
|
||||
static std::string text_;
|
||||
static std::string msg_;
|
||||
static bool mod_;
|
||||
|
||||
if (ImGui::IsWindowAppearing()) {
|
||||
text_ = mem->Stringify();
|
||||
msg_ = "";
|
||||
mod_ = false;
|
||||
}
|
||||
|
||||
mod_ |= ImGui::InputTextMultiline("##config", &text_);
|
||||
|
||||
ImGui::BeginDisabled(!mod_);
|
||||
if (ImGui::Button("apply")) {
|
||||
try {
|
||||
mem->Parse(text_);
|
||||
mem.Commit();
|
||||
msg_ = "";
|
||||
mod_ = false;
|
||||
} catch (nf7::Exception& e) {
|
||||
msg_ = e.msg();
|
||||
} catch (std::exception& e) {
|
||||
msg_ = e.what();
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("restore")) {
|
||||
text_ = mem->Stringify();
|
||||
msg_ = "";
|
||||
mod_ = false;
|
||||
}
|
||||
|
||||
if (msg_.size()) {
|
||||
ImGui::Bullet();
|
||||
ImGui::TextUnformatted(msg_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nf7::gui
|
@ -30,7 +30,7 @@
|
||||
#include "common/generic_context.hh"
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger_ref.hh"
|
||||
#include "common/node.hh"
|
||||
@ -403,7 +403,8 @@ try {
|
||||
|
||||
void Device::UpdateMenu() noexcept {
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::MenuItem("build")) {
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "common/generic_config.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger_ref.hh"
|
||||
#include "common/memento.hh"
|
||||
@ -231,7 +231,8 @@ void FontFace::UpdateMenu() noexcept {
|
||||
Create();
|
||||
}
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include "common/gl_fence.hh"
|
||||
#include "common/gl_obj.hh"
|
||||
#include "common/gl_shader_preproc.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/gui_window.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger_ref.hh"
|
||||
@ -194,11 +194,10 @@ class ObjBase : public nf7::FileBase,
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("these actions can cause CORRUPTION of running lambdas");
|
||||
}
|
||||
if constexpr (nf7::gui::ConfigData<T>) {
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if constexpr (HasWindow<T>) {
|
||||
ImGui::Separator();
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger_ref.hh"
|
||||
#include "common/luajit_nfile_importer.hh"
|
||||
@ -65,7 +64,7 @@ class Node final : public nf7::FileBase,
|
||||
Node(nf7::Env& env, Data&& data = {}) noexcept :
|
||||
nf7::FileBase(kType, env),
|
||||
nf7::GenericConfig(mem_),
|
||||
nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kWidget),
|
||||
nf7::DirItem(nf7::DirItem::kMenu),
|
||||
nf7::Node(nf7::Node::kCustomNode),
|
||||
life_(*this),
|
||||
log_(std::make_shared<nf7::LoggerRef>(*this)),
|
||||
@ -103,7 +102,6 @@ class Node final : public nf7::FileBase,
|
||||
void Update() noexcept override;
|
||||
void UpdateMenu() noexcept override;
|
||||
void UpdateNode(nf7::Node::Editor&) noexcept override;
|
||||
void UpdateWidget() noexcept override;
|
||||
|
||||
File::Interface* interface(const std::type_info& t) noexcept override {
|
||||
return nf7::InterfaceSelector<
|
||||
@ -241,7 +239,8 @@ void Node::Update() noexcept {
|
||||
|
||||
void Node::UpdateMenu() noexcept {
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
@ -254,7 +253,8 @@ void Node::UpdateNode(nf7::Node::Editor&) noexcept {
|
||||
ImGui::OpenPopup("ConfigPopup");
|
||||
}
|
||||
if (ImGui::BeginPopup("ConfigPopup")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
@ -274,9 +274,6 @@ void Node::UpdateNode(nf7::Node::Editor&) noexcept {
|
||||
ImGui::SameLine();
|
||||
nf7::gui::NodeOutputSockets(mem_->outputs);
|
||||
}
|
||||
void Node::UpdateWidget() noexcept {
|
||||
nf7::gui::Config(mem_);
|
||||
}
|
||||
|
||||
|
||||
std::string Node::Data::Stringify() const noexcept {
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui_window.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/memento.hh"
|
||||
@ -1182,8 +1181,10 @@ void Network::ItemAdder(const ImVec2& pos) noexcept {
|
||||
}
|
||||
|
||||
void Network::Config() noexcept {
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
|
||||
auto ptag = mem_.Save();
|
||||
nf7::gui::Config(mem_);
|
||||
ed(*this);
|
||||
auto tag = mem_.Save();
|
||||
|
||||
if (ptag != tag) {
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger.hh"
|
||||
#include "common/logger_ref.hh"
|
||||
@ -207,7 +206,8 @@ void Event::UpdateMenu() noexcept {
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "common/generic_config.hh"
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/gui_window.hh"
|
||||
#include "common/ptr_selector.hh"
|
||||
#include "common/util_algorithm.hh"
|
||||
@ -156,7 +156,8 @@ void ImGui_::UpdateMenu() noexcept {
|
||||
}
|
||||
}
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "common/generic_context.hh"
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/gui_window.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger.hh"
|
||||
@ -280,7 +280,8 @@ class Logger final : public nf7::FileBase,
|
||||
|
||||
void Logger::UpdateMenu() noexcept {
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "common/generic_context.hh"
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/life.hh"
|
||||
#include "common/logger_ref.hh"
|
||||
#include "common/mutex.hh"
|
||||
@ -277,7 +277,8 @@ std::shared_ptr<nf7::Node::Lambda> NFile::CreateLambda(
|
||||
|
||||
void NFile::UpdateMenu() noexcept {
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "common/generic_config.hh"
|
||||
#include "common/generic_memento.hh"
|
||||
#include "common/generic_type_info.hh"
|
||||
#include "common/gui_config.hh"
|
||||
#include "common/gui.hh"
|
||||
#include "common/gui_window.hh"
|
||||
#include "common/life.hh"
|
||||
@ -40,6 +39,7 @@ namespace nf7 {
|
||||
namespace {
|
||||
|
||||
class Plot final : public nf7::FileBase,
|
||||
public nf7::GenericConfig,
|
||||
public nf7::DirItem,
|
||||
public nf7::Node {
|
||||
public:
|
||||
@ -244,7 +244,8 @@ void Plot::UpdateMenu() noexcept {
|
||||
win_.MenuItem();
|
||||
|
||||
if (ImGui::BeginMenu("config")) {
|
||||
nf7::gui::Config(mem_);
|
||||
static nf7::gui::ConfigEditor ed;
|
||||
ed(*this);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user