Skip to content

Commit 6aa079b

Browse files
committed
UI: fix editor layout
1 parent bd68bb0 commit 6aa079b

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

src/ui/image.cpp

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,27 @@ ImageBuffer *load_image(var_t *map) {
122122
return result;
123123
}
124124

125+
ImageBuffer *load_image(const unsigned char* buffer, int32_t size) {
126+
ImageBuffer *result = NULL;
127+
unsigned w, h;
128+
unsigned char *image;
129+
unsigned error = 0;
130+
131+
error = lodepng_decode32(&image, &w, &h, buffer, size);
132+
if (!error) {
133+
result = new ImageBuffer();
134+
result->_bid = ++nextId;
135+
result->_width = w;
136+
result->_height = h;
137+
result->_filename = NULL;
138+
result->_image = image;
139+
cache.add(result);
140+
} else {
141+
err_throw(ERR_IMAGE_LOAD, lodepng_error_text(error));
142+
}
143+
return result;
144+
}
145+
125146
ImageBuffer *load_image(dev_file_t *filep) {
126147
ImageBuffer *result = NULL;
127148
List_each(ImageBuffer *, it, cache) {
@@ -424,14 +445,25 @@ extern "C" void v_create_image(var_p_t var) {
424445
strcpy(file.name, arg.v.p.ptr);
425446
file.type = ft_stream;
426447
image = load_image(&file);
427-
} else if (arg.type == V_ARRAY && !prog_error) {
428-
char **data = new char*[arg.v.a.size];
429-
for (int i = 0; i < arg.v.a.size; i++) {
430-
var_p_t elem = v_elem(&arg, i);
431-
data[i] = elem->v.p.ptr;
448+
} else if (arg.type == V_ARRAY && arg.v.a.size > 0 && !prog_error) {
449+
var_p_t elem0 = v_elem(&arg, 0);
450+
if (elem0->type == V_STR) {
451+
char **data = new char*[arg.v.a.size];
452+
for (int i = 0; i < arg.v.a.size; i++) {
453+
var_p_t elem = v_elem(&arg, i);
454+
data[i] = elem->v.p.ptr;
455+
}
456+
image = load_xpm_image(data);
457+
delete [] data;
458+
} else if (elem0->type == V_INT) {
459+
unsigned char *data = new unsigned char[arg.v.a.size];
460+
for (int i = 0; i < arg.v.a.size; i++) {
461+
var_p_t elem = v_elem(&arg, i);
462+
data[i] = (unsigned char)elem->v.i;
463+
}
464+
image = load_image(data, arg.v.a.size);
465+
delete [] data;
432466
}
433-
image = load_xpm_image(data);
434-
delete [] data;
435467
} else {
436468
image = load_image(&arg);
437469
}

src/ui/inputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ struct FormInput : public Shape {
116116
virtual bool isDrawTop() { return false; }
117117
virtual bool hasHover() { return false; }
118118
virtual void setFocus(bool focus);
119+
virtual void layout(int w, int h) {}
119120

120121
void construct(var_p_t form, var_p_t field, int id);
121122
void drawButton(const char *caption, int x, int y, int w, int h, bool pressed);

src/ui/screen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ void Screen::layoutInputs(int newWidth, int newHeight) {
248248
if (bottom) {
249249
r1->_height = newHeight - r1->_y;
250250
}
251+
} else {
252+
r1->layout(newWidth, newHeight);
251253
}
252254
}
253255
}

src/ui/textedit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct TextEditInput : public FormEditInput {
106106
void selectAll();
107107
bool isDirty() { return _dirty && _state.undostate.undo_point > 0; }
108108
void setDirty(bool dirty) { _dirty = dirty; }
109-
void resize(int w, int h) { _width = w; _height = h; }
109+
void layout(int w, int h) { _width = w; _height = h; }
110110
const char *getNodeId();
111111
char *getWordBeforeCursor();
112112
bool replaceNext(const char *text);
@@ -198,7 +198,7 @@ struct TextEditHelpWidget : public TextEditInput {
198198
bool edit(int key, int screenWidth, int charWidth);
199199
void paste(const char *text) {}
200200
bool isDrawTop() { return true; }
201-
void resize(int w, int h) { _x = w - _width; _height = h; }
201+
void layout(int w, int h) { _x = w - _width; _height = h; }
202202
void reset(HelpMode mode);
203203
bool closeOnEnter() const;
204204
bool lineEditMode() const { return _mode == kLineEdit; }

0 commit comments

Comments
 (0)