window: support scrolling

This commit is contained in:
Maxime Coste 2011-09-05 18:55:31 +00:00
parent 04c7ce8f01
commit d5012c9379
3 changed files with 30 additions and 2 deletions

View File

@ -11,12 +11,14 @@ using namespace Kakoune;
void draw_window(Window& window) void draw_window(Window& window)
{ {
window.update_display_buffer();
int max_x,max_y; int max_x,max_y;
getmaxyx(stdscr, max_y, max_x); getmaxyx(stdscr, max_y, max_x);
max_y -= 1; max_y -= 1;
window.set_dimensions(LineAndColumn(max_y, max_x));
window.update_display_buffer();
LineAndColumn position; LineAndColumn position;
for (const DisplayAtom& atom : window.display_buffer()) for (const DisplayAtom& atom : window.display_buffer())
{ {

View File

@ -170,4 +170,29 @@ void Window::set_dimensions(const LineAndColumn& dimensions)
m_dimensions = dimensions; m_dimensions = dimensions;
} }
void Window::scroll_to_keep_cursor_visible_ifn()
{
if (m_cursor.line < 0)
{
m_position.line = std::max(m_position.line + m_cursor.line, 0);
m_cursor.line = 0;
}
else if (m_cursor.line >= m_dimensions.line)
{
m_position.line += m_cursor.line - (m_dimensions.line - 1);
m_cursor.line = m_dimensions.line - 1;
}
if (m_cursor.column < 0)
{
m_position.column = std::max(m_position.column + m_cursor.column, 0);
m_cursor.column = 0;
}
else if (m_cursor.column >= m_dimensions.column)
{
m_position.column += m_cursor.column - (m_dimensions.column - 1);
m_cursor.column = m_dimensions.column - 1;
}
}
} }

View File

@ -57,6 +57,7 @@ public:
void update_display_buffer(); void update_display_buffer();
private: private:
void scroll_to_keep_cursor_visible_ifn();
std::shared_ptr<Buffer> m_buffer; std::shared_ptr<Buffer> m_buffer;
LineAndColumn m_position; LineAndColumn m_position;