enforce System/ImGui is updated prior than others

This commit is contained in:
falsycat 2022-11-05 23:21:02 +09:00
parent bb799adfb4
commit e8e0322e66
3 changed files with 32 additions and 5 deletions

View File

@ -16,6 +16,10 @@ class DirItem : public File::Interface {
kTooltip = 1 << 2,
kWidget = 1 << 3,
kDragDropTarget = 1 << 4,
// Update() will be called earlier than other items.
// This is used by some system files and meaningless in most of cases.
kEarlyUpdate = 1 << 5,
};
using Flags = uint8_t;

View File

@ -3,6 +3,7 @@
#include <string>
#include <string_view>
#include <unordered_set>
#include <vector>
#include <imgui.h>
#include <imgui_internal.h>
@ -148,6 +149,13 @@ class Dir final : public nf7::FileBase,
std::unordered_set<std::string> opened_;
static bool TestFlags(nf7::File& f, nf7::DirItem::Flags flags) noexcept
try {
return f.interfaceOrThrow<nf7::DirItem>().flags() & flags;
} catch (nf7::Exception&) {
return false;
}
std::string GetUniqueName(std::string_view name) const noexcept {
auto ret = std::string {name};
while (Find(ret)) {
@ -164,13 +172,28 @@ class Dir final : public nf7::FileBase,
};
void Dir::Update() noexcept {
// update children
// update children flagged as kEarlyUpdate
std::vector<nf7::File*> later;
later.reserve(items_.size());
for (const auto& item : items_) {
ImGui::PushID(item.second.get());
item.second->Update();
auto& f = *item.second;
if (TestFlags(f, nf7::DirItem::kEarlyUpdate)) {
ImGui::PushID(&f);
f.Update();
ImGui::PopID();
} else {
later.push_back(&f);
}
}
nf7::FileBase::Update();
// update children
for (auto f : later) {
ImGui::PushID(f);
f->Update();
ImGui::PopID();
}
nf7::FileBase::Update();
}
void Dir::UpdateTree() noexcept {
for (const auto& item : items_) {

View File

@ -29,7 +29,7 @@ class ImGui_ final : public nf7::File, public nf7::DirItem {
static inline const nf7::GenericTypeInfo<ImGui_> kType = {"System/ImGui", {}};
ImGui_(nf7::Env& env) noexcept :
nf7::File(kType, env), nf7::DirItem(nf7::DirItem::kNone) {
nf7::File(kType, env), nf7::DirItem(nf7::DirItem::kEarlyUpdate) {
}
ImGui_(nf7::Deserializer& ar) : ImGui_(ar.env()) {
std::string config;