overlays: More unicode utilities

This commit is contained in:
kd-11 2020-02-20 21:14:13 +03:00 committed by kd-11
parent 19350d024b
commit 703ec9f896
4 changed files with 28 additions and 17 deletions

View File

@ -437,9 +437,9 @@ namespace rsx
is_compiled = false;
}
virtual void set_text(const char* text)
virtual void set_text(const std::wstring& text)
{
this->text = utf8_to_wstring(text);
this->text = text;
is_compiled = false;
}
@ -1003,7 +1003,6 @@ namespace rsx
void set_pos(u16 _x, u16 _y) override;
void set_size(u16 _w, u16 _h) override;
void translate(s16 dx, s16 dy) override;
void set_text(const char* str) override;
void set_text(const std::string& str) override;
compiled_resource& get_compiled() override;
@ -1061,7 +1060,7 @@ namespace rsx
using label::label;
void move_caret(direction dir);
void insert_text(const std::string& str);
void insert_text(const std::wstring& str);
void erase();
compiled_resource& get_compiled() override;

View File

@ -58,19 +58,6 @@ namespace rsx
set_pos(x + dx, y + dy);
}
void progress_bar::set_text(const char* str)
{
text_view.set_text(str);
text_view.align_text(text_align::center);
u16 text_w, text_h;
text_view.measure_text(text_w, text_h);
text_view.set_size(w, text_h);
set_pos(text_view.x, text_view.y);
is_compiled = false;
}
void progress_bar::set_text(const std::string& str)
{
text_view.set_text(str);

View File

@ -1,4 +1,8 @@
#pragma once
#include "Utilities/types.h"
#include "Utilities/geometry.h"
#include <string>
struct vertex
{
@ -152,3 +156,4 @@ std::string utf16_to_ascii8(const std::u16string& utf16_string);
std::u16string ascii8_to_utf16(const std::string& ascii_string);
std::wstring utf8_to_wstring(const std::string& utf8_string);
std::u16string wstring_to_utf16(const std::wstring& w_string);
std::wstring utf16_to_wstring(const std::u16string& utf16_string);

View File

@ -200,6 +200,26 @@ std::u16string wstring_to_utf16(const std::wstring& w_string)
}
}
std::wstring utf16_to_wstring(const std::u16string& utf16_string)
{
if constexpr (sizeof(wchar_t) == sizeof(char16_t))
{
return reinterpret_cast<const wchar_t*>(utf16_string.data());
}
else
{
std::wstring result;
result.reserve(utf16_string.size());
for (const auto& code : utf16_string)
{
result.push_back(code);
}
return result;
}
}
namespace rsx
{
namespace overlays