Skip to content

Commit a39b476

Browse files
committed
UI: fix textwidget layout handling
1 parent 739ddab commit a39b476

File tree

4 files changed

+37
-36
lines changed

4 files changed

+37
-36
lines changed

src/platform/android/jni/runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ void System::editSource(strlib::String loadPath, bool restoreOnExit) {
10711071
case SB_KEY_F(1):
10721072
widget = helpWidget;
10731073
helpWidget->createKeywordIndex();
1074-
helpWidget->show();
1074+
helpWidget->showPopup(-4, -2);
10751075
helpWidget->setFocus(true);
10761076
runtime->showKeypad(false);
10771077
showStatus = false;

src/ui/screen.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ void Screen::drawOverlay(bool vscroll) {
170170
List_each(FormInput *, it, _inputs) {
171171
FormInput *input = (*it);
172172
if (input->_y >= _scrollY - _height &&
173-
input->_y + input->_height <= _scrollY + _height &&
174173
input->isVisible()) {
175174
if (input->isDrawTop()) {
176175
drawTop = input;
@@ -286,35 +285,7 @@ FormInput *Screen::getNextMenu(FormInput *prev, bool up) {
286285
void Screen::layoutInputs(int newWidth, int newHeight) {
287286
List_each(FormInput *, it, _inputs) {
288287
FormInput *r1 = (*it);
289-
if (r1->isResizable()) {
290-
bool right = true;
291-
bool bottom = true;
292-
List_each(FormInput *, subIt, _inputs) {
293-
FormInput *r2 = (*subIt);
294-
if (r1 != r2) {
295-
if (r2->_x > r1->_x &&
296-
r2->_y >= r1->_y &&
297-
r2->_y <= r1->_y + _height) {
298-
// cant resize over right side sibling
299-
right = false;
300-
}
301-
if (r2->_y > r1->_y &&
302-
r2->_x >= r1->_x &&
303-
r2->_x <= r1->_x + _width) {
304-
// cant resize over lower side sibling
305-
bottom = false;
306-
}
307-
}
308-
}
309-
if (right) {
310-
r1->_width = newWidth - r1->_x;
311-
}
312-
if (bottom) {
313-
r1->_height = newHeight - r1->_y;
314-
}
315-
} else {
316-
r1->layout(newWidth, newHeight);
317-
}
288+
r1->layout(newWidth, newHeight);
318289
}
319290
}
320291

src/ui/textedit.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ int textedit_move_to_word_next(EditBuffer *str, int c) {
7676
#define HELP_BG 0x20242a
7777
#define HELP_FG 0x73c990
7878
#define DOUBLE_CLICK_MS 200
79+
#define SIDE_BAR_WIDTH 30
7980

8081
#if defined(_Win32)
8182
#include <shlwapi.h>
@@ -509,9 +510,12 @@ TextEditInput::TextEditInput(const char *text, int chW, int chH,
509510
_matchingBrace(-1),
510511
_ptY(-1),
511512
_pressTick(0),
513+
_xmargin(0),
514+
_ymargin(0),
512515
_bottom(false),
513516
_dirty(false) {
514517
stb_textedit_initialize_state(&_state, false);
518+
_resizable = true;
515519
}
516520

517521
TextEditInput::~TextEditInput() {
@@ -1107,8 +1111,8 @@ bool TextEditInput::updateUI(var_p_t form, var_p_t field) {
11071111
}
11081112

11091113
bool TextEditInput::selected(MAPoint2d pt, int scrollX, int scrollY, bool &redraw) {
1110-
bool result = FormEditInput::selected(pt, scrollX, scrollY, redraw);
1111-
if (hasFocus()) {
1114+
bool result = hasFocus() && FormEditInput::selected(pt, scrollX, scrollY, redraw);
1115+
if (result) {
11121116
if (pt.x < _marginWidth) {
11131117
dragPage(pt.y, redraw);
11141118
} else {
@@ -1189,6 +1193,22 @@ void TextEditInput::layout(StbTexteditRow *row, int start) const {
11891193
row->ymax = row->baseline_y_delta = _charHeight;
11901194
}
11911195

1196+
void TextEditInput::layout(int w, int h) {
1197+
if (_resizable) {
1198+
if (_height == _charHeight) {
1199+
_x = (w - _width) / 2;
1200+
_y = h - (_charHeight * 2.5);
1201+
} else if (_width == _charWidth * SIDE_BAR_WIDTH) {
1202+
int border = _charWidth * 2;
1203+
_height = h - (border * 2);
1204+
_x = w - (_width + border);
1205+
} else {
1206+
_width = w - (_x + _xmargin);
1207+
_height = h - (_y + _ymargin);
1208+
}
1209+
}
1210+
}
1211+
11921212
int TextEditInput::charWidth(int k, int i) const {
11931213
int result = 0;
11941214
if (k + i < _buf._len && _buf._buffer[k + i] != '\n') {
@@ -1197,6 +1217,12 @@ int TextEditInput::charWidth(int k, int i) const {
11971217
return result;
11981218
}
11991219

1220+
void TextEditInput::calcMargin() {
1221+
MAExtent screenSize = maGetScrSize();
1222+
_xmargin = EXTENT_X(screenSize) - (_x + _width);
1223+
_ymargin = EXTENT_Y(screenSize) - (_y + _height);
1224+
}
1225+
12001226
void TextEditInput::changeCase() {
12011227
int start, end;
12021228
char *selection = getSelection(&start, &end);
@@ -2396,16 +2422,18 @@ void TextEditHelpWidget::showPopup(int cols, int rows) {
23962422
_y = (_editor->_height - _height) / 2;
23972423
}
23982424
_theme->contrast(_editor->getTheme());
2425+
calcMargin();
23992426
show();
24002427
}
24012428

24022429
void TextEditHelpWidget::showSidebar() {
24032430
int border = _charWidth * 2;
2404-
_width = _charWidth * 30;
2431+
_width = _charWidth * SIDE_BAR_WIDTH;
24052432
_height = _editor->_height - (border * 2);
24062433
_x = _editor->_width - (_width + border);
24072434
_y = border;
24082435
_theme->contrast(_editor->getTheme());
2436+
calcMargin();
24092437
show();
24102438
}
24112439

src/ui/textedit.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct TextEditInput : public FormEditInput {
104104
void selectAll();
105105
bool isDirty() { return _dirty && _state.undostate.undo_point > 0; }
106106
void setDirty(bool dirty) { _dirty = dirty; }
107-
void layout(int w, int h) { _width = w; _height = h; }
107+
void layout(int w, int h);
108108
const char *getNodeId();
109109
char *getWordBeforeCursor();
110110
bool replaceNext(const char *text, bool skip);
@@ -124,6 +124,7 @@ struct TextEditInput : public FormEditInput {
124124

125125
void dragPage(int y, bool &redraw);
126126
void drawText(int x, int y, const char *str, int length, SyntaxState &state);
127+
void calcMargin();
127128
void changeCase();
128129
void cycleTheme();
129130
void drawLineNumber(int x, int y, int row, bool selected);
@@ -169,6 +170,8 @@ struct TextEditInput : public FormEditInput {
169170
int _matchingBrace;
170171
int _ptY;
171172
int _pressTick;
173+
int _xmargin;
174+
int _ymargin;
172175
bool _bottom;
173176
bool _dirty;
174177
};
@@ -208,7 +211,6 @@ struct TextEditHelpWidget : public TextEditInput {
208211
bool edit(int key, int screenWidth, int charWidth);
209212
void paste(const char *text);
210213
bool isDrawTop() { return true; }
211-
void layout(int w, int h) { _x = w - _width; _height = h; }
212214
void reset(HelpMode mode);
213215
void cancelMode() { _mode = kNone; }
214216
bool closeOnEnter() const;

0 commit comments

Comments
 (0)