add navigation up down
This commit is contained in:
parent
11ba975ec8
commit
c39fb0e6da
@ -18,8 +18,6 @@ namespace rrr
|
||||
nav.fill(PWD);
|
||||
his.fill(PWD);
|
||||
prev.fill(nav.data.at(navigation_cursor_position).path);
|
||||
|
||||
hack::log()(prev.data.size());
|
||||
}
|
||||
|
||||
files* content::get(TYPE_WIN type)
|
||||
|
@ -37,8 +37,12 @@ namespace rrr::layers::gui
|
||||
pos.y += 9.f; // небольшой отступ сверху
|
||||
ImGui::SetCursorPosY(pos.y);
|
||||
|
||||
for (auto& item : *data)
|
||||
auto begin = data->begin() + delta;
|
||||
auto end = data->end();
|
||||
|
||||
for (files::iterator it = begin; it != end; ++it)
|
||||
{
|
||||
auto item = *it;
|
||||
ImGui::PushID(item.id);
|
||||
|
||||
push_style(item);
|
||||
@ -52,6 +56,7 @@ namespace rrr::layers::gui
|
||||
|
||||
ImGui::TextUnformatted(">");
|
||||
ImGui::SameLine(22.f);
|
||||
current_position = it - data->begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -175,12 +180,14 @@ namespace rrr::layers::gui
|
||||
{
|
||||
cnt->increment_position(STEP_DOWN);
|
||||
em->execute(types::event_type::NAVIGATION_DOWN, nullptr);
|
||||
set_delta(MOVE_DIRECTION::DOWN);
|
||||
}
|
||||
|
||||
if (key.get_keycode() == try_engine::key::K)
|
||||
{
|
||||
cnt->increment_position(STEP_UP);
|
||||
em->execute(types::event_type::NAVIGATION_UP, nullptr);
|
||||
set_delta(MOVE_DIRECTION::UP);
|
||||
}
|
||||
|
||||
if (key.get_keycode() == try_engine::key::H)
|
||||
@ -221,4 +228,54 @@ namespace rrr::layers::gui
|
||||
if (key.get_keycode() == try_engine::key::LEFTSHIFT || key.get_keycode() == try_engine::key::RIGHTSHIFT)
|
||||
shift = false;
|
||||
}
|
||||
|
||||
void navigation::set_delta(MOVE_DIRECTION mvd)
|
||||
{
|
||||
auto row_size = 26.3f; // высота вы пикселях одной строки списка
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,12 +43,16 @@ namespace rrr::layers::gui
|
||||
const int STEP_DOWN = 1;
|
||||
file selected_file;
|
||||
bool shift = false;
|
||||
int current_position = 0;
|
||||
int delta = 0;
|
||||
|
||||
private:
|
||||
const ImVec4 dir_color = func::get_IMGUI_color<ImVec4>(91.f, 128.f, 191.f);
|
||||
const ImVec4 file_color = func::get_IMGUI_color<ImVec4>(186.f, 186.f, 186.f);
|
||||
const ImVec4 link_color = func::get_IMGUI_color<ImVec4>(51.f, 95.f, 165.f);
|
||||
|
||||
enum class MOVE_DIRECTION { UP, DOWN };
|
||||
|
||||
private:
|
||||
void resize();
|
||||
void pressed(system_event& e);
|
||||
@ -57,6 +61,7 @@ namespace rrr::layers::gui
|
||||
void push_style(file&);
|
||||
void pop_style(file&);
|
||||
std::string get_file_content(file&);
|
||||
void set_delta(MOVE_DIRECTION);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -11,17 +11,17 @@ namespace rrr
|
||||
{
|
||||
using event_manager = try_engine::app_event::event;
|
||||
|
||||
class engine : public try_engine::application
|
||||
class rrr_impl : public try_engine::application
|
||||
{
|
||||
public:
|
||||
engine(std::string app_name) : try_engine::application{ app_name }
|
||||
rrr_impl(std::string app_name) : try_engine::application{ app_name }
|
||||
{
|
||||
// HERE
|
||||
// убрать это в релизе
|
||||
cnt.set_pwd("/mnt/develop/projects/cpp/rrr/dir_for_tests");
|
||||
cnt.fill();
|
||||
};
|
||||
~engine() = default;
|
||||
~rrr_impl() = default;
|
||||
|
||||
public:
|
||||
template<typename... Args>
|
||||
@ -42,7 +42,7 @@ namespace try_engine
|
||||
{
|
||||
inline application& create()
|
||||
{
|
||||
static rrr::engine e { "rrr.v2" };
|
||||
static rrr::rrr_impl e { "rrr.v2" };
|
||||
|
||||
e.push_layer(
|
||||
new rrr::layers::gui::history{},
|
||||
|
Loading…
Reference in New Issue
Block a user