[nostalgia] Cleanup frequent allocations and const correctness in project explorer
This commit is contained in:
parent
679226ef73
commit
2669aafe81
@ -32,7 +32,7 @@ class ProjectExplorer: public studio::Widget {
|
|||||||
|
|
||||||
// slots
|
// slots
|
||||||
public:
|
public:
|
||||||
ox::Signal<ox::Error(const ox::String&)> fileChosen;
|
ox::Signal<ox::Error(const ox::StringView&)> fileChosen;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -10,31 +10,37 @@
|
|||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
|
|
||||||
ProjectTreeModel::ProjectTreeModel(ProjectExplorer *explorer, ox::String name,
|
ProjectTreeModel::ProjectTreeModel(ProjectExplorer *explorer, ox::String name,
|
||||||
ProjectTreeModel *parent) noexcept {
|
ProjectTreeModel *parent) noexcept:
|
||||||
m_explorer = explorer;
|
m_explorer(explorer),
|
||||||
m_name = std::move(name);
|
m_parent(parent),
|
||||||
m_parent = parent;
|
m_name(std::move(name)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectTreeModel::ProjectTreeModel(ProjectTreeModel &&other) noexcept {
|
ProjectTreeModel::ProjectTreeModel(ProjectTreeModel &&other) noexcept:
|
||||||
m_name = std::move(other.m_name);
|
m_explorer(other.m_explorer),
|
||||||
m_children = std::move(other.m_children);
|
m_parent(other.m_parent),
|
||||||
|
m_name(std::move(other.m_name)),
|
||||||
|
m_children(std::move(other.m_children)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectTreeModel::draw(core::Context *ctx) noexcept {
|
void ProjectTreeModel::draw(core::Context *ctx) const noexcept {
|
||||||
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
if (!m_children.empty()) {
|
if (!m_children.empty()) {
|
||||||
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
||||||
for (auto &child : m_children) {
|
for (const auto &child : m_children) {
|
||||||
child->draw(ctx);
|
child->draw(ctx);
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
} else if (auto path = fullPath(); ImGui::TreeNodeEx(ox::sfmt("{}##{}", m_name, path).c_str(), ImGuiTreeNodeFlags_Leaf)) {
|
} else {
|
||||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
const auto path = fullPath();
|
||||||
m_explorer->fileChosen.emit(path);
|
const auto name = ox::sfmt<ox::BasicString<255>>("{}##{}", m_name, path);
|
||||||
|
if (ImGui::TreeNodeEx(name.c_str(), ImGuiTreeNodeFlags_Leaf)) {
|
||||||
|
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
||||||
|
m_explorer->fileChosen.emit(path);
|
||||||
|
}
|
||||||
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +48,9 @@ void ProjectTreeModel::setChildren(ox::Vector<ox::UniquePtr<ProjectTreeModel>> c
|
|||||||
m_children = std::move(children);
|
m_children = std::move(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::String ProjectTreeModel::fullPath() noexcept {
|
ox::BasicString<255> ProjectTreeModel::fullPath() const noexcept {
|
||||||
if (m_parent) {
|
if (m_parent) {
|
||||||
return m_parent->fullPath() + "/" + m_name;
|
return m_parent->fullPath() + "/" + ox::StringView(m_name);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,13 @@ class ProjectTreeModel {
|
|||||||
|
|
||||||
ProjectTreeModel(ProjectTreeModel &&other) noexcept;
|
ProjectTreeModel(ProjectTreeModel &&other) noexcept;
|
||||||
|
|
||||||
void draw(core::Context *ctx) noexcept;
|
void draw(core::Context *ctx) const noexcept;
|
||||||
|
|
||||||
void setChildren(ox::Vector<ox::UniquePtr<ProjectTreeModel>> children) noexcept;
|
void setChildren(ox::Vector<ox::UniquePtr<ProjectTreeModel>> children) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::String fullPath() noexcept;
|
ox::BasicString<255> fullPath() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user