add base navigation left and right

This commit is contained in:
chatlanin
2023-04-02 10:22:21 +03:00
parent c39fb0e6da
commit d82d6a63a3
7 changed files with 221 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
#include "navigation.hpp"
#include <algorithm>
#include "try_engine/event/event_classificator.hpp"
#include "utils/types.hpp"
@@ -179,6 +181,7 @@ namespace rrr::layers::gui
if (key.get_keycode() == try_engine::key::J)
{
cnt->increment_position(STEP_DOWN);
selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION);
em->execute(types::event_type::NAVIGATION_DOWN, nullptr);
set_delta(MOVE_DIRECTION::DOWN);
}
@@ -186,6 +189,7 @@ namespace rrr::layers::gui
if (key.get_keycode() == try_engine::key::K)
{
cnt->increment_position(STEP_UP);
selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION);
em->execute(types::event_type::NAVIGATION_UP, nullptr);
set_delta(MOVE_DIRECTION::UP);
}
@@ -194,14 +198,18 @@ namespace rrr::layers::gui
{
cnt->navigation_left();
data = cnt->get(TYPE_WIN::NAVIGATION);
selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION);
em->execute(types::event_type::NAVIGATION_LEFT, nullptr);
set_scroll();
}
if (key.get_keycode() == try_engine::key::L)
{
cnt->navigation_right();
data = cnt->get(TYPE_WIN::NAVIGATION);
selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION);
em->execute(types::event_type::NAVIGATION_RIGHT, nullptr);
set_scroll();
}
// удаление
@@ -217,8 +225,6 @@ namespace rrr::layers::gui
em->execute(types::event_type::SHOW_CREATE_FILE_DIALOG, nullptr);
freeze = true;
}
selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION);
}
void navigation::released(system_event& e)
@@ -235,7 +241,6 @@ namespace rrr::layers::gui
int h = height / row_size; // высота в строках списка всего столбца экрана
auto big_content = height < data->size() * row_size;
static auto cursor_position = 0; // позиция курсора относительно высоты экрана
int size = data->size();
if (big_content)
@@ -278,4 +283,30 @@ namespace rrr::layers::gui
}
}
}
void navigation::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;
}
}
}
}
}