add style and base navigation

This commit is contained in:
chatlanin
2023-03-12 12:50:05 +03:00
parent 3d6f90f0d9
commit 44ed461df9
12 changed files with 408 additions and 51 deletions

View File

@@ -1,5 +1,7 @@
#include "navigation.hpp"
#include "utils/types.hpp"
#include "logger/logger.hpp"
namespace rrr::layers::gui
@@ -9,7 +11,6 @@ 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()
@@ -24,66 +25,98 @@ namespace rrr::layers::gui
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();
pos.x += 17.f;
pos.y += 9.f; // небольшой отступ сверху
ImGui::SetCursorPosY(pos.y);
int index = 0;
for (auto& item : *data)
{
ImGui::PushID(item.id);
if (item.type == file_type::DIR)
ImGui::PushStyleColor(ImGuiCol_Text, dir_color);
else
ImGui::PushStyleColor(ImGuiCol_Text, file_color);
push_style(item);
if (selected == index)
if (cursor_position == index)
{
font = try_engine::style::fonts::get_font(item.is_hidden ? font_type::SEMI_BOLD_ITALIC : font_type::SEMI_BOLD, 18);
ImGui::PushFont(font);
ImGui::TextUnformatted(">");
ImGui::SameLine(22.f);
}
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);
}
ImGui::TextUnformatted(item.path.filename().string().data());
ImGui::PopStyleColor();
ImGui::PopID();
ImGui::TextUnformatted(get_file_content(item).data());
++index;
pop_style(item);
}
ImGui::PopFont();
END_IMGUI_WIN();
}
void navigation::on_event(try_engine::system_event::event& e)
// HERE начинаем тут
// нужно сделать навигацию влево и вправо
// в прошлыq раз тут сделали стилизацию по типу файлов (скрыты ссылки и тп)
// и затем все это нужно распространить на другие части (history, preview)
// когда делаем навигацию влево и вправо то не меняется центральный контент
// почему то у нас отличаются данные контента в файле content/navigation от
// content/history и content/preview
// там map<path, string> а у всех других файл. зачем это нужно???
void navigation::push_style(file& f)
{
switch (f.type)
{
case file_type::DIR:
ImGui::PushStyleColor(ImGuiCol_Text, dir_color);
break;
default: // когда просто файл
ImGui::PushStyleColor(ImGuiCol_Text, file_color);
break;
}
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();
ImGui::PopStyleColor();
ImGui::PopID();
if (f.is_link)
ImGui::PopStyleColor();
}
std::string navigation::get_file_content(file& f)
{
auto file_content = f.path.filename().string();
if (f.is_link)
file_content += " ->";
return file_content;
}
void navigation::on_event(system_event& e)
{
if (e.get_name() == try_engine::system_event::classificator::WINDOW_RESIZE())
{
height = try_engine::application::get()->get_window()->height() - 40.f;
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 начинаем тут
// нужно реализовать обработку клавишь
// и выннести это в движок тоже
resize();
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());
set_selected(e);
}
void navigation::on_event(std::any e, std::any value)
@@ -94,5 +127,38 @@ namespace rrr::layers::gui
{
}
}
void navigation::resize()
{
height = try_engine::application::get()->get_window()->height();
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;
}
void navigation::set_selected(system_event& e)
{
auto key = static_cast<try_engine::system_event::key_pressed_event&>(e);
if (key.get_keycode() == try_engine::key::J)
{
cnt->increment_position(STEP_DOWN);
cursor_position = cnt->get_cursor_position(TYPE_WIN::NAVIGATION);
}
if (key.get_keycode() == try_engine::key::K)
{
cnt->increment_position(STEP_UP);
cursor_position = cnt->get_cursor_position(TYPE_WIN::NAVIGATION);
}
if (key.get_keycode() == try_engine::key::H)
{
cnt->navigation_left();
}
if (key.get_keycode() == try_engine::key::L)
{
cnt->navigation_right();
}
}
}