From 5c805e494425a88da1813902b1ad8a1ab351e30d Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 5 Jul 2020 23:06:02 +0800 Subject: ... --- include/cru/platform/Check.hpp | 10 ++++++---- include/cru/platform/Resource.hpp | 2 +- include/cru/platform/graph/Factory.hpp | 4 ++-- include/cru/platform/graph/TextLayout.hpp | 6 +++--- include/cru/platform/native/InputMethod.hpp | 21 ++------------------- 5 files changed, 14 insertions(+), 29 deletions(-) (limited to 'include/cru/platform') 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 #include #include @@ -9,14 +11,14 @@ namespace cru::platform { template TTarget* CheckPlatform(INativeResource* resource, - const std::string_view& target_platform) { + const std::u16string_view& target_platform) { Expects(resource); const auto result = dynamic_cast(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 std::shared_ptr CheckPlatform( const std::shared_ptr& resource, - const std::string_view& target_platform) { + const std::u16string_view& target_platform) { static_assert(std::is_base_of_v, "TSource must be a subclass of INativeResource."); Expects(resource); @@ -33,7 +35,7 @@ std::shared_ptr 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 CreateGeometryBuilder() = 0; - virtual std::unique_ptr CreateFont(const std::string_view& font_family, + virtual std::unique_ptr CreateFont(std::u16string font_family, float font_size) = 0; virtual std::unique_ptr CreateTextLayout( - std::shared_ptr font, std::string text) = 0; + std::shared_ptr 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 GetFont() = 0; virtual void SetFont(std::shared_ptr font) = 0; @@ -17,7 +17,7 @@ struct ITextLayout : virtual IGraphResource { virtual Rect GetTextBounds() = 0; virtual std::vector 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; 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(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* CompositionEvent() = 0; - virtual IEvent* TextEvent() = 0; + virtual IEvent* TextEvent() = 0; }; struct IInputMethodManager : virtual INativeResource { -- cgit v1.2.3