expand command buffer to multiple lines as command length grows

This commit is contained in:
Josh Holtrop 2017-01-19 21:06:20 -05:00
parent 2ecee3f09a
commit 3cd988bc3a
3 changed files with 18 additions and 6 deletions

View File

@ -35,6 +35,7 @@ public:
m_focused = focused;
}
void clear();
int calculate_rows_in_line(const Buffer::Iterator & start_of_line);
protected:
int effective_scroll_offset()
@ -46,7 +47,6 @@ protected:
int character_width(uint32_t character);
void draw_buffer_character(int screen_column, int screen_row, uint32_t character);
void draw_cursor(int x, int y, int i, int columns);
int calculate_rows_in_line(const Buffer::Iterator & start_of_line);
int calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line);
int calculate_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);

View File

@ -144,6 +144,7 @@ bool Window::create(std::shared_ptr<Buffer> buffer)
m_command_buffer = std::make_shared<Buffer>();
m_command_buffer_pane = std::make_shared<BufferPane>(this, m_command_buffer);
m_command_buffer_pane->set_command_mode();
m_command_buffer_screen_rows = 1;
resize();
@ -294,6 +295,7 @@ void Window::handle_keyval(uint32_t keyval)
if (m_focused_buffer_pane == m_command_buffer_pane)
{
m_command_buffer_pane->clear();
m_command_buffer_screen_rows = 1;
change_focus(m_buffer_pane);
}
else
@ -307,6 +309,7 @@ void Window::handle_keyval(uint32_t keyval)
{
std::string command = m_command_buffer->get_string();
m_command_buffer_pane->clear();
m_command_buffer_screen_rows = 1;
change_focus(m_buffer_pane);
}
else
@ -409,19 +412,27 @@ void Window::resize()
SDL_GetWindowSize(m_window, &m_width, &m_height);
glViewport(0, 0, m_width, m_height);
m_gl->resize(m_width, m_height);
int line_height = m_font->get_line_height();
m_buffer_pane->move(0, line_height + 1);
m_buffer_pane->resize(m_width, m_height - line_height - 1);
m_command_buffer_pane->resize(m_width, line_height);
int command_buffer_height = m_command_buffer_screen_rows * m_font->get_line_height();
m_buffer_pane->move(0, command_buffer_height + 1);
m_buffer_pane->resize(m_width, m_height - command_buffer_height - 1);
m_command_buffer_pane->resize(m_width, command_buffer_height);
m_command_buffer_pane->move(0, 0);
}
void Window::redraw()
{
static int last_command_buffer_screen_rows = 0;
m_command_buffer_screen_rows = std::min(5, m_command_buffer_pane->calculate_rows_in_line(m_command_buffer->begin()));
if (m_command_buffer_screen_rows != last_command_buffer_screen_rows)
{
resize();
}
last_command_buffer_screen_rows = m_command_buffer_screen_rows;
glClear(GL_COLOR_BUFFER_BIT);
m_buffer_pane->draw();
m_gl->draw_rect(0, m_font->get_line_height(), m_width, 1, 0.5, 0.5, 0.5, 1.0);
m_gl->draw_rect(0, m_command_buffer_screen_rows * m_font->get_line_height(), m_width, 1, 0.5, 0.5, 0.5, 1.0);
m_command_buffer_pane->draw();
SDL_GL_SwapWindow(m_window);

View File

@ -80,6 +80,7 @@ protected:
bool m_redraw_requested;
int m_width;
int m_height;
int m_command_buffer_screen_rows;
std::shared_ptr<Font> m_font;
uint32_t m_target_column;