mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-26 04:32:35 +01:00
overlays: fix osk placeholder
This commit is contained in:
parent
fc9b3c13e6
commit
088d22675b
@ -468,7 +468,7 @@ namespace rsx
|
|||||||
is_compiled = false;
|
is_compiled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_text(const std::u32string& text)
|
virtual void set_unicode_text(const std::u32string& text)
|
||||||
{
|
{
|
||||||
this->text = text;
|
this->text = text;
|
||||||
is_compiled = false;
|
is_compiled = false;
|
||||||
@ -476,7 +476,7 @@ namespace rsx
|
|||||||
|
|
||||||
void set_text(localized_string_id id)
|
void set_text(localized_string_id id)
|
||||||
{
|
{
|
||||||
set_text(get_localized_u32string(id));
|
set_unicode_text(get_localized_u32string(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void set_font(const char* font_name, u16 font_size)
|
virtual void set_font(const char* font_name, u16 font_size)
|
||||||
@ -1101,10 +1101,18 @@ namespace rsx
|
|||||||
u16 caret_position = 0;
|
u16 caret_position = 0;
|
||||||
u16 vertical_scroll_offset = 0;
|
u16 vertical_scroll_offset = 0;
|
||||||
|
|
||||||
bool m_reset_caret_pulse = 0;
|
bool m_reset_caret_pulse = false;
|
||||||
|
|
||||||
|
std::u32string value;
|
||||||
|
std::u32string placeholder;
|
||||||
|
|
||||||
using label::label;
|
using label::label;
|
||||||
|
|
||||||
|
void set_text(const std::string& text) override;
|
||||||
|
void set_unicode_text(const std::u32string& text) override;
|
||||||
|
|
||||||
|
void set_placeholder(const std::u32string& placeholder_text);
|
||||||
|
|
||||||
void move_caret(direction dir);
|
void move_caret(direction dir);
|
||||||
void insert_text(const std::u32string& str);
|
void insert_text(const std::u32string& str);
|
||||||
void erase();
|
void erase();
|
||||||
|
@ -46,7 +46,7 @@ namespace rsx
|
|||||||
}
|
}
|
||||||
case direction::right:
|
case direction::right:
|
||||||
{
|
{
|
||||||
if (caret_position < text.length())
|
if (caret_position < value.length())
|
||||||
{
|
{
|
||||||
caret_position++;
|
caret_position++;
|
||||||
refresh();
|
refresh();
|
||||||
@ -55,7 +55,7 @@ namespace rsx
|
|||||||
}
|
}
|
||||||
case direction::up:
|
case direction::up:
|
||||||
{
|
{
|
||||||
const usz current_line_start = get_line_start(text, caret_position);
|
const usz current_line_start = get_line_start(value, caret_position);
|
||||||
if (current_line_start == 0)
|
if (current_line_start == 0)
|
||||||
{
|
{
|
||||||
// This is the first line, so caret moves to the very beginning
|
// This is the first line, so caret moves to the very beginning
|
||||||
@ -65,7 +65,7 @@ namespace rsx
|
|||||||
}
|
}
|
||||||
const usz caret_pos_in_line = caret_position - current_line_start;
|
const usz caret_pos_in_line = caret_position - current_line_start;
|
||||||
const usz prev_line_end = current_line_start - 1;
|
const usz prev_line_end = current_line_start - 1;
|
||||||
const usz prev_line_start = get_line_start(text, prev_line_end);
|
const usz prev_line_start = get_line_start(value, prev_line_end);
|
||||||
// TODO : Save caret position to some kind of buffer, so after switching back and forward, caret would be on initial position
|
// TODO : Save caret position to some kind of buffer, so after switching back and forward, caret would be on initial position
|
||||||
caret_position = std::min(prev_line_end, prev_line_start + caret_pos_in_line);
|
caret_position = std::min(prev_line_end, prev_line_start + caret_pos_in_line);
|
||||||
|
|
||||||
@ -74,18 +74,18 @@ namespace rsx
|
|||||||
}
|
}
|
||||||
case direction::down:
|
case direction::down:
|
||||||
{
|
{
|
||||||
const usz current_line_end = get_line_end(text, caret_position);
|
const usz current_line_end = get_line_end(value, caret_position);
|
||||||
if (current_line_end == text.length())
|
if (current_line_end == value.length())
|
||||||
{
|
{
|
||||||
// This is the last line, so caret moves to the very end
|
// This is the last line, so caret moves to the very end
|
||||||
caret_position = current_line_end;
|
caret_position = current_line_end;
|
||||||
refresh();
|
refresh();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const usz current_line_start = get_line_start(text, caret_position);
|
const usz current_line_start = get_line_start(value, caret_position);
|
||||||
const usz caret_pos_in_line = caret_position - current_line_start;
|
const usz caret_pos_in_line = caret_position - current_line_start;
|
||||||
const usz next_line_start = current_line_end + 1;
|
const usz next_line_start = current_line_end + 1;
|
||||||
const usz next_line_end = get_line_end(text, next_line_start);
|
const usz next_line_end = get_line_end(value, next_line_start);
|
||||||
// TODO : Save caret position to some kind of buffer, so after switching back and forward, caret would be on initial position
|
// TODO : Save caret position to some kind of buffer, so after switching back and forward, caret would be on initial position
|
||||||
caret_position = std::min(next_line_end, next_line_start + caret_pos_in_line);
|
caret_position = std::min(next_line_end, next_line_start + caret_pos_in_line);
|
||||||
|
|
||||||
@ -95,26 +95,51 @@ namespace rsx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void edit_text::set_text(const std::string& text)
|
||||||
|
{
|
||||||
|
set_unicode_text(utf8_to_u32string(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
void edit_text::set_unicode_text(const std::u32string& text)
|
||||||
|
{
|
||||||
|
value = text;
|
||||||
|
|
||||||
|
if (value.empty())
|
||||||
|
{
|
||||||
|
overlay_element::set_unicode_text(placeholder);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
overlay_element::set_unicode_text(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void edit_text::set_placeholder(const std::u32string& placeholder_text)
|
||||||
|
{
|
||||||
|
placeholder = placeholder_text;
|
||||||
|
}
|
||||||
|
|
||||||
void edit_text::insert_text(const std::u32string& str)
|
void edit_text::insert_text(const std::u32string& str)
|
||||||
{
|
{
|
||||||
if (caret_position == 0)
|
if (caret_position == 0)
|
||||||
{
|
{
|
||||||
// Start
|
// Start
|
||||||
text = str + text;
|
value = str + text;
|
||||||
}
|
}
|
||||||
else if (caret_position == text.length())
|
else if (caret_position == text.length())
|
||||||
{
|
{
|
||||||
// End
|
// End
|
||||||
text += str;
|
value += str;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Middle
|
// Middle
|
||||||
text.insert(caret_position, str);
|
value.insert(caret_position, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
caret_position += ::narrow<u16>(str.length());
|
caret_position += ::narrow<u16>(str.length());
|
||||||
m_reset_caret_pulse = true;
|
m_reset_caret_pulse = true;
|
||||||
|
set_unicode_text(value);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,19 +152,20 @@ namespace rsx
|
|||||||
|
|
||||||
if (caret_position == 1)
|
if (caret_position == 1)
|
||||||
{
|
{
|
||||||
text = text.length() > 1 ? text.substr(1) : U"";
|
value = value.length() > 1 ? value.substr(1) : U"";
|
||||||
}
|
}
|
||||||
else if (caret_position == text.length())
|
else if (caret_position == text.length())
|
||||||
{
|
{
|
||||||
text = text.substr(0, caret_position - 1);
|
value = value.substr(0, caret_position - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
text = text.substr(0, caret_position - 1) + text.substr(caret_position);
|
value = value.substr(0, caret_position - 1) + value.substr(caret_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
caret_position--;
|
caret_position--;
|
||||||
m_reset_caret_pulse = true;
|
m_reset_caret_pulse = true;
|
||||||
|
set_unicode_text(value);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,26 +250,27 @@ namespace rsx
|
|||||||
m_update = true;
|
m_update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void osk_dialog::initialize_layout(const std::u32string & title, const std::u32string & initial_text)
|
void osk_dialog::initialize_layout(const std::u32string& title, const std::u32string& initial_text)
|
||||||
{
|
{
|
||||||
m_background.set_size(1280, 720);
|
m_background.set_size(1280, 720);
|
||||||
m_background.back_color.a = 0.8f;
|
m_background.back_color.a = 0.8f;
|
||||||
|
|
||||||
m_frame.back_color = { 0.2f, 0.2f, 0.2f, 1.f };
|
m_frame.back_color = { 0.2f, 0.2f, 0.2f, 1.f };
|
||||||
|
|
||||||
m_title.set_text(title);
|
m_title.set_unicode_text(title);
|
||||||
m_title.back_color.a = 0.f;
|
m_title.back_color.a = 0.f;
|
||||||
|
|
||||||
if (initial_text.empty())
|
m_preview.set_placeholder(get_placeholder());
|
||||||
|
m_preview.set_unicode_text(initial_text);
|
||||||
|
|
||||||
|
if (m_preview.value.empty())
|
||||||
{
|
{
|
||||||
m_preview.set_text(get_placeholder());
|
|
||||||
m_preview.caret_position = 0;
|
m_preview.caret_position = 0;
|
||||||
m_preview.fore_color.a = 0.5f; // Muted contrast for hint text
|
m_preview.fore_color.a = 0.5f; // Muted contrast for hint text
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_preview.set_text(initial_text);
|
m_preview.caret_position = ::narrow<u16>(m_preview.value.length());
|
||||||
m_preview.caret_position = ::narrow<u16>(initial_text.length());
|
|
||||||
m_preview.fore_color.a = 1.f;
|
m_preview.fore_color.a = 1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,14 +344,12 @@ namespace rsx
|
|||||||
{
|
{
|
||||||
const auto current_index = (start_index + count);
|
const auto current_index = (start_index + count);
|
||||||
ensure(current_index <= index_limit);
|
ensure(current_index <= index_limit);
|
||||||
|
++count;
|
||||||
|
|
||||||
if (m_grid[current_index].flags & border_flags::right)
|
if (m_grid[current_index].flags & border_flags::right)
|
||||||
{
|
{
|
||||||
++count;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
++count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_pair(start_index, count);
|
return std::make_pair(start_index, count);
|
||||||
@ -559,7 +558,7 @@ namespace rsx
|
|||||||
|
|
||||||
void osk_dialog::on_text_changed()
|
void osk_dialog::on_text_changed()
|
||||||
{
|
{
|
||||||
const auto ws = u32string_to_utf16(m_preview.text);
|
const auto ws = u32string_to_utf16(m_preview.value);
|
||||||
const auto length = (ws.length() + 1) * sizeof(char16_t);
|
const auto length = (ws.length() + 1) * sizeof(char16_t);
|
||||||
memcpy(osk_text, ws.c_str(), length);
|
memcpy(osk_text, ws.c_str(), length);
|
||||||
|
|
||||||
@ -568,6 +567,9 @@ namespace rsx
|
|||||||
on_osk_input_entered();
|
on_osk_input_entered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Muted contrast for placeholder text
|
||||||
|
m_preview.fore_color.a = m_preview.value.empty() ? 0.5f : 1.f;
|
||||||
|
|
||||||
m_update = true;
|
m_update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,20 +581,19 @@ namespace rsx
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Append to output text
|
// Append to output text
|
||||||
if (m_preview.text == get_placeholder())
|
if (m_preview.value.empty())
|
||||||
{
|
{
|
||||||
m_preview.caret_position = ::narrow<u16>(str.length());
|
m_preview.caret_position = ::narrow<u16>(str.length());
|
||||||
m_preview.set_text(str);
|
m_preview.set_unicode_text(str);
|
||||||
m_preview.fore_color.a = 1.f;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_preview.text.length() == char_limit)
|
if (m_preview.value.length() == char_limit)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto new_str = m_preview.text + str;
|
const auto new_str = m_preview.value + str;
|
||||||
if (new_str.length() <= char_limit)
|
if (new_str.length() <= char_limit)
|
||||||
{
|
{
|
||||||
m_preview.insert_text(str);
|
m_preview.insert_text(str);
|
||||||
@ -641,12 +642,6 @@ namespace rsx
|
|||||||
void osk_dialog::on_backspace(const std::u32string&)
|
void osk_dialog::on_backspace(const std::u32string&)
|
||||||
{
|
{
|
||||||
m_preview.erase();
|
m_preview.erase();
|
||||||
|
|
||||||
if (m_preview.text.empty())
|
|
||||||
{
|
|
||||||
m_preview.set_text(get_placeholder());
|
|
||||||
}
|
|
||||||
|
|
||||||
on_text_changed();
|
on_text_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -752,7 +747,7 @@ namespace rsx
|
|||||||
m_label.fore_color = c.enabled ? normal_fore_color : disabled_fore_color;
|
m_label.fore_color = c.enabled ? normal_fore_color : disabled_fore_color;
|
||||||
|
|
||||||
const auto _z = (selected_z < output_count) ? selected_z : output_count - 1u;
|
const auto _z = (selected_z < output_count) ? selected_z : output_count - 1u;
|
||||||
m_label.set_text(c.outputs[m_selected_charset][_z]);
|
m_label.set_unicode_text(c.outputs[m_selected_charset][_z]);
|
||||||
m_label.align_text(rsx::overlays::overlay_element::text_align::center);
|
m_label.align_text(rsx::overlays::overlay_element::text_align::center);
|
||||||
render_label = true;
|
render_label = true;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ namespace rsx
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
text_view.set_text(get_localized_u32string(string_id, trophy.name));
|
text_view.set_unicode_text(get_localized_u32string(string_id, trophy.name));
|
||||||
text_view.auto_resize();
|
text_view.auto_resize();
|
||||||
|
|
||||||
// Resize background to cover the text
|
// Resize background to cover the text
|
||||||
|
Loading…
Reference in New Issue
Block a user