aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-09-09 17:55:40 +0800
committercrupest <crupest@outlook.com>2021-09-09 17:55:40 +0800
commit74aee8a6308445604b513ab37812ddc99365aa98 (patch)
tree4a0886df82af6baa248e62b97fa585e09be9470d /include/cru/platform
parent700751108257a00ab1a6134fe0ca570acb3269a8 (diff)
downloadcru-74aee8a6308445604b513ab37812ddc99365aa98.tar.gz
cru-74aee8a6308445604b513ab37812ddc99365aa98.tar.bz2
cru-74aee8a6308445604b513ab37812ddc99365aa98.zip
...
Diffstat (limited to 'include/cru/platform')
-rw-r--r--include/cru/platform/GraphBase.hpp40
1 files changed, 2 insertions, 38 deletions
diff --git a/include/cru/platform/GraphBase.hpp b/include/cru/platform/GraphBase.hpp
index c4dd19f6..cc0ffcc7 100644
--- a/include/cru/platform/GraphBase.hpp
+++ b/include/cru/platform/GraphBase.hpp
@@ -3,6 +3,7 @@
#include "Color.hpp"
#include "cru/common/Format.hpp"
+#include "cru/common/Range.hpp"
#include <fmt/core.h>
#include <cstdint>
@@ -266,42 +267,5 @@ constexpr bool operator!=(const Ellipse& left, const Ellipse& right) {
return !(left == right);
}
-struct TextRange final {
- constexpr static TextRange FromTwoSides(gsl::index start, gsl::index end) {
- return TextRange(start, end - start);
- }
-
- constexpr static TextRange FromTwoSides(gsl::index start, gsl::index end,
- gsl::index offset) {
- return TextRange(start + offset, end - start);
- }
-
- constexpr TextRange() = default;
- constexpr TextRange(const gsl::index position, const gsl::index count = 0)
- : position(position), count(count) {}
-
- gsl::index GetStart() const { return position; }
- gsl::index GetEnd() const { return position + count; }
-
- void ChangeEnd(gsl::index new_end) { count = new_end - position; }
-
- TextRange Normalize() const {
- auto result = *this;
- if (result.count < 0) {
- result.position += result.count;
- result.count = -result.count;
- }
- return result;
- }
-
- TextRange CoerceInto(gsl::index min, gsl::index max) const {
- auto coerce = [min, max](gsl::index index) {
- return index > max ? max : (index < min ? min : index);
- };
- return TextRange::FromTwoSides(coerce(GetStart()), coerce(GetEnd()));
- }
-
- gsl::index position = 0;
- gsl::index count = 0;
-};
+using TextRange = Range;
} // namespace cru::platform