paterns_menu: list and display paterns
This commit is contained in:
@@ -8,12 +8,17 @@
|
||||
|
||||
#include <paterns_menu.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <raylib.h>
|
||||
#include <rlImGui.h>
|
||||
|
||||
namespace gol {
|
||||
|
||||
PaternsMenu::PaternsMenu(std::shared_ptr<ctx> ctx): context_(ctx) {}
|
||||
|
||||
void PaternsMenu::Toogle() {
|
||||
is_open_ = !is_open_;
|
||||
}
|
||||
@@ -22,12 +27,45 @@ bool PaternsMenu::isOpen() {
|
||||
return is_open_;
|
||||
}
|
||||
|
||||
void PaternsMenu::refresh() {
|
||||
paterns_name_list_.clear();
|
||||
paterns_paths_list_.clear();
|
||||
auto paterns_path = context_->program_dir / "paterns";
|
||||
if (std::filesystem::exists(paterns_path) && std::filesystem::is_directory(paterns_path)) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(paterns_path)) {
|
||||
if (!std::filesystem::is_directory(entry) && entry.path().has_filename()) {
|
||||
paterns_paths_list_[entry.path().filename()] = entry.path();
|
||||
paterns_name_list_.push_back(entry.path().filename());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaternsMenu::loadPatern(std::string &path) {
|
||||
|
||||
}
|
||||
|
||||
void PaternsMenu::display() {
|
||||
if (is_open_) {
|
||||
ImGuiWindowFlags paterns_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize;
|
||||
ImGui::SetNextWindowSize(ImVec2(150, 200), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(200, 250), ImGuiCond_Always);
|
||||
ImGui::Begin("paterns", &is_open_, paterns_flags);
|
||||
ImGui::Button("refresh");
|
||||
for (auto patern_name: paterns_name_list_) {
|
||||
ImGui::PushID(patern_name.c_str());
|
||||
if (ImGui::Button(patern_name.c_str())) {
|
||||
loadPatern(paterns_paths_list_[patern_name]);
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - 57.);
|
||||
std::string del_id = patern_name.c_str();
|
||||
del_id.append("_del");
|
||||
ImGui::PushID(del_id.c_str());
|
||||
if (ImGui::Button("delete")) {
|
||||
std::filesystem::remove(paterns_paths_list_[patern_name]);
|
||||
refresh();
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user