add event key code base
This commit is contained in:
parent
f81f4e5e78
commit
3d6f90f0d9
@ -2,11 +2,17 @@
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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<int>::id ;
|
||||
return *this;
|
||||
|
@ -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<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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user