overlays/osk: clear on enter

This commit is contained in:
Megamouse 2023-01-24 01:15:35 +01:00
parent 3d99fea575
commit fb974a4551
6 changed files with 34 additions and 12 deletions

View File

@ -746,7 +746,7 @@ error_code getText(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo, bool is
std::lock_guard lock(info.text_mtx);
info.valid_text = {};
osk->Clear();
osk->Clear(true);
break;
}
default:

View File

@ -301,7 +301,7 @@ public:
};
virtual void Create(const osk_params& params) = 0;
virtual void Clear() = 0;
virtual void Clear(bool clear_all_data) = 0;
// Closes the dialog.
// Set status to CELL_OSKDIALOG_CLOSE_CONFIRM or CELL_OSKDIALOG_CLOSE_CANCEL for user input.

View File

@ -24,6 +24,8 @@ namespace rsx
void osk_dialog::Close(s32 status)
{
osk.notice("Closing osk (status=%d)", status);
if (status == FAKE_CELL_OSKDIALOG_CLOSE_TERMINATE)
{
close(false, true);
@ -63,19 +65,37 @@ namespace rsx
if (!m_use_separate_windows || continuous_mode == CELL_OSKDIALOG_CONTINUOUS_MODE_NONE)
{
close(true, true);
return;
}
// Clear text edit in continuous separate window mode. Keep actual data just in case.
Clear(false);
};
fade_animation.active = true;
}
void osk_dialog::Clear()
void osk_dialog::Clear(bool clear_all_data)
{
std::lock_guard lock(m_preview_mutex);
osk.notice("Clearing osk (clear_all_data=%d)", clear_all_data);
// Try to lock. Clear might be called recursively.
const bool locked = m_preview_mutex.try_lock();
m_preview.caret_position = 0;
m_preview.value.clear();
on_text_changed();
m_preview.set_text({});
if (clear_all_data)
{
on_text_changed();
}
if (locked)
{
m_preview_mutex.unlock();
}
m_update = true;
}
void osk_dialog::add_panel(const osk_panel& panel)
@ -961,10 +981,12 @@ namespace rsx
void osk_dialog::on_text_changed()
{
const auto ws = u32string_to_utf16(m_preview.value);
const std::u16string ws = u32string_to_utf16(m_preview.value);
const usz length = std::min(osk_text.size(), ws.length() + 1) * sizeof(char16_t);
memcpy(osk_text.data(), ws.c_str(), length);
osk.notice("on_text_changed: osk_text='%s'", utf16_to_ascii8(ws));
// Muted contrast for placeholder text
m_preview.fore_color.a = m_preview.value.empty() ? 0.5f : 1.f;

View File

@ -107,7 +107,7 @@ namespace rsx
void Create(const osk_params& params) override;
void Close(s32 status) override;
void Clear() override;
void Clear(bool clear_all_data) override;
void initialize_layout(const std::u32string& title, const std::u32string& initial_text);
void add_panel(const osk_panel& panel);

View File

@ -182,7 +182,7 @@ void osk_dialog_frame::Create(const osk_params& params)
void osk_dialog_frame::SetOskText(const QString& text)
{
std::memcpy(osk_text.data(), utils::bless<char16_t>(text.constData()), std::min(osk_text.size(), text.size() + 1ull) * sizeof(char16_t));
std::memcpy(osk_text.data(), utils::bless<char16_t>(text.constData()), std::min(osk_text.size(), text.size() + usz{1}) * sizeof(char16_t));
}
void osk_dialog_frame::Close(s32 status)
@ -204,9 +204,9 @@ void osk_dialog_frame::Close(s32 status)
}
}
void osk_dialog_frame::Clear()
void osk_dialog_frame::Clear(bool clear_all_data)
{
if (m_dialog)
if (m_dialog && clear_all_data)
{
SetOskText("");
}

View File

@ -18,7 +18,7 @@ public:
~osk_dialog_frame();
void Create(const osk_params& params) override;
void Close(s32 status) override;
void Clear() override;
void Clear(bool clear_all_data) override;
private:
void SetOskText(const QString& text);