aboutsummaryrefslogtreecommitdiff
path: root/src/ui/ui_base.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-10-07 00:49:38 +0800
committercrupest <crupest@outlook.com>2018-10-07 00:49:38 +0800
commit36820c22929f4fb11892c4fbd52f321cc63a55ad (patch)
tree0c87a377fac3d9359995cb1fa62ec541fe83f579 /src/ui/ui_base.h
parentb0057dc911f96258c7280b89c8f4da828ecc283c (diff)
downloadcru-36820c22929f4fb11892c4fbd52f321cc63a55ad.tar.gz
cru-36820c22929f4fb11892c4fbd52f321cc63a55ad.tar.bz2
cru-36820c22929f4fb11892c4fbd52f321cc63a55ad.zip
Add shift selection, and fix the bug that caret is at wrong position when move with selection.
Diffstat (limited to 'src/ui/ui_base.h')
-rw-r--r--src/ui/ui_base.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/ui/ui_base.h b/src/ui/ui_base.h
index 51ae4084..bff30bfd 100644
--- a/src/ui/ui_base.h
+++ b/src/ui/ui_base.h
@@ -1,5 +1,7 @@
#pragma once
+#include <optional>
+
namespace cru
{
@@ -125,8 +127,24 @@ namespace cru
struct TextRange
{
+ 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 TextRange() = default;
- constexpr TextRange(const int position, const int count)
+ constexpr TextRange(const unsigned position, const unsigned count)
: position(position), count(count)
{
@@ -135,5 +153,8 @@ namespace cru
unsigned position = 0;
unsigned count = 0;
};
+
+ bool IsKeyDown(int virtual_code);
+ bool IsKeyToggled(int virtual_code);
}
}