scroll through file with J/K keys

This commit is contained in:
Josh Holtrop 2016-07-10 20:13:40 -04:00
parent d8fcbcd428
commit b1684f1341
3 changed files with 24 additions and 0 deletions

View File

@ -23,6 +23,8 @@ public:
auto crbegin() const { return m_lines.crbegin(); }
auto crend() const { return m_lines.crend(); }
int get_num_lines() { return m_lines.size(); }
protected:
LinesType m_lines;
/* TODO: delete this */

View File

@ -111,6 +111,7 @@ bool Window::create(std::shared_ptr<Buffer> buffer)
m_programs.text->set_color(1.0, 1.0, 1.0, 1.0);
m_buffer = buffer;
m_line = 0;
resize();
@ -149,6 +150,20 @@ void Window::handle_event(SDL_Event & event)
case SDLK_ESCAPE:
m_exit_requested = true;
break;
case SDLK_j:
if (m_line < m_buffer->get_num_lines() - 1)
{
m_line++;
redraw();
}
break;
case SDLK_k:
if (m_line > 0)
{
m_line--;
redraw();
}
break;
}
break;
@ -185,8 +200,13 @@ void Window::redraw()
int advance = m_font.get_advance();
int line_height = m_font.get_line_height();
int y = m_height - line_height;
int line_number = 0;
for (auto line = m_buffer->cbegin(); line != m_buffer->cend(); line++)
{
if (line_number++ < m_line)
{
continue;
}
int x = 0;
for (int i = 0, len = (*line)->size(); i < len; i++)
{

View File

@ -29,6 +29,8 @@ protected:
Font m_font;
std::shared_ptr<Buffer> m_buffer;
int m_line;
};
#endif