From 5894a303dde5dd0ae760a3c25d71cde053f84be2 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sat, 12 Nov 2022 16:33:16 +0900 Subject: [PATCH] implement `init` event on System/Event --- file/system_event.cc | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/file/system_event.cc b/file/system_event.cc index 5905fd1..ecdba73 100644 --- a/file/system_event.cc +++ b/file/system_event.cc @@ -48,6 +48,7 @@ class Event final : public nf7::FileBase, nf7::File::Path handler; // feature switch + bool init = false; bool key = false; bool mouse = false; @@ -55,7 +56,7 @@ class Event final : public nf7::FileBase, Data() noexcept { } void serialize(auto& ar) { - ar(handler, key, mouse, watch); + ar(handler, init, key, mouse, watch); } std::string Stringify() const noexcept { @@ -65,6 +66,8 @@ class Event final : public nf7::FileBase, st << YAML::Value << handler; st << YAML::Key << "event"; st << YAML::BeginMap; + st << YAML::Key << "init"; + st << YAML::Value << init; st << YAML::Key << "key"; st << YAML::Value << key; st << YAML::Key << "mouse"; @@ -82,6 +85,7 @@ class Event final : public nf7::FileBase, d.handler = yaml["handler"].as(); const auto& ev = yaml["event"]; + d.init = ev["init"].as(); d.key = ev["key"].as(); d.mouse = ev["mouse"].as(); d.watch = ev["watch"].as>(); @@ -111,6 +115,24 @@ class Event final : public nf7::FileBase, return std::make_unique(env, Data {mem_.data()}); } + void PostHandle(const nf7::File::Event& e) noexcept override { + switch (e.type) { + case nf7::File::Event::kAdd: + if (mem_->init) { + env().ExecMain( + std::make_shared(*this, "trigger init event"), + [this]() { + if (auto la = CreateLambdaIf()) { + la->Handle("init", nf7::Value::Pulse {}, la_root_); + } + }); + } + return; + default: + return; + } + } + void PostUpdate() noexcept override; void UpdateMenu() noexcept override; void UpdateTooltip() noexcept override; @@ -230,6 +252,9 @@ void Event::UpdateMenu() noexcept { void Event::UpdateTooltip() noexcept { ImGui::Text("handler: %s", mem_->handler.Stringify().c_str()); ImGui::Text("events :"); + if (mem_->init) { + ImGui::Bullet(); ImGui::TextUnformatted("init"); + } if (mem_->key) { ImGui::Bullet(); ImGui::TextUnformatted("key"); }