more work on BufferView

This commit is contained in:
Josh Holtrop 2017-05-07 19:52:21 -04:00
parent e243dd654c
commit 65df0c2320
2 changed files with 16 additions and 0 deletions

View File

@ -9,6 +9,8 @@ BufferView::BufferView(std::shared_ptr<Buffer> buffer,
{
m_width = 1;
m_height = 1;
m_scroll_offset = 0;
m_cursor_screen_row = 0;
}
void BufferView::resize(int width, int height)
@ -17,6 +19,11 @@ void BufferView::resize(int width, int height)
m_height = std::max(1, height);
}
void BufferView::set_scroll_offset(int scroll_offset)
{
m_scroll_offset = std::max(0, scroll_offset);
}
void BufferView::iter_cols(const Buffer::Iterator & start_of_line, std::function<void(int, int, int, int, const Buffer::Iterator &)> callback)
{
int row_offset = 0;

View File

@ -16,6 +16,8 @@ public:
std::shared_ptr<Buffer::Iterator> iterator,
CharacterWidthDeterminer & character_width_determiner);
void resize(int width, int height);
void set_scroll_offset(int scroll_offset);
void iter_lines(std::function<bool(const Buffer::Iterator &)> callback);
void iter_cols(const Buffer::Iterator & start_of_line, std::function<void(int, int, int, int, const Buffer::Iterator &)> callback);
protected:
@ -24,6 +26,13 @@ protected:
CharacterWidthDeterminer & m_character_width_determiner;
int m_width;
int m_height;
int m_scroll_offset;
int m_cursor_screen_row;
int effective_scroll_offset()
{
return std::min(m_scroll_offset, (m_height - 1) / 2);
}
};
#endif