Skip to content

Commit 3c3d4f6

Browse files
committed
ANDROID: clip handling for drawlink
1 parent b68c0d8 commit 3c3d4f6

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

src/platform/common/ansiwidget.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,25 @@ void Widget::drawButton(const char *caption, int dx, int dy,
138138
}
139139
}
140140

141-
void Widget::drawLink(const char *caption, int dx, int dy) {
141+
void Widget::drawLink(const char *caption, int dx, int dy, int sw, int chw) {
142142
maSetColor(_fg);
143-
maDrawText(dx, dy, caption);
143+
144+
int len = strlen(caption);
145+
int width = min(sw, _width) - dx;
146+
if ((len * chw) > sw - width) {
147+
int len = width / chw;
148+
char *buffer = new char[len + 1];
149+
strncpy(buffer, caption, len - 2);
150+
buffer[len - 2] = '~';
151+
buffer[len - 1] = '~';
152+
buffer[len] = 0;
153+
maDrawText(dx, dy, buffer);
154+
delete [] buffer;
155+
} else {
156+
maDrawText(dx, dy, caption);
157+
}
144158
maSetColor(_pressed ? _fg : _bg);
145-
maLine(dx + 2, dy + _height + 1, dx + _width, dy + _height + 1);
159+
maLine(dx + 2, dy + _height - 1, dx + min(sw, _width), dy + _height - 1);
146160
}
147161

148162
bool Widget::overlaps(MAPoint2d pt, int offsX, int offsY, bool &redraw) {
@@ -218,7 +232,7 @@ FormLineInput::FormLineInput(Screen *screen, char *buffer, int maxSize,
218232
_scroll(0) {
219233
}
220234

221-
void FormLineInput::draw(int dx, int dy) {
235+
void FormLineInput::draw(int dx, int dy, int sw, int chw) {
222236
maSetColor(getBackground(GRAY_BG_COL));
223237
maFillRect(dx, dy, _width, _height);
224238
maSetColor(_fg);
@@ -856,11 +870,11 @@ Widget *AnsiWidget::createLink(const char *action, const char *text,
856870
_back->_linePadding = BUTTON_PADDING;
857871
}
858872
if (_back->_curX + w >= _width) {
859-
w = _width - _back->_curX; // clipped
860-
_back->newLine(EXTENT_Y(textSize) + LINE_SPACING);
861-
} else {
862-
_back->_curX += w;
873+
// clipped
874+
w = _width - _back->_curX - BUTTON_PADDING;
863875
}
876+
_back->_curX += w;
877+
864878
Widget *result;
865879
if (formLink) {
866880
result = new FormLink(_back, action, x, y, w, h);
@@ -986,7 +1000,7 @@ void AnsiWidget::drawActiveButton() {
9861000
int x = _focus->_x + _activeButton->_x;
9871001
int y = _focus->_y + _activeButton->_y - _focus->_scrollY;
9881002
maSetClipRect(x, y, _activeButton->_width, _activeButton->_height + 2);
989-
_activeButton->draw(x, y);
1003+
_activeButton->draw(x, y, _front->w(), _front->_charWidth);
9901004
maUpdateScreen();
9911005
maResetBacklight();
9921006
maSetDrawTarget(currentHandle);

src/platform/common/ansiwidget.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
7-
//
7+
//
88

99
#ifndef ANSIWIDGET_H
1010
#define ANSIWIDGET_H
@@ -37,7 +37,7 @@ struct Widget : public Shape {
3737
virtual void clicked(IButtonListener *listener, int x, int y) = 0;
3838
virtual bool overlaps(MAPoint2d pt, int scrollX, int scrollY, bool &redraw);
3939
void drawButton(const char *caption, int x, int y, int w, int h, bool pressed);
40-
void drawLink(const char *caption, int x, int y);
40+
void drawLink(const char *caption, int x, int y, int sw, int chw);
4141
int getBackground(int buttonColor);
4242

4343
bool _pressed;
@@ -60,16 +60,18 @@ struct TextButton : public Button {
6060
TextButton(Screen *screen, const char *action, const char *label,
6161
int x, int y, int w, int h) :
6262
Button(screen, action, label, x, y, w, h) {}
63-
void draw(int x, int y) { drawLink(_label.c_str(), x, y); }
63+
void draw(int x, int y, int bw, int cw) {
64+
drawLink(_label.c_str(), x, y, bw, cw);
65+
}
6466
};
6567

6668
// internal block button
6769
struct BlockButton : public Button {
6870
BlockButton(Screen *screen, const char *action, const char *label,
6971
int x, int y, int w, int h) :
7072
Button(screen, action, label, x, y, w, h) {}
71-
void draw(int x, int y) {
72-
drawButton(_label.c_str(), x, y, _width, _height, _pressed);
73+
void draw(int x, int y, int bw, int cw) {
74+
drawButton(_label.c_str(), x, y, _width, _height, _pressed);
7375
}
7476
};
7577

@@ -105,8 +107,8 @@ struct FormButton : public FormWidget {
105107
virtual ~FormButton() {}
106108

107109
const char *getText() const { return _caption.c_str(); }
108-
void draw(int x, int y) {
109-
drawButton(_caption.c_str(), x, y, _width, _height, _pressed);
110+
void draw(int x, int y, int sw, int chw) {
111+
drawButton(_caption.c_str(), x, y, _width, _height, _pressed);
110112
}
111113
void clicked(IButtonListener *listener, int x, int y);
112114
void setText(const char *text) { _caption = text; }
@@ -120,7 +122,7 @@ struct FormLabel : public FormWidget {
120122
virtual ~FormLabel() {}
121123

122124
const char *getText() const { return _caption.c_str(); }
123-
void draw(int x, int y) {
125+
void draw(int x, int y, int sw, int chw) {
124126
drawButton(_caption.c_str(), x, y, _width, _height, false);
125127
}
126128
void setText(const char *text) { _caption = text; }
@@ -134,19 +136,21 @@ struct FormLink : public FormWidget {
134136
virtual ~FormLink() {}
135137

136138
const char *getText() const { return _link.c_str(); }
137-
void draw(int x, int y) { drawLink(_link.c_str(), x, y); }
139+
void draw(int x, int y, int sw, int chw) {
140+
drawLink(_link.c_str(), x, y, sw, chw);
141+
}
138142

139143
private:
140144
String _link;
141145
};
142146

143147
struct FormLineInput : public FormWidget {
144-
FormLineInput(Screen *screen, char *buffer, int maxSize,
148+
FormLineInput(Screen *screen, char *buffer, int maxSize,
145149
int x, int y, int w, int h);
146150
virtual ~FormLineInput() {}
147151

148152
void close();
149-
void draw(int x, int y);
153+
void draw(int x, int y, int sw, int chw);
150154
bool edit(int key);
151155
const char *getText() const { return _buffer; }
152156
void setText(const char *text) {}
@@ -158,7 +162,7 @@ struct FormLineInput : public FormWidget {
158162
};
159163

160164
struct FormList : public FormWidget {
161-
FormList(Screen *screen, IFormWidgetListModel *model,
165+
FormList(Screen *screen, IFormWidgetListModel *model,
162166
int x, int y, int w, int h);
163167
virtual ~FormList() {}
164168

@@ -173,7 +177,7 @@ struct FormList : public FormWidget {
173177
};
174178

175179
struct FormDropList : public FormList {
176-
FormDropList(Screen *screen, IFormWidgetListModel *model,
180+
FormDropList(Screen *screen, IFormWidgetListModel *model,
177181
int x, int y, int w, int h);
178182
void clicked(IButtonListener *listener, int x, int y);
179183
void draw(int dx, int dy);
@@ -189,7 +193,7 @@ struct FormDropList : public FormList {
189193
};
190194

191195
struct FormListBox : public FormList {
192-
FormListBox(Screen *screen, IFormWidgetListModel *model,
196+
FormListBox(Screen *screen, IFormWidgetListModel *model,
193197
int x, int y, int w, int h);
194198
void clicked(IButtonListener *listener, int x, int y);
195199
void draw(int dx, int dy);
@@ -264,7 +268,7 @@ struct AnsiWidget {
264268

265269
Screen *_screens[MAX_SCREENS];
266270
Screen *_back; // screen being painted/written
267-
Screen *_front; // screen to display
271+
Screen *_front; // screen to display
268272
Screen *_focus; // screen with the active button
269273
int _width; // device screen width
270274
int _height; // device screen height

src/platform/common/screen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void Screen::drawOverlay(bool vscroll) {
128128
Shape *rect = (*it);
129129
if (rect->_y >= _scrollY &&
130130
rect->_y + rect->_height <= _scrollY + _height) {
131-
rect->draw(_x + rect->_x, _y + rect->_y - _scrollY);
131+
rect->draw(_x + rect->_x, _y + rect->_y - _scrollY, w(), _charWidth);
132132
}
133133
}
134134

src/platform/common/screen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using namespace strlib;
3434
struct Shape {
3535
Shape(int x, int y, int w, int h) : _x(x), _y(y), _width(w), _height(h) {}
3636
virtual ~Shape() {}
37-
virtual void draw(int x, int y) {}
37+
virtual void draw(int x, int y, int bw, int cw) {}
3838

3939
int w() { return _width; }
4040
int h() { return _height; }

0 commit comments

Comments
 (0)