Skip to content

Commit 1d71f82

Browse files
committed
UI: experimental keypad to replace android keypad
- now toggles between 4 separate sub-keypad pages
1 parent 368624f commit 1d71f82

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/ui/keycode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ inline bool isExtended(KeyCode key) {
9898
inline bool isArrow(KeyCode key) {
9999
return key == K_LINE_UP || key == K_PAGE_UP || key == K_LINE_DOWN || key == K_PAGE_DOWN;
100100
}
101+
102+
inline bool isRightMargin(KeyCode key) {
103+
return key == K_ENTER || key == K_HELP || key == K_BACKSPACE;
104+
}

src/ui/keypad.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ KeypadDrawContext::KeypadDrawContext(int charWidth, int charHeight) :
164164

165165
const KeypadImage *KeypadDrawContext::getImage(const RawKey &key) const {
166166
const KeypadImage *result;
167-
switch (key._lower) {
167+
switch (getKey(key)) {
168168
case K_CUT: result = &_cutImage; break;
169169
case K_COPY: result = &_copyImage; break;
170170
case K_PASTE: result = &_pasteImage; break;
@@ -188,6 +188,18 @@ void KeypadDrawContext::toggle() {
188188
_keySet = static_cast<Keyset>((_keySet + 1) % kSize);
189189
}
190190

191+
KeyCode KeypadDrawContext::getKey(RawKey key) const {
192+
KeyCode keyCode;
193+
switch (_keySet) {
194+
case kLower: keyCode = key._lower; break;
195+
case kUpper: keyCode = key._upper; break;
196+
case kNumber: keyCode = key._number; break;
197+
case kSymbol: keyCode = key._symbol; break;
198+
case kSize: keyCode = K_NULL; break;
199+
}
200+
return keyCode;
201+
}
202+
191203
//
192204
// Key
193205
//
@@ -210,14 +222,7 @@ int Key::color(const KeypadTheme *theme) const {
210222

211223
char Key::getKey(const KeypadDrawContext *context) const {
212224
char result;
213-
KeyCode keyCode;
214-
215-
switch (context->_keySet) {
216-
case kLower: keyCode = _key._lower; break;
217-
case kUpper: keyCode = _key._upper; break;
218-
case kNumber: keyCode = _key._number; break;
219-
case kSymbol: keyCode = _key._symbol; break;
220-
}
225+
KeyCode keyCode = context->getKey(_key);
221226
switch (keyCode) {
222227
case K_EXT1: result = (char)164; break;
223228
case K_EXT2: result = (char)172; break;
@@ -305,7 +310,7 @@ void Key::onClick(const KeypadDrawContext *context) const {
305310
auto *event = new MAEvent();
306311
event->type = EVENT_TYPE_KEY_PRESSED;
307312
event->nativeKey = 0;
308-
switch (_key._lower) {
313+
switch (context->getKey(_key)) {
309314
case K_BACKSPACE:
310315
event->key = SB_KEY_BACKSPACE;
311316
break;
@@ -415,7 +420,7 @@ void Keypad::layout(int x, int y, int w, int h) {
415420
}
416421
Key *key = _keys[index++];
417422
int keyWidth = keyW;
418-
if (key->_key._lower == K_ENTER || key->_key._lower == K_HELP || key->_key._lower == K_BACKSPACE) {
423+
if (isRightMargin(key->_key._lower)) {
419424
keyWidth = _width - xPos;
420425
} else if (row == 0) {
421426
keyWidth = _width / cols;

src/ui/keypad.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct RawKey {
5454
struct KeypadDrawContext {
5555
explicit KeypadDrawContext(int charWidth, int charHeight);
5656
const KeypadImage *getImage(const RawKey &keycode) const;
57+
KeyCode getKey(RawKey rawKey) const;
5758
void toggle();
5859

5960
int _charWidth;

src/ui/textedit.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ void TextEditHelpWidget::clicked(int x, int y, bool pressed) {
21162116
if (pressed && _buf._len > 0) {
21172117
stb_textedit_click(&_buf, &_state, 0, (y - _y) + (_scroll * _charHeight));
21182118
if (_mode == kHelpKeyword) {
2119-
if (x < (_x + _charWidth * 10)) {
2119+
if (x < (_x + _charWidth * 4)) {
21202120
// allow scrolling from the right hand side
21212121
toggleKeyword();
21222122
} else {
@@ -2462,9 +2462,7 @@ void TextEditHelpWidget::buildKeywordIndex() {
24622462
_buf.append("\n\n", 2);
24632463
rows += 7;
24642464
int scroll = ((_charHeight * rows) - (_height - _y)) / _charHeight;
2465-
if (scroll > 0) {
2466-
_scroll = scroll;
2467-
}
2465+
_scroll = scroll > 0 ? scroll : 0;
24682466
} else {
24692467
_scroll = 0;
24702468
}

0 commit comments

Comments
 (0)