add event key code base

This commit is contained in:
chatlanin 2023-03-05 16:08:51 +03:00
parent f81f4e5e78
commit 3d6f90f0d9
4 changed files with 64 additions and 31 deletions

View File

@ -2,11 +2,17 @@
namespace rrr namespace rrr
{ {
file::file(std::filesystem::path path_, file_type type_, bool is_link_) : id { ++hack::utils::counter<int>::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<int>::id }, path{ path_ }, type{ type_ }, is_link{ is_link_ }, is_hidden{ is_hidden_ } {}
file::file(file&& f) : id { ++hack::utils::counter<int>::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<int>::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<int>::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<int>::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) file& file::operator=(const file& other)
{ {
@ -15,6 +21,7 @@ namespace rrr
path = other.path; path = other.path;
type = other.type; type = other.type;
is_link = other.is_link; is_link = other.is_link;
is_hidden = other.is_hidden;
is_mark = other.is_mark; is_mark = other.is_mark;
id = ++hack::utils::counter<int>::id ; id = ++hack::utils::counter<int>::id ;
return *this; return *this;

View File

@ -23,7 +23,7 @@ namespace rrr
{ {
public: public:
file() = default; file() = default;
file(std::filesystem::path, file_type, bool); file(std::filesystem::path, file_type, bool, bool);
file(file&&); file(file&&);
file(const file&); file(const file&);
@ -38,6 +38,7 @@ namespace rrr
std::filesystem::path path; std::filesystem::path path;
file_type type; file_type type;
bool is_link = false; bool is_link = false;
bool is_hidden = false;
bool is_mark = false; bool is_mark = false;
}; };
} }
@ -46,6 +47,14 @@ namespace rrr::file_utils
{ {
using files = std::vector<file>; using files = std::vector<file>;
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 struct filesystem_convert
{ {
file operator()(const std::filesystem::directory_entry& entry) const file operator()(const std::filesystem::directory_entry& entry) const
@ -56,8 +65,9 @@ namespace rrr::file_utils
type = file_type::DIR; type = file_type::DIR;
auto is_link = std::filesystem::is_symlink(entry); 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(...) catch(...)
{ {
f.push_back({ path / "no permission", file_type::TEXT, false }); f.push_back({ path / "no permission", file_type::TEXT, false, false });
} }
return f; return f;
@ -109,12 +119,4 @@ namespace rrr::file_utils
return tmp; 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;
}
} }

View File

@ -1,5 +1,7 @@
#include "navigation.hpp" #include "navigation.hpp"
#include "logger/logger.hpp"
namespace rrr::layers::gui namespace rrr::layers::gui
{ {
void navigation::on_attach() void navigation::on_attach()
@ -7,6 +9,7 @@ namespace rrr::layers::gui
BASE_WINDOW_FLAGS(); BASE_WINDOW_FLAGS();
data = cnt->get(TYPE_WIN::NAVIGATION); data = cnt->get(TYPE_WIN::NAVIGATION);
font = try_engine::style::fonts::get_font(font_type::MEDIUM, 18);
} }
void navigation::on_detach() void navigation::on_detach()
@ -19,44 +22,49 @@ namespace rrr::layers::gui
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y)); ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y));
ImGui::SetNextWindowSize(ImVec2(width, height)); 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(); BEGIN_IMGUI_WIN();
auto pos = ImGui::GetCursorPos(); 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) for (auto& item : *data)
{ {
ImGui::PushID(item.id); ImGui::PushID(item.id);
char buf[32]; if (item.type == file_type::DIR)
sprintf(buf, "##item_%d", item.id); ImGui::PushStyleColor(ImGuiCol_Text, dir_color);
else
ImGui::PushStyleColor(ImGuiCol_Text, file_color);
ImGui::SetCursorPos(ImVec2(pos.x, pos.y + padding)); if (selected == index)
if (ImGui::Selectable(buf, item.id == selected, 0, ImVec2(width, 60))) {
selected = item.id; ImGui::TextUnformatted(">");
ImGui::SameLine(22.f);
font = atlas->Fonts[1]; }
ImGui::PushFont(font); else
ImGui::PushStyleColor(ImGuiCol_Text, type_color); ImGui::SetCursorPosX(pos.x);
ImGui::TextUnformatted(item.path.filename().string().data()); ImGui::TextUnformatted(item.path.filename().string().data());
pos.y += font->FontSize + 4.f;
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::PopFont();
ImGui::PopID(); ImGui::PopID();
++index;
} }
ImGui::PopFont();
END_IMGUI_WIN(); 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()) 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; 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; 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<try_engine::system_event::key_pressed_event&>(e);
hack::log()(key.get_keycode());
}
hack::log()(e.get_name());
} }
void navigation::on_event(std::any e, std::any value) void navigation::on_event(std::any e, std::any value)

View File

@ -7,6 +7,8 @@ namespace rrr::layers::gui
{ {
class navigation : public try_engine::layer class navigation : public try_engine::layer
{ {
using font_type = try_engine::style::fonts::font_type;
BASE_TYPE_DEFINE(); BASE_TYPE_DEFINE();
public: public:
@ -41,6 +43,8 @@ namespace rrr::layers::gui
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
ImFontAtlas* atlas = io.Fonts; ImFontAtlas* atlas = io.Fonts;
ImFont* font; 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);
}; };
} }