From 3d6f90f0d9f8bb19438a8bdb9e97d4c4e1650c74 Mon Sep 17 00:00:00 2001 From: chatlanin Date: Sun, 5 Mar 2023 16:08:51 +0300 Subject: [PATCH] add event key code base --- src/rrr/content/file/file.cpp | 13 +++-- src/rrr/content/file/file.hpp | 24 +++++---- .../gui/browser/navigation/navigation.cpp | 54 +++++++++++++------ .../gui/browser/navigation/navigation.hpp | 4 ++ 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/rrr/content/file/file.cpp b/src/rrr/content/file/file.cpp index 1cdcdf8..83f81ad 100644 --- a/src/rrr/content/file/file.cpp +++ b/src/rrr/content/file/file.cpp @@ -2,11 +2,17 @@ namespace rrr { - file::file(std::filesystem::path path_, file_type type_, bool is_link_) : id { ++hack::utils::counter::id }, path { path_ }, type { type_ }, is_link { is_link_ } {} + file::file(std::filesystem::path path_, file_type type_, bool is_link_, bool is_hidden_) : + id{ ++hack::utils::counter::id }, path{ path_ }, type{ type_ }, is_link{ is_link_ }, is_hidden{ is_hidden_ } {} - file::file(file&& f) : id { ++hack::utils::counter::id }, path { std::move(f.path) }, type { std::move(f.type) }, is_link { std::move(f.is_link) }, is_mark { std::move(f.is_mark) } {} + file::file(file&& f) : + id{ ++hack::utils::counter::id }, path{ std::move(f.path) }, + type{ std::move(f.type) }, is_link{ std::move(f.is_link) }, + is_hidden{ std::move(f.is_hidden) }, is_mark{ std::move(f.is_mark) } {} - file::file(const file& f) : id { ++hack::utils::counter::id }, path { f.path }, type { f.type }, is_link { f.is_link }, is_mark { f.is_mark } {} + file::file(const file& f) : + id{ ++hack::utils::counter::id }, path{ f.path }, type{ f.type }, is_link{ f.is_link }, + is_hidden{ f.is_hidden }, is_mark{ f.is_mark } {} file& file::operator=(const file& other) { @@ -15,6 +21,7 @@ namespace rrr path = other.path; type = other.type; is_link = other.is_link; + is_hidden = other.is_hidden; is_mark = other.is_mark; id = ++hack::utils::counter::id ; return *this; diff --git a/src/rrr/content/file/file.hpp b/src/rrr/content/file/file.hpp index 67a7775..bc31769 100644 --- a/src/rrr/content/file/file.hpp +++ b/src/rrr/content/file/file.hpp @@ -23,7 +23,7 @@ namespace rrr { public: file() = default; - file(std::filesystem::path, file_type, bool); + file(std::filesystem::path, file_type, bool, bool); file(file&&); file(const file&); @@ -38,6 +38,7 @@ namespace rrr std::filesystem::path path; file_type type; bool is_link = false; + bool is_hidden = false; bool is_mark = false; }; } @@ -46,6 +47,14 @@ namespace rrr::file_utils { using files = std::vector; + inline bool is_hidden(const std::filesystem::path &p) + { + std::filesystem::path::string_type name = p.filename(); + if(name != ".." && name != "." && name[0] == '.') + return true; + return false; + } + struct filesystem_convert { file operator()(const std::filesystem::directory_entry& entry) const @@ -56,8 +65,9 @@ namespace rrr::file_utils type = file_type::DIR; auto is_link = std::filesystem::is_symlink(entry); + auto is_hidden = file_utils::is_hidden(entry); - return { entry.path(), type, is_link }; + return { entry.path(), type, is_link, is_hidden }; } }; @@ -73,7 +83,7 @@ namespace rrr::file_utils } catch(...) { - f.push_back({ path / "no permission", file_type::TEXT, false }); + f.push_back({ path / "no permission", file_type::TEXT, false, false }); } return f; @@ -109,12 +119,4 @@ namespace rrr::file_utils return tmp; } - - inline bool is_hidden(const std::filesystem::path &p) - { - std::filesystem::path::string_type name = p.filename(); - if(name != ".." && name != "." && name[0] == '.') - return true; - return false; - } } diff --git a/src/rrr/layers/gui/browser/navigation/navigation.cpp b/src/rrr/layers/gui/browser/navigation/navigation.cpp index ad794fc..13b4b45 100644 --- a/src/rrr/layers/gui/browser/navigation/navigation.cpp +++ b/src/rrr/layers/gui/browser/navigation/navigation.cpp @@ -1,5 +1,7 @@ #include "navigation.hpp" +#include "logger/logger.hpp" + namespace rrr::layers::gui { void navigation::on_attach() @@ -7,6 +9,7 @@ namespace rrr::layers::gui BASE_WINDOW_FLAGS(); data = cnt->get(TYPE_WIN::NAVIGATION); + font = try_engine::style::fonts::get_font(font_type::MEDIUM, 18); } void navigation::on_detach() @@ -19,44 +22,49 @@ namespace rrr::layers::gui ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y)); ImGui::SetNextWindowSize(ImVec2(width, height)); + ImGuiStyle& st = ImGui::GetStyle(); + st.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.14f, 0.18f, 1.00f); + + ImGui::PushFont(font); + BEGIN_IMGUI_WIN(); auto pos = ImGui::GetCursorPos(); - auto padding = -60.f; - const ImVec4 type_color = ImVec4(0.35f, 0.35f, 0.35f, 1.0f); - // HERE начинаем тут - // стилизуем ссылки - // делаем навигацию + int index = 0; for (auto& item : *data) { ImGui::PushID(item.id); - char buf[32]; - sprintf(buf, "##item_%d", item.id); + if (item.type == file_type::DIR) + ImGui::PushStyleColor(ImGuiCol_Text, dir_color); + else + ImGui::PushStyleColor(ImGuiCol_Text, file_color); - ImGui::SetCursorPos(ImVec2(pos.x, pos.y + padding)); - if (ImGui::Selectable(buf, item.id == selected, 0, ImVec2(width, 60))) - selected = item.id; - - font = atlas->Fonts[1]; - ImGui::PushFont(font); - ImGui::PushStyleColor(ImGuiCol_Text, type_color); + if (selected == index) + { + ImGui::TextUnformatted(">"); + ImGui::SameLine(22.f); + } + else + ImGui::SetCursorPosX(pos.x); ImGui::TextUnformatted(item.path.filename().string().data()); - pos.y += font->FontSize + 4.f; ImGui::PopStyleColor(); - ImGui::PopFont(); ImGui::PopID(); + ++index; } + ImGui::PopFont(); + + END_IMGUI_WIN(); } - void navigation::on_event(system_event& e) + void navigation::on_event(try_engine::system_event::event& e) { if (e.get_name() == try_engine::system_event::classificator::WINDOW_RESIZE()) { @@ -64,6 +72,18 @@ namespace rrr::layers::gui width = try_engine::application::get()->get_window()->width() / 3.f - padding_between_window; pos_x = try_engine::application::get()->get_window()->width() / 3.f + padding_between_window / 2.f; } + + // HERE начинаем тут + // нужно реализовать обработку клавишь + // и выннести это в движок тоже + + if (e.get_name() == try_engine::system_event::classificator::KEY_PRESSED()) + { + auto key = static_cast(e); + hack::log()(key.get_keycode()); + } + + hack::log()(e.get_name()); } void navigation::on_event(std::any e, std::any value) diff --git a/src/rrr/layers/gui/browser/navigation/navigation.hpp b/src/rrr/layers/gui/browser/navigation/navigation.hpp index 9b48fd5..0261e0e 100644 --- a/src/rrr/layers/gui/browser/navigation/navigation.hpp +++ b/src/rrr/layers/gui/browser/navigation/navigation.hpp @@ -7,6 +7,8 @@ namespace rrr::layers::gui { class navigation : public try_engine::layer { + using font_type = try_engine::style::fonts::font_type; + BASE_TYPE_DEFINE(); public: @@ -41,6 +43,8 @@ namespace rrr::layers::gui ImGuiIO& io = ImGui::GetIO(); ImFontAtlas* atlas = io.Fonts; ImFont* font; + const ImVec4 dir_color = ImVec4(0.36f, 0.5f, 0.74f, 1.0f); + const ImVec4 file_color = ImVec4(0.9f, 0.9f, 0.9f, 1.0f); }; }