diff options
author | crupest <crupest@outlook.com> | 2020-07-08 16:06:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-08 16:06:25 +0800 |
commit | 47b976c02c0960111165633d1331adc8fe07abfd (patch) | |
tree | a9094eb755ce3bdf17e44dd06622346efcac5c60 /include | |
parent | b0ca583b6b46c866f9541352e73ca2361d7e398b (diff) | |
download | cru-47b976c02c0960111165633d1331adc8fe07abfd.tar.gz cru-47b976c02c0960111165633d1331adc8fe07abfd.tar.bz2 cru-47b976c02c0960111165633d1331adc8fe07abfd.zip |
...
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/common/Logger.hpp | 3 | ||||
-rw-r--r-- | include/cru/platform/native/InputMethod.hpp | 46 |
2 files changed, 28 insertions, 21 deletions
diff --git a/include/cru/common/Logger.hpp b/include/cru/common/Logger.hpp index d976dbc3..4ea17c09 100644 --- a/include/cru/common/Logger.hpp +++ b/include/cru/common/Logger.hpp @@ -1,8 +1,7 @@ #pragma once -#include "cru/common/Base.hpp" +#include "Base.hpp" #include <fmt/format.h> -#include <iostream> #include <list> #include <memory> #include <string_view> diff --git a/include/cru/platform/native/InputMethod.hpp b/include/cru/platform/native/InputMethod.hpp index c975825f..6f222a43 100644 --- a/include/cru/platform/native/InputMethod.hpp +++ b/include/cru/platform/native/InputMethod.hpp @@ -4,7 +4,7 @@ #include "cru/common/Event.hpp" -#include <iostream> +#include <fmt/format.h> #include <memory> #include <vector> @@ -23,24 +23,6 @@ struct CompositionText { TextRange selection; }; -// inline std::basic_ostream<char16_t>& operator<<( -// std::basic_ostream<char16_t>& stream, -// const CompositionText& composition_text) { -// stream << u"text: " << composition_text.text << u"\n" << u"clauses:\n"; -// for (int i = 0; i < static_cast<int>(composition_text.clauses.size()); i++) { -// const auto& clause = composition_text.clauses[i]; -// stream << u"\t" << i << u". start:" << clause.start << u" end:" -// << clause.end; -// if (clause.target) { -// stream << u" target"; -// } -// stream << u"\n"; -// } -// stream << u"selection: position:" << composition_text.selection.position -// << u" 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. @@ -76,3 +58,29 @@ struct IInputMethodManager : virtual INativeResource { INativeWindow* window) = 0; }; } // namespace cru::platform::native + +template <> +struct fmt::formatter<cru::platform::native::CompositionText, char16_t> + : fmt::formatter<std::u16string_view, char16_t> { + auto parse(fmt::basic_format_parse_context<char16_t>& ctx) { + return fmt::formatter<std::u16string_view, char16_t>::parse(ctx); + } + + template <typename FormatContext> + auto format(const cru::platform::native::CompositionText& ct, + FormatContext& ctx) { + auto output = ctx.out(); + output = format_to(output, u"text: {}\n", ct.text); + output = format_to(output, u"clauses:\n"); + for (gsl::index i = 0; i < static_cast<gsl::index>(ct.clauses.size()); + i++) { + const auto& clause = ct.clauses[i]; + output = + format_to(output, u"\t{}. start: {} end: {}{}\n", i, clause.start, + clause.end, clause.target ? u" target" : u""); + } + output = format_to(output, u"selection: position: {} count: {}", + ct.selection.position, ct.selection.count); + return output; + } +}; |