[App] Build title using StringBuffer.

This commit is contained in:
gibbed 2021-05-01 17:15:41 -05:00 committed by Rick Gibbed
parent 38c3db1afb
commit 0419a9f13d
6 changed files with 28 additions and 17 deletions

View File

@ -430,31 +430,40 @@ void EmulatorWindow::ShowCommitID() {
}
void EmulatorWindow::UpdateTitle() {
std::string title(base_title_);
xe::StringBuffer sb;
sb.Append(base_title_);
// Title information, if available
if (emulator()->is_title_open()) {
auto game_title = emulator()->game_title();
title += fmt::format(" | [{:08X}] {}", emulator()->title_id(), game_title);
sb.AppendFormat(u8" | [{:08X}]", emulator()->title_id());
auto title_name = emulator()->title_name();
if (!title_name.empty()) {
sb.Append(u8" ");
sb.Append(title_name);
}
}
// Graphics system name, if available
auto graphics_system = emulator()->graphics_system();
if (graphics_system) {
auto graphics_name = graphics_system->name();
title += fmt::format(" <{}>", graphics_name);
if (!graphics_name.empty()) {
sb.Append(u8" <");
sb.Append(graphics_name);
sb.Append(u8">");
}
}
if (Clock::guest_time_scalar() != 1.0) {
title += fmt::format(" (@{:.2f}x)", Clock::guest_time_scalar());
sb.AppendFormat(u8" (@{:.2f}x)", Clock::guest_time_scalar());
}
if (initializing_shader_storage_) {
title +=
" (Preloading shaders"
u8"\u2026"
")";
sb.Append(u8" (Preloading shaders\u2026)");
}
window_->set_title(title);
window_->set_title(sb.to_string_view());
}
void EmulatorWindow::SetInitializingShaderStorage(bool initializing) {

View File

@ -48,7 +48,7 @@ class Window {
virtual void DisableMainMenu() = 0;
const std::string& title() const { return title_; }
virtual bool set_title(const std::string& title) {
virtual bool set_title(const std::string_view title) {
if (title == title_) {
return false;
}

View File

@ -99,11 +99,12 @@ void GTKWindow::OnClose() {
super::OnClose();
}
bool GTKWindow::set_title(const std::string& title) {
bool GTKWindow::set_title(const std::string_view title) {
if (!super::set_title(title)) {
return false;
}
gtk_window_set_title(GTK_WINDOW(window_), (gchar*)title.c_str());
std::string titlez(title);
gtk_window_set_title(GTK_WINDOW(window_), (gchar*)titlez.c_str());
return true;
}

View File

@ -38,7 +38,7 @@ class GTKWindow : public Window {
void EnableMainMenu() override {}
void DisableMainMenu() override {}
bool set_title(const std::string& title) override;
bool set_title(const std::string_view title) override;
bool SetIcon(const void* buffer, size_t size) override;

View File

@ -199,11 +199,12 @@ void Win32Window::DisableMainMenu() {
}
}
bool Win32Window::set_title(const std::string& title) {
bool Win32Window::set_title(const std::string_view title) {
if (!super::set_title(title)) {
return false;
}
SetWindowTextW(hwnd_, reinterpret_cast<LPCWSTR>(xe::to_utf16(title).c_str()));
auto wide_title = xe::to_utf16(title);
SetWindowTextW(hwnd_, reinterpret_cast<LPCWSTR>(wide_title.c_str()));
return true;
}

View File

@ -34,7 +34,7 @@ class Win32Window : public Window {
void EnableMainMenu() override;
void DisableMainMenu() override;
bool set_title(const std::string& title) override;
bool set_title(const std::string_view title) override;
bool SetIcon(const void* buffer, size_t size) override;