update BufferPane::update_cursor_row() in preparation for drawing again

This commit is contained in:
Josh Holtrop 2016-12-20 23:24:06 -05:00
parent 975b7763a8
commit 1486cdf7f4
2 changed files with 17 additions and 14 deletions

View File

@ -15,18 +15,6 @@ void BufferPane::resize(int width, int height)
m_rows = std::max(1, (m_height + m_window->font()->get_line_height() - 1) / m_window->font()->get_line_height()); m_rows = std::max(1, (m_height + m_window->font()->get_line_height() - 1) / m_window->font()->get_line_height());
} }
#if 0
void BufferPane::update_cursor_row()
{
int so = effective_scroll_offset();
int rows_above = screen_rows_above_cursor(std::max(so, m_cursor_row));
int rows_below = screen_rows_below_cursor(std::max(so, m_rows - m_cursor_row - 1));
int min_rows_to_leave_above = std::min(rows_above, so);
int min_rows_to_leave_below = std::min(rows_below, so);
m_cursor_row = std::max(min_rows_to_leave_above, std::min(m_rows - min_rows_to_leave_below - 1, m_cursor_row));
}
#endif
int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line) int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line)
{ {
int rows = 1; int rows = 1;
@ -111,6 +99,21 @@ int BufferPane::screen_rows_above_line(const Buffer::Iterator & line)
return rows; return rows;
} }
int BufferPane::update_cursor_row()
{
Buffer::Iterator start_of_line = *m_iterator;
start_of_line.go_start_of_line();
int cursor_row_offset;
int rows_in_cursor_line = rows_in_line_with_iterator_offset(start_of_line, *m_iterator, &cursor_row_offset);
int so = effective_scroll_offset();
int rows_above = screen_rows_above_line(*m_iterator) + cursor_row_offset;
int rows_below = screen_rows_below_line(*m_iterator) + std::min(0, rows_in_cursor_line - cursor_row_offset - 1);
int min_rows_to_leave_above = std::min(rows_above, so);
int min_rows_to_leave_below = std::min(rows_below, so);
m_cursor_screen_row = std::max(min_rows_to_leave_above, std::min(m_rows - min_rows_to_leave_below - 1, m_cursor_screen_row));
return cursor_row_offset;
}
void BufferPane::draw() void BufferPane::draw()
{ {
if (m_iterator->valid()) if (m_iterator->valid())

View File

@ -27,12 +27,11 @@ protected:
EOL, EOL,
}; };
#if 0
int effective_scroll_offset() int effective_scroll_offset()
{ {
return std::min(m_scroll_offset, (m_rows - 1) / 2); return std::min(m_scroll_offset, (m_rows - 1) / 2);
} }
void update_cursor_row(); #if 0
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor); void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
#endif #endif
int character_width(uint32_t character); int character_width(uint32_t character);
@ -42,6 +41,7 @@ protected:
int rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset); int rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset);
int screen_rows_below_line(const Buffer::Iterator & line); int screen_rows_below_line(const Buffer::Iterator & line);
int screen_rows_above_line(const Buffer::Iterator & line); int screen_rows_above_line(const Buffer::Iterator & line);
int update_cursor_row();
int col_x(int col) int col_x(int col)
{ {
return col * m_window->font()->get_advance(); return col * m_window->font()->get_advance();