Skip to content

Commit fd6252a

Browse files
committed
SDL: fix editor layout resize handling
1 parent 009fca8 commit fd6252a

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/ui/textedit.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,17 +1195,8 @@ void TextEditInput::layout(StbTexteditRow *row, int start) const {
11951195

11961196
void TextEditInput::layout(int w, int h) {
11971197
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-
}
1198+
_width = w - (_x + _xmargin);
1199+
_height = h - (_y + _ymargin);
12091200
}
12101201
}
12111202

@@ -1932,7 +1923,8 @@ TextEditHelpWidget::TextEditHelpWidget(TextEditInput *editor, int chW, int chH,
19321923
_mode(kNone),
19331924
_editor(editor),
19341925
_openPackage(nullptr),
1935-
_openKeyword(-1) {
1926+
_openKeyword(-1),
1927+
_layout(kPopup) {
19361928
_theme = new EditTheme(HELP_FG, HELP_BG);
19371929
hide();
19381930
if (overlay) {
@@ -2417,8 +2409,10 @@ void TextEditHelpWidget::showPopup(int cols, int rows) {
24172409
}
24182410
_x = (_editor->_width - _width) / 2;
24192411
if (rows == 1) {
2412+
_layout = kLine;
24202413
_y = _editor->_height - (_charHeight * 2.5);
24212414
} else {
2415+
_layout = kPopup;
24222416
_y = (_editor->_height - _height) / 2;
24232417
}
24242418
_theme->contrast(_editor->getTheme());
@@ -2433,6 +2427,7 @@ void TextEditHelpWidget::showSidebar() {
24332427
_x = _editor->_width - (_width + border);
24342428
_y = border;
24352429
_theme->contrast(_editor->getTheme());
2430+
_layout = kSidebar;
24362431
calcMargin();
24372432
show();
24382433
}
@@ -2446,3 +2441,23 @@ void TextEditHelpWidget::draw(int x, int y, int w, int h, int chw) {
24462441
maFillRect(x + _width, y + shadowH, shadowW, _height);
24472442
maFillRect(x + shadowW, y + _height, _width, shadowH);
24482443
}
2444+
2445+
void TextEditHelpWidget::layout(int w, int h) {
2446+
if (_resizable) {
2447+
int border;
2448+
switch (_layout) {
2449+
case kLine:
2450+
_x = (w - _width) / 2;
2451+
_y = h - (_charHeight * 2.5);
2452+
break;
2453+
case kSidebar:
2454+
border = _charWidth * 2;
2455+
_height = h - (border * 2);
2456+
_x = w - (_width + border);
2457+
break;
2458+
case kPopup:
2459+
_width = w - (_x + _xmargin);
2460+
_height = h - (_y + _ymargin);
2461+
}
2462+
}
2463+
}

src/ui/textedit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ struct TextEditHelpWidget : public TextEditInput {
215215
void cancelMode() { _mode = kNone; }
216216
bool closeOnEnter() const;
217217
bool searchMode() const { return _mode >= kSearch && _mode <= kReplaceDone; }
218+
void layout(int w, int h);
218219
bool lineEditMode() const { return _mode == kLineEdit; }
219220
bool messageMode() const { return _mode == kMessage; }
220221
bool replaceMode() const { return _mode == kReplace; }
@@ -235,6 +236,11 @@ struct TextEditHelpWidget : public TextEditInput {
235236
TextEditInput *_editor;
236237
const char *_openPackage;
237238
int _openKeyword;
239+
enum Layout {
240+
kLine,
241+
kSidebar,
242+
kPopup,
243+
} _layout;
238244
};
239245

240246
#define STB_TEXTEDIT_STRING EditBuffer

0 commit comments

Comments
 (0)