182 lines
4.2 KiB
C++
Executable File
182 lines
4.2 KiB
C++
Executable File
#include "history.hpp"
|
||
|
||
#include "utils/types.hpp"
|
||
|
||
namespace rrr::layers::gui
|
||
{
|
||
void history::on_attach()
|
||
{
|
||
BASE_WINDOW_FLAGS();
|
||
|
||
data = cnt->get(TYPE_WIN::HISTORY);
|
||
selected_file = cnt->get_selected_file(TYPE_WIN::HISTORY);
|
||
}
|
||
|
||
void history::on_detach()
|
||
{
|
||
|
||
}
|
||
|
||
void history::gui_render()
|
||
{
|
||
if (!show) return;
|
||
|
||
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y));
|
||
ImGui::SetNextWindowSize(ImVec2(width, height));
|
||
|
||
ImGuiStyle& st = ImGui::GetStyle();
|
||
st.Colors[ImGuiCol_WindowBg] = func::get_IMGUI_color<ImVec4>(33.f, 36.f, 46.f);
|
||
|
||
BEGIN_IMGUI_WIN();
|
||
|
||
auto pos = ImGui::GetCursorPos();
|
||
pos.x += 17.f;
|
||
pos.y += 9.f; // небольшой отступ сверху
|
||
ImGui::SetCursorPosY(pos.y);
|
||
|
||
auto begin = data->begin() + delta;
|
||
auto end = data->end();
|
||
|
||
for (files::iterator it = begin; it != end; ++it)
|
||
{
|
||
auto item = *it;
|
||
ImGui::PushID(item.id);
|
||
|
||
if (item.type == file_type::DIR)
|
||
ImGui::PushStyleColor(ImGuiCol_Text, dir_color);
|
||
else
|
||
ImGui::PushStyleColor(ImGuiCol_Text, file_color);
|
||
|
||
if (selected_file.path == item.path)
|
||
{
|
||
TR_PUSH_FONT(SEMI_BOLD, 18);
|
||
ImGui::TextUnformatted(">");
|
||
ImGui::SameLine(22.f);
|
||
current_position = std::distance(data->begin(), it);
|
||
}
|
||
else
|
||
{
|
||
ImGui::SetCursorPosX(pos.x);
|
||
TR_PUSH_FONT(MEDIUM, 18);
|
||
}
|
||
|
||
ImGui::TextUnformatted(item.path.filename().string().data());
|
||
|
||
TR_POP_FONT();
|
||
ImGui::PopStyleColor();
|
||
ImGui::PopID();
|
||
}
|
||
|
||
END_IMGUI_WIN();
|
||
}
|
||
|
||
void history::on_event(system_event& e)
|
||
{
|
||
if (e.get_name() == try_engine::system_event::classificator::WINDOW_RESIZE())
|
||
resize();
|
||
}
|
||
|
||
void history::resize()
|
||
{
|
||
height = try_engine::application::get()->get_window()->height();
|
||
width = try_engine::application::get()->get_window()->width() / 3.f;
|
||
}
|
||
|
||
void history::on_event(std::any event_type, std::any value)
|
||
{
|
||
auto et = std::any_cast<types::event_type>(event_type);
|
||
|
||
switch (et)
|
||
{
|
||
case types::event_type::NAVIGATION_LEFT:
|
||
case types::event_type::NAVIGATION_RIGHT:
|
||
selected_file = cnt->get_selected_file(TYPE_WIN::HISTORY);
|
||
set_scroll();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
void history::on_update(time t)
|
||
{
|
||
|
||
}
|
||
|
||
void history::set_delta(MOVE_DIRECTION mvd)
|
||
{
|
||
auto row_size = 26.3f; // высота вы пикселях одной строки списка
|
||
int h = height / row_size; // высота в строках списка всего столбца экрана
|
||
auto big_content = height < data->size() * row_size;
|
||
|
||
int size = data->size();
|
||
|
||
if (big_content)
|
||
{
|
||
if (mvd == MOVE_DIRECTION::DOWN)
|
||
{
|
||
++cursor_position;
|
||
|
||
// на самом деле получаем его выше, но делаем такой трюк
|
||
// т.к. происходит задержка на один ход нажатия клавиши
|
||
++current_position;
|
||
if (current_position >= size) current_position = size - 1;
|
||
|
||
bool is_end = size - current_position <= 10;
|
||
if (cursor_position >= h - 10 && !is_end)
|
||
{
|
||
++delta;
|
||
cursor_position = h - 10;
|
||
}
|
||
|
||
if (cursor_position >= h) cursor_position = h;
|
||
}
|
||
|
||
if (mvd == MOVE_DIRECTION::UP)
|
||
{
|
||
--cursor_position;
|
||
--current_position;
|
||
|
||
if (cursor_position <= 10)
|
||
--delta;
|
||
|
||
if (cursor_position < 10 && current_position > 12)
|
||
cursor_position = 10;
|
||
|
||
if (delta < 0)
|
||
{
|
||
delta = 0;
|
||
cursor_position = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void history::set_scroll()
|
||
{
|
||
delta = 0;
|
||
current_position = 0;
|
||
cursor_position = 0;
|
||
|
||
auto row_size = 26.3f; // высота вы пикселях одной строки списка
|
||
auto big_content = height < data->size() * row_size;
|
||
|
||
if (big_content)
|
||
{
|
||
for (const auto& f : *data)
|
||
{
|
||
if (f.path != selected_file.path)
|
||
{
|
||
set_delta(MOVE_DIRECTION::DOWN);
|
||
}
|
||
else
|
||
{
|
||
set_delta(MOVE_DIRECTION::DOWN);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|