Skip to content

Commit 1c22dfa

Browse files
committed
UI: experimental keypad to replace android keypad
1 parent 230060f commit 1c22dfa

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

src/ui/ansiwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ void AnsiWidget::pointerReleaseEvent(MAEvent &event) {
489489
_activeButton->clicked(event.point.x, event.point.y, false);
490490
} else if (_activeButton != nullptr && _activeButton->_pressed) {
491491
_activeButton->_pressed = false;
492-
drawActiveButton();
493492
_activeButton->clicked(event.point.x, event.point.y, false);
493+
drawActiveButton();
494494
} else if (_swipeExit) {
495495
_swipeExit = false;
496496
} else {

src/ui/keypad.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "config.h"
1010
#include "keypad.h"
1111
#include "lib/maapi.h"
12+
#include "common/device.h"
1213

1314
constexpr char cutIcon[] = {'\346', '\0'};
1415
constexpr char copyIcon[] = {'\251', '\0'};
@@ -98,7 +99,7 @@ Key::Key(const RawKey &k) :
9899
_altLabel(k._shifted) {
99100
_labelLength = _label.length();
100101
_pressed = false;
101-
_special = k._normal[0] > 128 || _labelLength > 1;
102+
_special = (uint8_t )k._normal[0] > 128 || _labelLength > 1;
102103
_number = k._normal[0] >= '0' && k._normal[0] <= '9';
103104
}
104105

@@ -274,11 +275,16 @@ void Keypad::clicked(int x, int y, bool pressed) {
274275
layout(_posX, _posY, _width, _height);
275276
break;
276277
} else {
278+
bool useShift = _shiftActive ^ _capsLockActive;
279+
String label = useShift ? key->_altLabel : key->_label;
280+
fprintf(stderr, "pressed %s\n", label.c_str());
281+
277282
if (_shiftActive && !key->_special) {
278283
_shiftActive = false;
279284
}
280285
// TODO: Output the key's character/command
281286
}
287+
break;
282288
}
283289
}
284290
}
@@ -314,25 +320,41 @@ void Keypad::draw() {
314320
//
315321
// KeypadInput
316322
//
317-
KeypadInput::KeypadInput(bool floatTop, bool toolbar) :
318-
FormInput(0, 0, 0, 100),
323+
KeypadInput::KeypadInput(bool floatTop, bool toolbar, int charWidth, int charHeight) :
324+
FormInput(0, 0, 0, charHeight * 2),
319325
_floatTop(floatTop),
320-
_toolbar(toolbar) {
326+
_toolbar(toolbar),
327+
_keypad(nullptr) {
328+
if (!toolbar) {
329+
_keypad = new Keypad(charWidth, charHeight);
330+
_height = Keypad::outerHeight(charHeight);
331+
}
332+
}
333+
334+
KeypadInput::~KeypadInput() {
335+
delete _keypad;
321336
}
322337

323338
void KeypadInput::clicked(int x, int y, bool pressed) {
324-
fprintf(stderr, "clicked %d %d %d\n", x, y, pressed);
339+
if (_keypad) {
340+
_keypad->clicked(x, y, pressed);
341+
}
325342
}
326343

327344
void KeypadInput::draw(int x, int y, int w, int h, int chw) {
328-
maSetColor(0xff3344);
329-
maFillRect(_x, _y, _width, _height);
330-
maSetColor(0x007744);
331-
maDrawText(_x + 10, _y + 10, "keypad !", 8);
345+
if (_keypad) {
346+
_keypad->draw();
347+
} else {
348+
maSetColor(modernDarkTheme._bg);
349+
maFillRect(x, y, _width, _height);
350+
}
332351
}
333352

334353
void KeypadInput::layout(int x, int y, int w, int h) {
335354
_x = x;
336-
_y = _floatTop ? 0 : h;
355+
_y = _floatTop ? 0 : h;
337356
_width = w;
357+
if (_keypad) {
358+
_keypad->layout(_x, _y, _width, _height);
359+
}
338360
}

src/ui/keypad.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct Keypad {
5656
Keypad(int charWidth, int charHeight);
5757
~Keypad() = default;
5858

59-
static int outerHeight(int ch) ;
59+
static int outerHeight(int ch) ;
6060
void clicked(int x, int y, bool pressed);
6161
void draw();
6262
void layout(int x, int y, int w, int h);
@@ -79,8 +79,8 @@ struct Keypad {
7979
};
8080

8181
struct KeypadInput : public FormInput {
82-
KeypadInput(bool floatTop, bool toolbar);
83-
~KeypadInput() override = default;
82+
KeypadInput(bool floatTop, bool toolbar, int charWidth, int charHeight);
83+
~KeypadInput() override;
8484

8585
void clicked(int x, int y, bool pressed) override;
8686
void draw(int x, int y, int w, int h, int chw) override;
@@ -91,5 +91,5 @@ struct KeypadInput : public FormInput {
9191
private:
9292
bool _floatTop;
9393
bool _toolbar;
94-
//Keypad _keypad;
94+
Keypad *_keypad;
9595
};

src/ui/system.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,9 @@ void System::showMenu() {
11011101
items->add(new String(MENU_STR_BACK));
11021102
_systemMenu[index++] = MENU_BACK;
11031103
#else
1104-
items->add(new String(MENU_STR_KEYPAD));
1105-
_systemMenu[index++] = MENU_KEYPAD;
11061104
if (!isEditing()) {
1105+
items->add(new String(MENU_STR_KEYPAD));
1106+
_systemMenu[index++] = MENU_KEYPAD;
11071107
bool controlMode = get_focus_edit()->getControlMode();
11081108
sprintf(buffer, MENU_STR_CONTROL, (controlMode ? MENU_STR_ON : MENU_STR_OFF));
11091109
items->add(new String(buffer));

0 commit comments

Comments
 (0)