Skip to content

Commit 3695a0c

Browse files
committed
UI: experimental keypad to replace android keypad
1 parent 3f18391 commit 3695a0c

File tree

3 files changed

+64
-64
lines changed

3 files changed

+64
-64
lines changed

src/platform/android/jni/editor.cpp

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
#include "common/device.h"
1414
#include "ui/keypad.h"
1515

16+
// whether to hide the status message
17+
bool statusEnabled = true;
18+
1619
struct StatusMessage {
17-
explicit StatusMessage(const TextEditInput *editor) :
20+
explicit StatusMessage(const TextEditInput *editor, String &loadPath) :
1821
_dirty(!editor->isDirty()),
19-
_enabled(true),
2022
_find(false),
2123
_scroll(-1),
2224
_row(editor->getRow()),
2325
_col(editor->getCol()) {
24-
}
25-
26-
void setFilename(const String &loadPath) {
2726
int i = loadPath.lastIndexOf('/', 0);
2827
if (i != -1) {
2928
_fileName = loadPath.substring(i + 1);
@@ -38,66 +37,73 @@ struct StatusMessage {
3837
_scroll = editor->getScroll();
3938
}
4039

41-
bool toggleEnabled() {
42-
_enabled = !_enabled;
43-
_dirty = true;
44-
return _enabled;
40+
void toggleEnabled(const TextEditInput *editor) {
41+
statusEnabled = !statusEnabled;
42+
setDirty(editor);
4543
}
4644

4745
void setDirty(const TextEditInput *editor) {
4846
_dirty = !editor->isDirty();
4947
}
5048

51-
void setFind(bool find) {
52-
_find = find;
53-
_dirty = true;
49+
void setFind(bool find, const TextEditInput *editor) {
50+
if (_find != find) {
51+
_find = find;
52+
setDirty(editor);
53+
}
5454
}
5555

5656
bool update(TextEditInput *editor, const AnsiWidget *out) {
5757
bool result;
5858
bool dirty = editor->isDirty();
59-
if (_enabled &&
60-
(_dirty != dirty
61-
|| _scroll != editor->getScroll()
62-
|| _row != editor->getRow()
63-
|| _col != editor->getCol())) {
64-
String message;
65-
result = true;
66-
if (_find) {
67-
message.append(" Search ");
59+
if (_dirty != dirty
60+
|| _scroll != editor->getScroll()
61+
|| _row != editor->getRow()
62+
|| _col != editor->getCol()) {
63+
if (statusEnabled) {
64+
setMessage(editor, out, dirty);
6865
} else {
69-
if (dirty) {
70-
message.append(" * ");
71-
} else {
72-
message.append(" - ");
73-
}
74-
message.append(_fileName);
75-
}
76-
message.append(" (")
77-
.append(editor->getRow())
78-
.append(",")
79-
.append(editor->getCol())
80-
.append(") ");
81-
if (!editor->getScroll()) {
82-
message.append("Top");
83-
} else if (editor->getLines() - editor->getScroll() < editor->getPageRows()) {
84-
message.append("Bot");
85-
} else {
86-
const int pos = editor->getRow() * 100 / editor->getLines();
87-
message.append(pos).append("%");
66+
out->setStatus("");
8867
}
89-
out->setStatus(message);
90-
_dirty = dirty;
9168
resetCursor(editor);
69+
result = true;
9270
} else {
9371
result = false;
9472
}
73+
_dirty = dirty;
9574
return result;
9675
}
9776

77+
void setMessage(TextEditInput *editor, const AnsiWidget *out, bool dirty) const {
78+
String message;
79+
if (_find) {
80+
message.append(" Search ");
81+
} else {
82+
if (dirty) {
83+
message.append(" * ");
84+
} else {
85+
message.append(" - ");
86+
}
87+
message.append(_fileName);
88+
}
89+
message.append(" (")
90+
.append(editor->getRow())
91+
.append(",")
92+
.append(editor->getCol())
93+
.append(") ");
94+
if (!editor->getScroll()) {
95+
message.append("Top");
96+
} else if (editor->getLines() - editor->getScroll() < editor->getPageRows()) {
97+
message.append("Bot");
98+
} else {
99+
const int pos = editor->getRow() * 100 / editor->getLines();
100+
message.append(pos).append("%");
101+
}
102+
out->setStatus(message);
103+
}
104+
98105
private:
99106
bool _dirty;
100-
bool _enabled;
101107
bool _find;
102108
int _scroll;
103109
int _row;
@@ -135,8 +141,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
135141
}
136142
auto *helpWidget = new TextEditHelpWidget(editWidget, charWidth, charHeight, false);
137143
auto *widget = editWidget;
138-
StatusMessage statusMessage(editWidget);
139-
statusMessage.setFilename(loadPath);
144+
StatusMessage statusMessage(editWidget, loadPath);
140145

141146
_modifiedTime = getModifiedTime();
142147
editWidget->updateUI(nullptr, nullptr);
@@ -213,11 +218,11 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
213218
case SB_KEY_CTRL('f'):
214219
if (widget == helpWidget) {
215220
exitHelp = true;
216-
statusMessage.setFind(false);
221+
statusMessage.setFind(false, editWidget);
217222
} else {
218223
widget = helpWidget;
219224
showFind(helpWidget);
220-
statusMessage.setFind(true);
225+
statusMessage.setFind(true, editWidget);
221226
}
222227
redraw = true;
223228
break;
@@ -247,9 +252,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
247252
_state = kEditState;
248253
break;
249254
case SB_KEY_CTRL('t'):
250-
if (!statusMessage.toggleEnabled()) {
251-
_output->setStatus("");
252-
}
255+
statusMessage.toggleEnabled(editWidget);
253256
redraw = true;
254257
break;
255258
default:
@@ -267,6 +270,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
267270
widget = editWidget;
268271
helpWidget->hide();
269272
editWidget->setFocus(true);
273+
statusMessage.setFind(false, editWidget);
270274
_state = kEditState;
271275
_output->redraw();
272276
}

src/ui/keypad.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ KeypadDrawContext::KeypadDrawContext(int charWidth, int charHeight) :
127127
_charWidth(charWidth),
128128
_charHeight(charHeight),
129129
_keySet(kLower) {
130-
const int imageSize = static_cast<int>(charHeight * 1.1);
130+
const int imageSize = static_cast<int>(charHeight * 1.2);
131131

132132
if (!_cutImage.decode(img_cut, img_cut_len) ||
133133
!_copyImage.decode(img_copy, img_copy_len) ||
@@ -452,15 +452,14 @@ void Keypad::layout(int x, int y, int w, int h) {
452452

453453
void Keypad::clicked(int x, int y, bool pressed) {
454454
for (const auto key : _keys) {
455-
const bool inside = key->inside(x, y);
456-
key->_pressed = pressed && inside;
457-
458-
if (!pressed && inside) {
459-
if (key->_key._lower == K_TOGGLE) {
460-
_context.toggle();
461-
break;
462-
} else {
463-
key->onClick(&_context);
455+
if (key->inside(x, y)) {
456+
key->_pressed = pressed;
457+
if (!pressed) {
458+
if (key->_key._lower == K_TOGGLE) {
459+
_context.toggle();
460+
} else {
461+
key->onClick(&_context);
462+
}
464463
}
465464
break;
466465
}

src/ui/textedit.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,14 +2115,11 @@ void TextEditHelpWidget::completeWord(int pos) const {
21152115
void TextEditHelpWidget::clicked(int x, int y, bool pressed) {
21162116
_ptY = -1;
21172117
if (pressed && _buf._len > 0) {
2118-
stb_textedit_click(&_buf, &_state, 0, (y - _y) + (_scroll * _charHeight));
2118+
stb_textedit_click(&_buf, &_state, (x - _x), (y - _y) + (_scroll * _charHeight));
21192119
if (_mode == kHelpKeyword) {
21202120
if (x < (_x + _charWidth * 4)) {
21212121
// allow scrolling from the right hand side
21222122
toggleKeyword();
2123-
} else {
2124-
// position to [+]
2125-
_state.cursor += 3;
21262123
}
21272124
}
21282125
}

0 commit comments

Comments
 (0)