aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform')
-rw-r--r--include/cru/platform/Check.hpp10
-rw-r--r--include/cru/platform/Resource.hpp2
-rw-r--r--include/cru/platform/graph/Factory.hpp4
-rw-r--r--include/cru/platform/graph/TextLayout.hpp6
-rw-r--r--include/cru/platform/native/InputMethod.hpp21
5 files changed, 14 insertions, 29 deletions
diff --git a/include/cru/platform/Check.hpp b/include/cru/platform/Check.hpp
index f4bbcfe8..d3180582 100644
--- a/include/cru/platform/Check.hpp
+++ b/include/cru/platform/Check.hpp
@@ -2,6 +2,8 @@
#include "Exception.hpp"
#include "Resource.hpp"
+#include "cru/common/StringUtil.hpp"
+
#include <fmt/format.h>
#include <memory>
#include <type_traits>
@@ -9,14 +11,14 @@
namespace cru::platform {
template <typename TTarget>
TTarget* CheckPlatform(INativeResource* resource,
- const std::string_view& target_platform) {
+ const std::u16string_view& target_platform) {
Expects(resource);
const auto result = dynamic_cast<TTarget*>(resource);
if (result == nullptr) {
throw UnsupportPlatformException(fmt::format(
"Try to convert resource to target platform failed. Platform id of "
"resource to convert: {} . Target platform id: {} .",
- resource->GetPlatformId(), target_platform));
+ ToUtf8(resource->GetPlatformId()), ToUtf8(target_platform)));
}
return result;
}
@@ -24,7 +26,7 @@ TTarget* CheckPlatform(INativeResource* resource,
template <typename TTarget, typename TSource>
std::shared_ptr<TTarget> CheckPlatform(
const std::shared_ptr<TSource>& resource,
- const std::string_view& target_platform) {
+ const std::u16string_view& target_platform) {
static_assert(std::is_base_of_v<INativeResource, TSource>,
"TSource must be a subclass of INativeResource.");
Expects(resource);
@@ -33,7 +35,7 @@ std::shared_ptr<TTarget> CheckPlatform(
throw UnsupportPlatformException(fmt::format(
"Try to convert resource to target platform failed. Platform id of "
"resource to convert: {} . Target platform id: {} .",
- resource->GetPlatformId(), target_platform));
+ ToUtf8(resource->GetPlatformId()), ToUtf8(target_platform)));
}
return result;
}
diff --git a/include/cru/platform/Resource.hpp b/include/cru/platform/Resource.hpp
index 72cfaf52..7a85d9c1 100644
--- a/include/cru/platform/Resource.hpp
+++ b/include/cru/platform/Resource.hpp
@@ -5,6 +5,6 @@
namespace cru::platform {
struct INativeResource : virtual Interface {
- virtual std::string_view GetPlatformId() const = 0;
+ virtual std::u16string_view GetPlatformId() const = 0;
};
} // namespace cru::platform
diff --git a/include/cru/platform/graph/Factory.hpp b/include/cru/platform/graph/Factory.hpp
index 0a425d15..b4e68f12 100644
--- a/include/cru/platform/graph/Factory.hpp
+++ b/include/cru/platform/graph/Factory.hpp
@@ -16,10 +16,10 @@ struct IGraphFactory : virtual INativeResource {
virtual std::unique_ptr<IGeometryBuilder> CreateGeometryBuilder() = 0;
- virtual std::unique_ptr<IFont> CreateFont(const std::string_view& font_family,
+ virtual std::unique_ptr<IFont> CreateFont(std::u16string font_family,
float font_size) = 0;
virtual std::unique_ptr<ITextLayout> CreateTextLayout(
- std::shared_ptr<IFont> font, std::string text) = 0;
+ std::shared_ptr<IFont> font, std::u16string text) = 0;
};
} // namespace cru::platform::graph
diff --git a/include/cru/platform/graph/TextLayout.hpp b/include/cru/platform/graph/TextLayout.hpp
index 4086ac56..7dd20987 100644
--- a/include/cru/platform/graph/TextLayout.hpp
+++ b/include/cru/platform/graph/TextLayout.hpp
@@ -6,8 +6,8 @@
namespace cru::platform::graph {
struct ITextLayout : virtual IGraphResource {
- virtual std::string GetText() = 0;
- virtual void SetText(std::string new_text) = 0;
+ virtual std::u16string GetText() = 0;
+ virtual void SetText(std::u16string new_text) = 0;
virtual std::shared_ptr<IFont> GetFont() = 0;
virtual void SetFont(std::shared_ptr<IFont> font) = 0;
@@ -17,7 +17,7 @@ struct ITextLayout : virtual IGraphResource {
virtual Rect GetTextBounds() = 0;
virtual std::vector<Rect> TextRangeRect(const TextRange& text_range) = 0;
- virtual Point TextSinglePoint(gsl::index position, bool trailing) = 0;
+ virtual Point TextSinglePoint(Index position, bool trailing) = 0;
virtual TextHitTestResult HitTest(const Point& point) = 0;
};
} // namespace cru::platform::graph
diff --git a/include/cru/platform/native/InputMethod.hpp b/include/cru/platform/native/InputMethod.hpp
index 1ede15b2..1c5b287e 100644
--- a/include/cru/platform/native/InputMethod.hpp
+++ b/include/cru/platform/native/InputMethod.hpp
@@ -18,28 +18,11 @@ struct CompositionClause {
using CompositionClauses = std::vector<CompositionClause>;
struct CompositionText {
- std::string text;
+ std::u16string text;
CompositionClauses clauses;
TextRange selection;
};
-inline std::ostream& operator<<(std::ostream& stream,
- const CompositionText& composition_text) {
- stream << "text: " << composition_text.text << "\n"
- << "clauses:\n";
- for (int i = 0; i < static_cast<int>(composition_text.clauses.size()); i++) {
- const auto& clause = composition_text.clauses[i];
- stream << "\t" << i << ". start:" << clause.start << " end:" << clause.end;
- if (clause.target) {
- stream << " target";
- }
- stream << "\n";
- }
- stream << "selection: position:" << composition_text.selection.position
- << " count:" << composition_text.selection.count;
- return stream;
-}
-
struct IInputMethodContext : virtual INativeResource {
// Return true if you should draw composition text manually. Return false if
// system will take care of that for you.
@@ -67,7 +50,7 @@ struct IInputMethodContext : virtual INativeResource {
// Triggered every time composition text changes.
virtual IEvent<std::nullptr_t>* CompositionEvent() = 0;
- virtual IEvent<std::string_view>* TextEvent() = 0;
+ virtual IEvent<std::u16string_view>* TextEvent() = 0;
};
struct IInputMethodManager : virtual INativeResource {