Add an explicit refresh method to user interface

With this refresh method user interface can defer updating
the display until really needed.
This commit is contained in:
Maxime Coste 2014-04-15 19:19:44 +01:00
parent 98c6a6f17e
commit 7af9863e51
5 changed files with 33 additions and 6 deletions

View File

@ -91,6 +91,7 @@ void Client::redraw_ifn()
context().ui().draw(context().window().display_buffer(), context().ui().draw(context().window().display_buffer(),
m_status_line, generate_mode_line()); m_status_line, generate_mode_line());
} }
context().ui().refresh();
} }
static void reload_buffer(Context& context, const String& filename) static void reload_buffer(Context& context, const String& filename)

View File

@ -195,6 +195,14 @@ void NCursesUI::redraw()
} }
doupdate(); doupdate();
} }
void NCursesUI::refresh()
{
if (m_dirty)
redraw();
m_dirty = false;
}
using Utf8Policy = utf8::InvalidBytePolicy::Pass; using Utf8Policy = utf8::InvalidBytePolicy::Pass;
using Utf8Iterator = utf8::utf8_iterator<String::const_iterator, Utf8Policy>; using Utf8Iterator = utf8::utf8_iterator<String::const_iterator, Utf8Policy>;
void addutf8str(WINDOW* win, Utf8Iterator begin, Utf8Iterator end) void addutf8str(WINDOW* win, Utf8Iterator begin, Utf8Iterator end)
@ -301,7 +309,7 @@ void NCursesUI::draw(const DisplayBuffer& display_buffer,
printf("%s%s%s", tsl, title.c_str(), fsl); printf("%s%s%s", tsl, title.c_str(), fsl);
} }
redraw(); m_dirty = true;
} }
bool NCursesUI::is_key_available() bool NCursesUI::is_key_available()
@ -438,7 +446,7 @@ void NCursesUI::draw_menu()
wattron(m_menu_win, COLOR_PAIR(menu_bg)); wattron(m_menu_win, COLOR_PAIR(menu_bg));
waddstr(m_menu_win, is_mark ? "" : ""); waddstr(m_menu_win, is_mark ? "" : "");
} }
redraw(); m_dirty = true;
} }
void NCursesUI::menu_show(memoryview<String> items, void NCursesUI::menu_show(memoryview<String> items,
@ -520,7 +528,7 @@ void NCursesUI::menu_hide()
(int)window_size(m_menu_win).line); (int)window_size(m_menu_win).line);
delwin(m_menu_win); delwin(m_menu_win);
m_menu_win = nullptr; m_menu_win = nullptr;
redraw(); m_dirty = true;
} }
static DisplayCoord compute_needed_size(const String& str) static DisplayCoord compute_needed_size(const String& str)
@ -711,7 +719,7 @@ void NCursesUI::info_show(const String& title, const String& content,
break; break;
it = eol + 1; it = eol + 1;
} }
redraw(); m_dirty = true;
} }
void NCursesUI::info_hide() void NCursesUI::info_hide()
@ -722,7 +730,7 @@ void NCursesUI::info_hide()
(int)window_size(m_info_win).line); (int)window_size(m_info_win).line);
delwin(m_info_win); delwin(m_info_win);
m_info_win = nullptr; m_info_win = nullptr;
redraw(); m_dirty = true;
} }
DisplayCoord NCursesUI::dimensions() DisplayCoord NCursesUI::dimensions()

View File

@ -37,6 +37,8 @@ public:
MenuStyle style) override; MenuStyle style) override;
void info_hide() override; void info_hide() override;
void refresh() override;
void set_input_callback(InputCallback callback) override; void set_input_callback(InputCallback callback) override;
DisplayCoord dimensions() override; DisplayCoord dimensions() override;
@ -63,6 +65,8 @@ private:
FDWatcher m_stdin_watcher; FDWatcher m_stdin_watcher;
InputCallback m_input_callback; InputCallback m_input_callback;
bool m_dirty = false;
}; };
} }

View File

@ -25,7 +25,8 @@ enum class RemoteUIMsg
MenuHide, MenuHide,
InfoShow, InfoShow,
InfoHide, InfoHide,
Draw Draw,
Refresh
}; };
struct socket_error{}; struct socket_error{};
@ -256,6 +257,8 @@ public:
const DisplayLine& status_line, const DisplayLine& status_line,
const DisplayLine& mode_line) override; const DisplayLine& mode_line) override;
void refresh() override;
bool is_key_available() override; bool is_key_available() override;
Key get_key() override; Key get_key() override;
DisplayCoord dimensions() override; DisplayCoord dimensions() override;
@ -342,6 +345,12 @@ void RemoteUI::draw(const DisplayBuffer& display_buffer,
msg.write(mode_line); msg.write(mode_line);
} }
void RemoteUI::refresh()
{
Message msg(m_socket_watcher.fd());
msg.write(RemoteUIMsg::Refresh);
}
static const Key::Modifiers resize_modifier = (Key::Modifiers)0x80; static const Key::Modifiers resize_modifier = (Key::Modifiers)0x80;
bool RemoteUI::is_key_available() bool RemoteUI::is_key_available()
@ -466,6 +475,9 @@ void RemoteClient::process_next_message()
m_ui->draw(display_buffer, status_line, mode_line); m_ui->draw(display_buffer, status_line, mode_line);
break; break;
} }
case RemoteUIMsg::Refresh:
m_ui->refresh();
break;
} }
} }

View File

@ -45,6 +45,8 @@ public:
virtual bool is_key_available() = 0; virtual bool is_key_available() = 0;
virtual Key get_key() = 0; virtual Key get_key() = 0;
virtual void refresh() = 0;
virtual void set_input_callback(InputCallback callback) = 0; virtual void set_input_callback(InputCallback callback) = 0;
}; };