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

@@ -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<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)