From f81940e3ea386a6dfdda2ff4a42d8cede35f2c8a Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 17 Apr 2020 00:49:46 +0800 Subject: ... --- include/cru/platform/graph_base.hpp | 28 ++++++++-------------------- include/cru/platform/native/input_method.hpp | 9 ++++++--- 2 files changed, 14 insertions(+), 23 deletions(-) (limited to 'include/cru/platform') diff --git a/include/cru/platform/graph_base.hpp b/include/cru/platform/graph_base.hpp index 5840ce18..98ac3993 100644 --- a/include/cru/platform/graph_base.hpp +++ b/include/cru/platform/graph_base.hpp @@ -1,5 +1,5 @@ #pragma once -#include "cru/common/pre_config.hpp" +#include "cru/common/base.hpp" #include #include @@ -214,30 +214,18 @@ constexpr bool operator!=(const Ellipse& left, const Ellipse& right) { } struct TextRange final { - constexpr static std::optional FromTwoSides(unsigned first, - unsigned second) { - if (first > second) - return std::make_optional(second, first - second); - if (first < second) - return std::make_optional(first, second - first); - return std::nullopt; - } - - constexpr static std::pair ToTwoSides( - std::optional text_range, unsigned default_position = 0) { - if (text_range.has_value()) - return std::make_pair( - text_range.value().position, - text_range.value().position + text_range.value().count); - return std::make_pair(default_position, default_position); + constexpr static TextRange FromTwoSides(gsl::index start, gsl::index end) { + return TextRange(start, end - start); } constexpr TextRange() = default; - constexpr TextRange(const unsigned position, const unsigned count) + constexpr TextRange(const gsl::index position, const gsl::index count) : position(position), count(count) {} - unsigned position = 0; - unsigned count = 0; + gsl::index GetEnd() const { return position + count; } + + gsl::index position = 0; + gsl::index count = 0; }; struct Color { diff --git a/include/cru/platform/native/input_method.hpp b/include/cru/platform/native/input_method.hpp index 00017502..56e2fb27 100644 --- a/include/cru/platform/native/input_method.hpp +++ b/include/cru/platform/native/input_method.hpp @@ -7,15 +7,18 @@ #include namespace cru::platform::native { -struct CompositionUnderline { +struct CompositionClause { int start; int end; + bool target; }; +using CompositionClauses = std::vector; + struct CompositionText { std::string text; - std::vector underlines; - int caret_position; + CompositionClauses clauses; + TextRange selection; }; struct IInputMethodContext : virtual INativeResource { -- cgit v1.2.3