new input system
This commit is contained in:
parent
b3db40ebec
commit
ac2eb7fb0a
31 changed files with 3292 additions and 781 deletions
|
|
@ -23,6 +23,7 @@ import :UI;
|
|||
import :UIComponents;
|
||||
import :Font;
|
||||
import :Types;
|
||||
import :Keys;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
|
@ -87,32 +88,26 @@ void Crafter::InputField_OnText(InputField& f, std::string_view utf8) {
|
|||
f.cursorPos += utf8.size();
|
||||
}
|
||||
|
||||
void Crafter::InputField_OnKey(InputField& f, CrafterKeys key) {
|
||||
switch (key) {
|
||||
case CrafterKeys::Backspace:
|
||||
if (f.cursorPos > 0 && !f.value.empty()) {
|
||||
f.value.erase(f.cursorPos - 1, 1);
|
||||
--f.cursorPos;
|
||||
}
|
||||
break;
|
||||
case CrafterKeys::Delete:
|
||||
if (f.cursorPos < f.value.size()) {
|
||||
f.value.erase(f.cursorPos, 1);
|
||||
}
|
||||
break;
|
||||
case CrafterKeys::Left:
|
||||
if (f.cursorPos > 0) --f.cursorPos;
|
||||
break;
|
||||
case CrafterKeys::Right:
|
||||
if (f.cursorPos < f.value.size()) ++f.cursorPos;
|
||||
break;
|
||||
case CrafterKeys::Home:
|
||||
f.cursorPos = 0;
|
||||
break;
|
||||
case CrafterKeys::End:
|
||||
f.cursorPos = f.value.size();
|
||||
break;
|
||||
default: break;
|
||||
void Crafter::InputField_OnKey(InputField& f, KeyCode code) {
|
||||
// `Key(...)` is consteval — every comparison below folds to an immediate
|
||||
// integer at compile time, so this is just a sequence of int-eq tests.
|
||||
if (code == Key(CrafterKeys::Backspace)) {
|
||||
if (f.cursorPos > 0 && !f.value.empty()) {
|
||||
f.value.erase(f.cursorPos - 1, 1);
|
||||
--f.cursorPos;
|
||||
}
|
||||
} else if (code == Key(CrafterKeys::Delete)) {
|
||||
if (f.cursorPos < f.value.size()) {
|
||||
f.value.erase(f.cursorPos, 1);
|
||||
}
|
||||
} else if (code == Key(CrafterKeys::Left)) {
|
||||
if (f.cursorPos > 0) --f.cursorPos;
|
||||
} else if (code == Key(CrafterKeys::Right)) {
|
||||
if (f.cursorPos < f.value.size()) ++f.cursorPos;
|
||||
} else if (code == Key(CrafterKeys::Home)) {
|
||||
f.cursorPos = 0;
|
||||
} else if (code == Key(CrafterKeys::End)) {
|
||||
f.cursorPos = f.value.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue