Controller: Use string_view() for localised strings
This commit is contained in:
parent
057398b4ab
commit
32963c3f6a
|
@ -42,14 +42,14 @@ static constexpr std::array<const Controller::ControllerInfo*, static_cast<size_
|
|||
|
||||
const std::array<u32, NUM_CONTROLLER_AND_CARD_PORTS> Controller::PortDisplayOrder = {{0, 2, 3, 4, 1, 5, 6, 7}};
|
||||
|
||||
const char* Controller::ControllerInfo::GetDisplayName() const
|
||||
std::string_view Controller::ControllerInfo::GetDisplayName() const
|
||||
{
|
||||
return Host::TranslateToCString("ControllerType", display_name);
|
||||
return Host::TranslateToStringView("ControllerType", display_name);
|
||||
}
|
||||
|
||||
const char* Controller::ControllerInfo::GetBindingDisplayName(const ControllerBindingInfo& bi) const
|
||||
std::string_view Controller::ControllerInfo::GetBindingDisplayName(const ControllerBindingInfo& bi) const
|
||||
{
|
||||
return Host::TranslateToCString(name, bi.display_name);
|
||||
return Host::TranslateToStringView(name, bi.display_name);
|
||||
}
|
||||
|
||||
Controller::Controller(u32 index) : m_index(index)
|
||||
|
|
|
@ -43,10 +43,10 @@ public:
|
|||
std::span<const SettingInfo> settings;
|
||||
|
||||
/// Returns localized controller type name.
|
||||
const char* GetDisplayName() const;
|
||||
std::string_view GetDisplayName() const;
|
||||
|
||||
/// Returns localized controller type name.
|
||||
const char* GetBindingDisplayName(const ControllerBindingInfo& bi) const;
|
||||
std::string_view GetBindingDisplayName(const ControllerBindingInfo& bi) const;
|
||||
};
|
||||
|
||||
/// Default stick deadzone/sensitivity.
|
||||
|
|
|
@ -418,7 +418,7 @@ static void PopulatePostProcessingChain(SettingsInterface* si, const char* secti
|
|||
static void BeginVibrationMotorBinding(SettingsInterface* bsi, InputBindingInfo::Type type, const char* section,
|
||||
const char* key, std::string_view display_name);
|
||||
static void DrawInputBindingButton(SettingsInterface* bsi, InputBindingInfo::Type type, const char* section,
|
||||
const char* name, const char* display_name, const char* icon_name,
|
||||
const char* name, std::string_view display_name, std::string_view icon_name,
|
||||
bool show_type = true);
|
||||
static void StartAutomaticBindingForPort(u32 port);
|
||||
static void StartClearBindingsForPort(u32 port);
|
||||
|
@ -2466,7 +2466,7 @@ TinyString FullscreenUI::GetEffectiveTinyStringSetting(SettingsInterface* bsi, c
|
|||
}
|
||||
|
||||
void FullscreenUI::DrawInputBindingButton(SettingsInterface* bsi, InputBindingInfo::Type type, const char* section,
|
||||
const char* name, const char* display_name, const char* icon_name,
|
||||
const char* name, std::string_view display_name, std::string_view icon_name,
|
||||
bool show_type)
|
||||
{
|
||||
if (type == InputBindingInfo::Type::Pointer || type == InputBindingInfo::Type::RelativePointer)
|
||||
|
@ -2492,7 +2492,7 @@ void FullscreenUI::DrawInputBindingButton(SettingsInterface* bsi, InputBindingIn
|
|||
|
||||
if (show_type)
|
||||
{
|
||||
if (icon_name)
|
||||
if (!icon_name.empty())
|
||||
{
|
||||
title.format("{} {}", icon_name, display_name);
|
||||
}
|
||||
|
@ -2527,32 +2527,31 @@ void FullscreenUI::DrawInputBindingButton(SettingsInterface* bsi, InputBindingIn
|
|||
|
||||
if (oneline)
|
||||
{
|
||||
ImGui::PushFont(UIStyle.LargeFont);
|
||||
if (value.empty())
|
||||
value.assign(FSUI_VSTR("-"));
|
||||
|
||||
const ImVec2 value_size(ImGui::CalcTextSize(value.empty() ? FSUI_CSTR("-") : value.c_str(), nullptr));
|
||||
const ImVec2 value_size =
|
||||
UIStyle.LargeFont->CalcTextSizeA(UIStyle.LargeFont->FontSize, bb.Max.x - bb.Min.x, 0.0f, IMSTR_START_END(value));
|
||||
const float text_end = bb.Max.x - value_size.x;
|
||||
const ImRect title_bb(bb.Min, ImVec2(text_end, midpoint));
|
||||
|
||||
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, show_type ? title.c_str() : display_name, nullptr, nullptr,
|
||||
ImVec2(0.0f, 0.0f), &title_bb);
|
||||
ImGui::RenderTextClipped(bb.Min, bb.Max, value.empty() ? FSUI_CSTR("-") : value.c_str(), nullptr, &value_size,
|
||||
ImVec2(1.0f, 0.5f), &bb);
|
||||
ImGui::PopFont();
|
||||
RenderShadowedTextClipped(UIStyle.LargeFont, title_bb.Min, title_bb.Max, ImGui::GetColorU32(ImGuiCol_Text),
|
||||
show_type ? title.view() : display_name, nullptr, ImVec2(0.0f, 0.0f), 0.0f, &title_bb);
|
||||
RenderShadowedTextClipped(UIStyle.LargeFont, bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_Text),
|
||||
value.empty() ? FSUI_VSTR("-") : value.view(), &value_size, ImVec2(1.0f, 0.5f), 0.0f,
|
||||
&bb);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
|
||||
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
|
||||
|
||||
ImGui::PushFont(UIStyle.LargeFont);
|
||||
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, show_type ? title.c_str() : display_name, nullptr, nullptr,
|
||||
ImVec2(0.0f, 0.0f), &title_bb);
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::PushFont(UIStyle.MediumFont);
|
||||
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, value.empty() ? FSUI_CSTR("No Binding") : value.c_str(),
|
||||
nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
|
||||
ImGui::PopFont();
|
||||
RenderShadowedTextClipped(UIStyle.LargeFont, title_bb.Min, title_bb.Max, ImGui::GetColorU32(ImGuiCol_Text),
|
||||
show_type ? title.view() : display_name, nullptr, ImVec2(0.0f, 0.0f), 0.0f, &title_bb);
|
||||
RenderShadowedTextClipped(UIStyle.MediumFont, summary_bb.Min, summary_bb.Max,
|
||||
ImGui::GetColorU32(DarkerColor(ImGui::GetStyle().Colors[ImGuiCol_Text])),
|
||||
value.empty() ? FSUI_VSTR("No Binding") : value.view(), nullptr, ImVec2(0.0f, 0.0f), 0.0f,
|
||||
&summary_bb);
|
||||
}
|
||||
|
||||
if (clicked)
|
||||
|
@ -4958,12 +4957,12 @@ void FullscreenUI::DrawControllerSettingsPage()
|
|||
{
|
||||
for (const std::string_view& bind : StringUtil::SplitString(binds_string, '&', true))
|
||||
{
|
||||
const char* dispname = nullptr;
|
||||
std::string_view dispname;
|
||||
for (const Controller::ControllerBindingInfo& bi : ci->bindings)
|
||||
{
|
||||
if (bind == bi.name)
|
||||
{
|
||||
dispname = bi.icon_name ? bi.icon_name : ci->GetBindingDisplayName(bi);
|
||||
dispname = bi.icon_name ? std::string_view(bi.icon_name) : ci->GetBindingDisplayName(bi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ ControllerBindingWidget::~ControllerBindingWidget() = default;
|
|||
void ControllerBindingWidget::populateControllerTypes()
|
||||
{
|
||||
for (const Controller::ControllerInfo* cinfo : Controller::GetControllerInfoList())
|
||||
m_ui.controllerType->addItem(QString::fromUtf8(cinfo->GetDisplayName()), QVariant(static_cast<int>(cinfo->type)));
|
||||
m_ui.controllerType->addItem(QtUtils::StringViewToQString(cinfo->GetDisplayName()), QVariant(static_cast<int>(cinfo->type)));
|
||||
|
||||
m_controller_info = Controller::GetControllerInfo(
|
||||
m_dialog->getStringValue(m_config_section.c_str(), "Type",
|
||||
|
@ -503,7 +503,8 @@ void ControllerBindingWidget::createBindingWidgets(QWidget* parent)
|
|||
axis_layout = new QGridLayout(axis_gbox);
|
||||
}
|
||||
|
||||
QGroupBox* gbox = new QGroupBox(QString::fromUtf8(m_controller_info->GetBindingDisplayName(bi)), axis_gbox);
|
||||
QGroupBox* gbox =
|
||||
new QGroupBox(QtUtils::StringViewToQString(m_controller_info->GetBindingDisplayName(bi)), axis_gbox);
|
||||
QVBoxLayout* temp = new QVBoxLayout(gbox);
|
||||
QWidget* widget;
|
||||
if (bi.type != InputBindingInfo::Type::Motor)
|
||||
|
@ -537,7 +538,8 @@ void ControllerBindingWidget::createBindingWidgets(QWidget* parent)
|
|||
button_layout = new QGridLayout(button_gbox);
|
||||
}
|
||||
|
||||
QGroupBox* gbox = new QGroupBox(QString::fromUtf8(m_controller_info->GetBindingDisplayName(bi)), button_gbox);
|
||||
QGroupBox* gbox =
|
||||
new QGroupBox(QtUtils::StringViewToQString(m_controller_info->GetBindingDisplayName(bi)), button_gbox);
|
||||
QVBoxLayout* temp = new QVBoxLayout(gbox);
|
||||
InputBindingWidget* widget = new InputBindingWidget(gbox, sif, bi.type, getConfigSection(), bi.name);
|
||||
temp->addWidget(widget);
|
||||
|
@ -673,7 +675,7 @@ ControllerMacroEditWidget::ControllerMacroEditWidget(ControllerMacroWidget* pare
|
|||
continue;
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem();
|
||||
item->setText(QString::fromUtf8(cinfo->GetBindingDisplayName(bi)));
|
||||
item->setText(QtUtils::StringViewToQString(cinfo->GetBindingDisplayName(bi)));
|
||||
item->setCheckState((std::find(m_binds.begin(), m_binds.end(), &bi) != m_binds.end()) ? Qt::Checked :
|
||||
Qt::Unchecked);
|
||||
m_ui.bindList->addItem(item);
|
||||
|
|
|
@ -459,7 +459,8 @@ void ControllerSettingsWindow::createWidgets()
|
|||
m_port_bindings[global_slot] = new ControllerBindingWidget(m_ui.settingsContainer, this, global_slot);
|
||||
m_ui.settingsContainer->addWidget(m_port_bindings[global_slot]);
|
||||
|
||||
const QString display_name(QString::fromUtf8(m_port_bindings[global_slot]->getControllerInfo()->GetDisplayName()));
|
||||
const QString display_name(
|
||||
QtUtils::StringViewToQString(m_port_bindings[global_slot]->getControllerInfo()->GetDisplayName()));
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem();
|
||||
item->setText(tr("Controller Port %1\n%2")
|
||||
|
@ -509,7 +510,7 @@ void ControllerSettingsWindow::updateListDescription(u32 global_slot, Controller
|
|||
const std::array<bool, 2> mtap_enabled = getEnabledMultitaps();
|
||||
const auto [port, slot] = Controller::ConvertPadToPortAndSlot(global_slot);
|
||||
|
||||
const QString display_name = QString::fromUtf8(widget->getControllerInfo()->GetDisplayName());
|
||||
const QString display_name = QtUtils::StringViewToQString(widget->getControllerInfo()->GetDisplayName());
|
||||
|
||||
item->setText(tr("Controller Port %1\n%2")
|
||||
.arg(Controller::GetPortDisplayName(port, slot, mtap_enabled[port]))
|
||||
|
|
|
@ -416,7 +416,7 @@ void SetupWizardDialog::setupControllerPage(bool initial)
|
|||
const PadWidgets& w = pad_widgets[port];
|
||||
|
||||
for (const Controller::ControllerInfo* cinfo : Controller::GetControllerInfoList())
|
||||
w.type_combo->addItem(QString::fromUtf8(cinfo->GetDisplayName()), QString::fromUtf8(cinfo->name));
|
||||
w.type_combo->addItem(QtUtils::StringViewToQString(cinfo->GetDisplayName()), QString::fromUtf8(cinfo->name));
|
||||
|
||||
ControllerSettingWidgetBinder::BindWidgetToInputProfileString(
|
||||
nullptr, w.type_combo, section, "Type",
|
||||
|
|
Loading…
Reference in New Issue