diff options
author | Yuqian Yang <crupest@outlook.com> | 2018-10-06 16:52:51 +0000 |
---|---|---|
committer | Yuqian Yang <crupest@outlook.com> | 2018-10-06 16:52:51 +0000 |
commit | 508c69d6706ddfdba5bac7970ea95b8158992323 (patch) | |
tree | 0c87a377fac3d9359995cb1fa62ec541fe83f579 /src/ui/ui_base.h | |
parent | b0057dc911f96258c7280b89c8f4da828ecc283c (diff) | |
parent | 36820c22929f4fb11892c4fbd52f321cc63a55ad (diff) | |
download | cru-508c69d6706ddfdba5bac7970ea95b8158992323.tar.gz cru-508c69d6706ddfdba5bac7970ea95b8158992323.tar.bz2 cru-508c69d6706ddfdba5bac7970ea95b8158992323.zip |
Merge branch '6-shift-selection' into 'master'
Resolve "Add shift selection in text box."
Closes #6
See merge request crupest/CruUI!14
Diffstat (limited to 'src/ui/ui_base.h')
-rw-r--r-- | src/ui/ui_base.h | 23 |
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); } } |