make UserInterface unaware of Window, only of DisplayBuffer

This commit is contained in:
Maxime Coste 2012-10-20 20:15:20 +02:00
parent 48fe18ff0a
commit a0cca31dc1
5 changed files with 31 additions and 12 deletions

View File

@ -657,12 +657,14 @@ public:
bool has_key_left() const { return m_pos < m_keys.size(); }
void print_status(const String& , CharCount) override {}
void draw_window(Window&) override {}
void draw(const DisplayBuffer&, const String&) override {}
void menu_show(const memoryview<String>&,
const DisplayCoord&, MenuStyle) override {}
void menu_select(int) override {}
void menu_hide() override {}
DisplayCoord dimensions() override { return { 0, 0 }; }
private:
const KeyList& m_keys;
size_t m_pos;

View File

@ -94,7 +94,15 @@ struct Context
void draw_ifn() const
{
if (has_ui() and has_window())
ui().draw_window(window());
{
DisplayCoord dimensions = ui().dimensions();
if (dimensions == DisplayCoord{0,0})
return;
window().set_dimensions(dimensions);
window().update_display_buffer();;
ui().draw(window().display_buffer(), window().status_line());
}
}
void print_status(const String& status) const

View File

@ -1,6 +1,6 @@
#include "ncurses.hh"
#include "window.hh"
#include "display_buffer.hh"
#include "register_manager.hh"
#include "utf8_iterator.hh"
@ -113,18 +113,16 @@ void addutf8str(Utf8Iterator begin, Utf8Iterator end)
addch(*begin++);
}
void NCursesUI::draw_window(Window& window)
void NCursesUI::draw(const DisplayBuffer& display_buffer,
const String& status_line)
{
int max_x,max_y;
getmaxyx(stdscr, max_y, max_x);
max_y -= 1;
int status_y = max_y;
window.set_dimensions(DisplayCoord(LineCount(max_y), max_x));
window.update_display_buffer();
int line_index = 0;
for (const DisplayLine& line : window.display_buffer().lines())
for (const DisplayLine& line : display_buffer.lines())
{
move(line_index, 0);
clrtoeol();
@ -169,7 +167,6 @@ void NCursesUI::draw_window(Window& window)
}
set_color(Color::Cyan, Color::Black);
String status_line = window.status_line();
static int last_status_length = 0;
move(status_y, max_x - last_status_length);
clrtoeol();
@ -312,4 +309,11 @@ void NCursesUI::menu_hide()
m_items.clear();
}
DisplayCoord NCursesUI::dimensions()
{
int max_x,max_y;
getmaxyx(stdscr, max_y, max_x);
return {max_y - 1, max_x};
}
}

View File

@ -19,7 +19,8 @@ public:
NCursesUI(const NCursesUI&) = delete;
NCursesUI& operator=(const NCursesUI&) = delete;
void draw_window(Window& window) override;
void draw(const DisplayBuffer& display_buffer,
const String& status_line) override;
void print_status(const String& status, CharCount cursor_pos) override;
Key get_key() override;
@ -28,6 +29,8 @@ public:
const DisplayCoord& anchor, MenuStyle style) override;
void menu_select(int selected) override;
void menu_hide() override;
DisplayCoord dimensions() override;
private:
MENU* m_menu = nullptr;
WINDOW* m_menu_win = nullptr;

View File

@ -10,7 +10,7 @@ namespace Kakoune
{
class String;
class Window;
class DisplayBuffer;
class DisplayCoord;
enum class MenuStyle
@ -28,7 +28,9 @@ public:
const DisplayCoord& anchor, MenuStyle style) = 0;
virtual void menu_select(int selected) = 0;
virtual void menu_hide() = 0;
virtual void draw_window(Window& window) = 0;
virtual void draw(const DisplayBuffer& display_buffer,
const String& status_line) = 0;
virtual DisplayCoord dimensions() = 0;
virtual Key get_key() = 0;
};