diff options
author | crupest <crupest@outlook.com> | 2020-04-17 00:49:46 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-04-17 00:49:46 +0800 |
commit | f81940e3ea386a6dfdda2ff4a42d8cede35f2c8a (patch) | |
tree | d00c4f933e2a78fe8cf563e7d2bcc7a4cb588dfa /include/cru/platform/graph_base.hpp | |
parent | 39c0b5ad6814db9e46ac2cb4ab64a37e0e19749b (diff) | |
download | cru-f81940e3ea386a6dfdda2ff4a42d8cede35f2c8a.tar.gz cru-f81940e3ea386a6dfdda2ff4a42d8cede35f2c8a.tar.bz2 cru-f81940e3ea386a6dfdda2ff4a42d8cede35f2c8a.zip |
...
Diffstat (limited to 'include/cru/platform/graph_base.hpp')
-rw-r--r-- | include/cru/platform/graph_base.hpp | 28 |
1 files changed, 8 insertions, 20 deletions
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 <cstdint> #include <optional> @@ -214,30 +214,18 @@ constexpr bool operator!=(const Ellipse& left, const Ellipse& right) { } struct TextRange final { - constexpr static std::optional<TextRange> FromTwoSides(unsigned first, - unsigned second) { - if (first > second) - return std::make_optional<TextRange>(second, first - second); - if (first < second) - return std::make_optional<TextRange>(first, second - first); - return std::nullopt; - } - - constexpr static std::pair<unsigned, unsigned> ToTwoSides( - std::optional<TextRange> 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 { |