@@ -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
517521TextEditInput::~TextEditInput () {
@@ -1107,8 +1111,8 @@ bool TextEditInput::updateUI(var_p_t form, var_p_t field) {
11071111}
11081112
11091113bool 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+
11921212int 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+
12001226void 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
24022429void 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
0 commit comments