diff --git a/src/rrr/content/content.cpp b/src/rrr/content/content.cpp index cdafeea..9e0c5cc 100644 --- a/src/rrr/content/content.cpp +++ b/src/rrr/content/content.cpp @@ -17,7 +17,9 @@ namespace rrr { nav.fill(PWD); his.fill(PWD); - prev.fill(nav.store[PWD].at(cursor_position).path); + prev.fill(nav.data.at(navigation_cursor_position).path); + + hack::log()(prev.data.size()); } files* content::get(TYPE_WIN type) @@ -28,7 +30,7 @@ namespace rrr return &his.data; break; case TYPE_WIN::NAVIGATION: - return &nav.store[PWD]; + return &nav.data; break; case TYPE_WIN::PREVIEW: return &prev.data; @@ -39,46 +41,55 @@ namespace rrr } } - int content::get_cursor_position(TYPE_WIN type) + file content::get_selected_file(TYPE_WIN type) { + file f; switch (type) { case TYPE_WIN::HISTORY: - return get_history_cursor_position(); + try + { + set_history_cursor_position(); + f = his.data.at(history_cursor_position); + } + catch(...) { hack::error()("Dont set history"); } break; case TYPE_WIN::NAVIGATION: - return cursor_position; + try + { + f = nav.data.at(navigation_cursor_position); + } + catch(...) { hack::error()("Dont set navigation"); } break; case TYPE_WIN::PREVIEW: - return get_preview_cursor_position(); - break; - default: - return 0; + try + { + set_preview_cursor_position(); + f = prev.data.at(preview_cursor_position); + } + catch(...) { hack::error()("Dont set preview"); } break; } + + return f; } - int content::get_history_cursor_position() const + void content::set_history_cursor_position() { - int history_cursor_position = 0; tbb::parallel_for(tbb::blocked_range(0, his.data.size()), [&](tbb::blocked_range r) { for (int i = r.begin(); i < r.end(); ++i) if (his.data.at(i).path == PWD) history_cursor_position = i; }); - - return history_cursor_position; } - int content::get_preview_cursor_position() + void content::set_preview_cursor_position() { - int preview_cursor_position = 0; - if (std::filesystem::is_empty(PWD)) - return preview_cursor_position; + return; - auto pwd = nav.store[PWD].at(cursor_position).path; + auto pwd = nav.data.at(navigation_cursor_position).path; if (buffer::state.contains(pwd)) { @@ -89,13 +100,11 @@ namespace rrr preview_cursor_position = i; }); } - - return preview_cursor_position; } void content::increment_position(int step) { - cursor_position += step; + navigation_cursor_position += step; check_cursor_position(); // в зависимости от того пустаая ли директория @@ -103,14 +112,14 @@ namespace rrr if (std::filesystem::is_empty(PWD)) prev.data.clear(); else - prev.fill(nav.store[PWD].at(cursor_position).path); + prev.fill(nav.data.at(navigation_cursor_position).path); } void content::check_cursor_position() { - if (cursor_position == (int)nav.store[PWD].size()) cursor_position = (int)nav.store[PWD].size() - 1; - else if (cursor_position < 0) cursor_position = 0; - else if (cursor_position > (int)nav.store[PWD].size()) cursor_position = 0; + if (navigation_cursor_position == (int)nav.data.size()) navigation_cursor_position = (int)nav.data.size() - 1; + else if (navigation_cursor_position < 0) navigation_cursor_position = 0; + else if (navigation_cursor_position > (int)nav.data.size()) navigation_cursor_position = 0; } void content::navigation_right() @@ -118,7 +127,7 @@ namespace rrr if (std::filesystem::is_empty(PWD)) return; // ставим новый pwd и заполняем навигацию и историю - PWD = PWD / nav.store[PWD].at(cursor_position).path.filename(); + PWD = PWD / nav.data.at(navigation_cursor_position).path.filename(); nav.fill(PWD); his.fill(PWD); @@ -129,16 +138,16 @@ namespace rrr if (buffer::state.contains(PWD)) { auto f = buffer::state[PWD]; - tbb::parallel_for(tbb::blocked_range(0, nav.store[PWD].size()), [&](tbb::blocked_range r) + tbb::parallel_for(tbb::blocked_range(0, nav.data.size()), [&](tbb::blocked_range r) { for (int i = r.begin(); i < r.end(); ++i) - if (nav.store[PWD].at(i).path == f.path) - cursor_position = i; + if (nav.data.at(i).path == f.path) + navigation_cursor_position = i; }); } else { - cursor_position = 0; + navigation_cursor_position = 0; } // и исходя из позиции курсора заполняем окно предварительного просмотра @@ -146,7 +155,7 @@ namespace rrr if (std::filesystem::is_empty(PWD)) prev.data.clear(); else - prev.fill(nav.store[PWD].at(cursor_position).path); + prev.fill(nav.data.at(navigation_cursor_position).path); } void content::navigation_left() @@ -154,26 +163,28 @@ namespace rrr // буфер заполняется только когда отсюда уходишь // типа я тут был if (std::filesystem::is_empty(PWD)) - buffer::state[PWD] = nav.store[PWD.parent_path()].at(cursor_position); + // buffer::state[PWD] = nav.store[PWD.parent_path()].at(cursor_position); + buffer::state[PWD] = nav.data.at(navigation_cursor_position); else - buffer::state[PWD] = nav.store[PWD].at(cursor_position); + buffer::state[PWD] = nav.data.at(navigation_cursor_position); auto from = PWD; + nav.fill(PWD.parent_path()); + his.fill(PWD.parent_path()); + prev.fill(PWD); + // ставим новый pwd и заполняем навигацию и историю PWD = PWD.parent_path(); - nav.fill(PWD); - his.fill(PWD); - prev.fill(from); // тут всегда есть место откуда ты пришел // т.е. нет возмолжности придти неоткуда // соответственно находим это место - tbb::parallel_for(tbb::blocked_range(0, nav.store[PWD].size()), [&](tbb::blocked_range r) + tbb::parallel_for(tbb::blocked_range(0, nav.data.size()), [&](tbb::blocked_range r) { for (int i = r.begin(); i < r.end(); ++i) - if (nav.store[PWD].at(i).path == from) - cursor_position = i; + if (nav.data.at(i).path == from) + navigation_cursor_position = i; }); } diff --git a/src/rrr/content/content.hpp b/src/rrr/content/content.hpp index 5967bd5..939d4ba 100644 --- a/src/rrr/content/content.hpp +++ b/src/rrr/content/content.hpp @@ -28,12 +28,13 @@ namespace rrr void set_pwd(std::filesystem::path); void fill(); files* get(TYPE_WIN); - int get_cursor_position(TYPE_WIN); void increment_position(int); void navigation_right(); void navigation_left(); void create_file(std::string); void delete_file(file); + + file get_selected_file(TYPE_WIN); private: content_type::navigation nav; @@ -44,13 +45,16 @@ namespace rrr // она может отличается от его расположения в терминале по факту std::filesystem::path PWD; - // чтобы не устанавливалась стрелка изначально - // полезно при первом открытии окна prev - int cursor_position = 0; + int navigation_cursor_position = 0; + int preview_cursor_position = 0; + int history_cursor_position = 0; + private: - int get_history_cursor_position() const; - int get_preview_cursor_position(); + void set_history_cursor_position(); + void set_preview_cursor_position(); void check_cursor_position(); + + file navigation_selected_file; }; } diff --git a/src/rrr/content/navigation/navigation.cpp b/src/rrr/content/navigation/navigation.cpp index 02d9493..1a79e4e 100644 --- a/src/rrr/content/navigation/navigation.cpp +++ b/src/rrr/content/navigation/navigation.cpp @@ -7,7 +7,7 @@ namespace rrr::content_type // if (!store.contains(PWD)) // store[PWD] = file_utils::fill(PWD); - store[PWD] = file_utils::fill(PWD); + data = file_utils::fill(PWD); } // void navigation::update(std::filesystem::path PWD) diff --git a/src/rrr/content/navigation/navigation.hpp b/src/rrr/content/navigation/navigation.hpp index 8898fe8..8122d6b 100644 --- a/src/rrr/content/navigation/navigation.hpp +++ b/src/rrr/content/navigation/navigation.hpp @@ -16,6 +16,6 @@ namespace rrr::content_type void fill(std::filesystem::path); // void update(std::filesystem::path); - std::unordered_map store; + files data; }; } diff --git a/src/rrr/layers/gui/browser/history/history.cpp b/src/rrr/layers/gui/browser/history/history.cpp index c63f1d8..e4ca46f 100644 --- a/src/rrr/layers/gui/browser/history/history.cpp +++ b/src/rrr/layers/gui/browser/history/history.cpp @@ -9,7 +9,7 @@ namespace rrr::layers::gui BASE_WINDOW_FLAGS(); data = cnt->get(TYPE_WIN::HISTORY); - cursor_position = cnt->get_cursor_position(TYPE_WIN::HISTORY); + selected_file = cnt->get_selected_file(TYPE_WIN::HISTORY); } void history::on_detach() @@ -34,7 +34,6 @@ namespace rrr::layers::gui pos.y += 9.f; // небольшой отступ сверху ImGui::SetCursorPosY(pos.y); - int index = 0; for (auto& item : *data) { ImGui::PushID(item.id); @@ -44,24 +43,21 @@ namespace rrr::layers::gui else ImGui::PushStyleColor(ImGuiCol_Text, file_color); - if (cursor_position == index) + if (selected_file.path == item.path) { - font = try_engine::style::fonts::get_font(font_type::SEMI_BOLD, 18); - ImGui::PushFont(font); + TR_PUSH_FONT(SEMI_BOLD, 18); ImGui::TextUnformatted(">"); ImGui::SameLine(22.f); } else { ImGui::SetCursorPosX(pos.x); - font = try_engine::style::fonts::get_font(font_type::MEDIUM, 18); - ImGui::PushFont(font); + TR_PUSH_FONT(MEDIUM, 18); } ImGui::TextUnformatted(item.path.filename().string().data()); - ++index; - ImGui::PopFont(); + TR_POP_FONT(); ImGui::PopStyleColor(); ImGui::PopID(); } @@ -89,7 +85,7 @@ namespace rrr::layers::gui { case types::event_type::NAVIGATION_LEFT: case types::event_type::NAVIGATION_RIGHT: - cursor_position = cnt->get_cursor_position(TYPE_WIN::HISTORY); + selected_file = cnt->get_selected_file(TYPE_WIN::HISTORY); break; default: break; diff --git a/src/rrr/layers/gui/browser/history/history.hpp b/src/rrr/layers/gui/browser/history/history.hpp index 9e0f073..7edb046 100644 --- a/src/rrr/layers/gui/browser/history/history.hpp +++ b/src/rrr/layers/gui/browser/history/history.hpp @@ -8,8 +8,6 @@ namespace rrr::layers::gui { class history : public try_engine::layer { - using font_type = try_engine::style::fonts::font_type; - BASE_TYPE_DEFINE(); public: @@ -31,7 +29,7 @@ namespace rrr::layers::gui event_manager* em; content* cnt; files* data; - int cursor_position = 0; + file selected_file; float width = 0.f; float height = 0.f; @@ -39,9 +37,6 @@ namespace rrr::layers::gui float pos_y = 0.f; private: - ImGuiIO& io = ImGui::GetIO(); - ImFontAtlas* atlas = io.Fonts; - ImFont* font; const ImVec4 dir_color = func::get_IMGUI_color(91.f, 128.f, 191.f); const ImVec4 file_color = func::get_IMGUI_color(186.f, 186.f, 186.f); const ImVec4 link_color = func::get_IMGUI_color(51.f, 95.f, 165.f); diff --git a/src/rrr/layers/gui/browser/navigation/navigation.cpp b/src/rrr/layers/gui/browser/navigation/navigation.cpp index c11dcbb..4d9bd15 100644 --- a/src/rrr/layers/gui/browser/navigation/navigation.cpp +++ b/src/rrr/layers/gui/browser/navigation/navigation.cpp @@ -12,6 +12,7 @@ namespace rrr::layers::gui BASE_WINDOW_FLAGS(); data = cnt->get(TYPE_WIN::NAVIGATION); + selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION); } void navigation::on_detach() @@ -36,30 +37,32 @@ namespace rrr::layers::gui pos.y += 9.f; // небольшой отступ сверху ImGui::SetCursorPosY(pos.y); - int index = 0; for (auto& item : *data) { ImGui::PushID(item.id); push_style(item); - if (cursor_position == index) + if (selected_file.path == item.path) { - font = try_engine::style::fonts::get_font(item.is_hidden ? font_type::SEMI_BOLD_ITALIC : font_type::SEMI_BOLD, 18); - ImGui::PushFont(font); + if (selected_file.is_hidden) + TR_PUSH_FONT(SEMI_BOLD_ITALIC, 18); + else + TR_PUSH_FONT(SEMI_BOLD, 18); + ImGui::TextUnformatted(">"); ImGui::SameLine(22.f); - current_file = item; } else { ImGui::SetCursorPosX(pos.x); - font = try_engine::style::fonts::get_font(item.is_hidden ? font_type::MEDIUM_ITALIC : font_type::MEDIUM, 18); - ImGui::PushFont(font); + if (item.is_hidden) + TR_PUSH_FONT(MEDIUM_ITALIC, 18); + else + TR_PUSH_FONT(MEDIUM, 18); } ImGui::TextUnformatted(get_file_content(item).data()); - ++index; pop_style(item); } @@ -81,14 +84,11 @@ namespace rrr::layers::gui if (f.is_link) ImGui::PushStyleColor(ImGuiCol_Text, link_color); - - if (f.is_hidden) - font = try_engine::style::fonts::get_font(font_type::MEDIUM_ITALIC, 18); } void navigation::pop_style(file& f) { - ImGui::PopFont(); + TR_POP_FONT(); ImGui::PopStyleColor(); ImGui::PopID(); @@ -133,8 +133,8 @@ namespace rrr::layers::gui case types::event_type::DELETE_CURRENT_FILE: { freeze = false; - cnt->delete_file(current_file); - cursor_position = cnt->get_cursor_position(TYPE_WIN::NAVIGATION); + cnt->delete_file(selected_file); + selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION); } break; case types::event_type::CREATE_FILE: @@ -142,7 +142,7 @@ namespace rrr::layers::gui freeze = false; auto filename = std::any_cast(value); cnt->create_file(filename); - cursor_position = cnt->get_cursor_position(TYPE_WIN::NAVIGATION); + selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION); } break; default: @@ -200,7 +200,7 @@ namespace rrr::layers::gui // удаление if (shift && key.get_keycode() == try_engine::key::D) { - em->execute(types::event_type::SHOW_DELETE_ONE_FILE_DIALOG, current_file); + em->execute(types::event_type::SHOW_DELETE_ONE_FILE_DIALOG, selected_file); freeze = true; } @@ -211,7 +211,7 @@ namespace rrr::layers::gui freeze = true; } - cursor_position = cnt->get_cursor_position(TYPE_WIN::NAVIGATION); + selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION); } void navigation::released(system_event& e) diff --git a/src/rrr/layers/gui/browser/navigation/navigation.hpp b/src/rrr/layers/gui/browser/navigation/navigation.hpp index 8674888..e12234f 100644 --- a/src/rrr/layers/gui/browser/navigation/navigation.hpp +++ b/src/rrr/layers/gui/browser/navigation/navigation.hpp @@ -10,8 +10,6 @@ namespace rrr::layers::gui // Они не вычисляют ни чего, все вычисления делает контент (cnt) class navigation : public try_engine::layer { - using font_type = try_engine::style::fonts::font_type; - BASE_TYPE_DEFINE(); public: @@ -41,16 +39,12 @@ namespace rrr::layers::gui float pos_y = 0.f; float padding_between_window = 2.f; - int cursor_position = 0; const int STEP_UP = -1; const int STEP_DOWN = 1; - file current_file; + file selected_file; bool shift = false; private: - ImGuiIO& io = ImGui::GetIO(); - ImFontAtlas* atlas = io.Fonts; - ImFont* font; const ImVec4 dir_color = func::get_IMGUI_color(91.f, 128.f, 191.f); const ImVec4 file_color = func::get_IMGUI_color(186.f, 186.f, 186.f); const ImVec4 link_color = func::get_IMGUI_color(51.f, 95.f, 165.f); diff --git a/src/rrr/layers/gui/browser/preview/preview.cpp b/src/rrr/layers/gui/browser/preview/preview.cpp index 5b3e8e5..4f4596a 100644 --- a/src/rrr/layers/gui/browser/preview/preview.cpp +++ b/src/rrr/layers/gui/browser/preview/preview.cpp @@ -9,7 +9,7 @@ namespace rrr::layers::gui BASE_WINDOW_FLAGS(); data = cnt->get(TYPE_WIN::PREVIEW); - cursor_position = cnt->get_cursor_position(TYPE_WIN::PREVIEW); + selected_file = cnt->get_selected_file(TYPE_WIN::PREVIEW); } void preview::on_detach() @@ -34,7 +34,6 @@ namespace rrr::layers::gui pos.y += 9.f; // небольшой отступ сверху ImGui::SetCursorPosY(pos.y); - int index = 0; for (auto& item : *data) { ImGui::PushID(item.id); @@ -44,24 +43,21 @@ namespace rrr::layers::gui else ImGui::PushStyleColor(ImGuiCol_Text, file_color); - if (cursor_position == index) + if (selected_file.path == item.path) { - font = try_engine::style::fonts::get_font(font_type::SEMI_BOLD, 18); - ImGui::PushFont(font); + TR_PUSH_FONT(SEMI_BOLD, 18); ImGui::TextUnformatted(">"); ImGui::SameLine(22.f); } else { ImGui::SetCursorPosX(pos.x); - font = try_engine::style::fonts::get_font(font_type::MEDIUM, 18); - ImGui::PushFont(font); + TR_PUSH_FONT(MEDIUM, 18); } ImGui::TextUnformatted(item.path.filename().string().data()); - ++index; - ImGui::PopFont(); + TR_POP_FONT(); ImGui::PopStyleColor(); ImGui::PopID(); } @@ -97,7 +93,7 @@ namespace rrr::layers::gui case types::event_type::NAVIGATION_DOWN: case types::event_type::NAVIGATION_LEFT: case types::event_type::NAVIGATION_RIGHT: - cursor_position = cnt->get_cursor_position(TYPE_WIN::PREVIEW); + selected_file = cnt->get_selected_file(TYPE_WIN::PREVIEW); break; default: break; diff --git a/src/rrr/layers/gui/browser/preview/preview.hpp b/src/rrr/layers/gui/browser/preview/preview.hpp index 4c27d54..401b368 100644 --- a/src/rrr/layers/gui/browser/preview/preview.hpp +++ b/src/rrr/layers/gui/browser/preview/preview.hpp @@ -8,8 +8,6 @@ namespace rrr::layers::gui { class preview : public try_engine::layer { - using font_type = try_engine::style::fonts::font_type; - BASE_TYPE_DEFINE(); public: @@ -30,7 +28,7 @@ namespace rrr::layers::gui bool show = true; event_manager* em; content* cnt; - int cursor_position = 0; + file selected_file; files* data; float width = 0.f; @@ -39,9 +37,6 @@ namespace rrr::layers::gui float pos_y = 0.f; private: - ImGuiIO& io = ImGui::GetIO(); - ImFontAtlas* atlas = io.Fonts; - ImFont* font; const ImVec4 dir_color = func::get_IMGUI_color(91.f, 128.f, 191.f); const ImVec4 file_color = func::get_IMGUI_color(186.f, 186.f, 186.f); const ImVec4 link_color = func::get_IMGUI_color(51.f, 95.f, 165.f); diff --git a/src/rrr/layers/gui/dialogs/dialogs.cpp b/src/rrr/layers/gui/dialogs/dialogs.cpp index 70ad1fb..013f9e5 100644 --- a/src/rrr/layers/gui/dialogs/dialogs.cpp +++ b/src/rrr/layers/gui/dialogs/dialogs.cpp @@ -133,8 +133,7 @@ namespace rrr::layers::gui void dialogs::draw_delete_dialog() { - font = try_engine::style::fonts::get_font(font_type::MEDIUM, 18); - ImGui::PushFont(font); + TR_PUSH_FONT(MEDIUM, 18); std::string label = current_file.type == file_type::DIR ? "Даннaя директория будет удалена!" : "Данный файл будет удален!"; // манипуляции с тем чтобы название стояло посередлине @@ -175,13 +174,12 @@ namespace rrr::layers::gui if (ImGui::Button("Отмена (n / Esc)", button_size)) cancel(); - ImGui::PopFont(); + TR_POP_FONT(); } void dialogs::draw_create_dialog() { - font = try_engine::style::fonts::get_font(font_type::MEDIUM, 18); - ImGui::PushFont(font); + TR_PUSH_FONT(MEDIUM, 18); std::string label = "Создание файла/директории!"; // манипуляции с тем чтобы название стояло посередлине @@ -216,7 +214,7 @@ namespace rrr::layers::gui if (ImGui::Button("Отмена (Esc)", button_size)) cancel(); - ImGui::PopFont(); + TR_POP_FONT(); } void dialogs::create_file() diff --git a/src/rrr/layers/gui/dialogs/dialogs.hpp b/src/rrr/layers/gui/dialogs/dialogs.hpp index 36292a3..48b4575 100644 --- a/src/rrr/layers/gui/dialogs/dialogs.hpp +++ b/src/rrr/layers/gui/dialogs/dialogs.hpp @@ -7,8 +7,6 @@ namespace rrr::layers::gui { class dialogs : public try_engine::layer { - using font_type = try_engine::style::fonts::font_type; - BASE_TYPE_DEFINE(); public: @@ -36,11 +34,6 @@ namespace rrr::layers::gui bool shift = false; std::string title; - private: - ImGuiIO& io = ImGui::GetIO(); - ImFontAtlas* atlas = io.Fonts; - ImFont* font; - private: void resize(); void cancel();