measure line properly
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
833947c1ec
commit
ca703f24d5
3 changed files with 53 additions and 17 deletions
|
|
@ -211,7 +211,7 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name,
|
||||||
|
|
||||||
h->internal = NULL;
|
h->internal = NULL;
|
||||||
h->opaque = NULL;
|
h->opaque = NULL;
|
||||||
h->user = NULL;
|
h->user = NULL;
|
||||||
|
|
||||||
h->top_step = 0;
|
h->top_step = 0;
|
||||||
h->draw_queue = NULL;
|
h->draw_queue = NULL;
|
||||||
|
|
@ -1068,10 +1068,10 @@ void MwGetClipboard(MwWidget handle, int clipboard_type) {
|
||||||
MwLLGetClipboard(handle->lowlevel, clipboard_type);
|
MwLLGetClipboard(handle->lowlevel, clipboard_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwSetUser(MwWidget handle, void* user){
|
void MwSetUser(MwWidget handle, void* user) {
|
||||||
handle->user = user;
|
handle->user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MwGetUser(MwWidget handle){
|
void* MwGetUser(MwWidget handle) {
|
||||||
return handle->user;
|
return handle->user;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,19 +71,53 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text,
|
||||||
}
|
}
|
||||||
|
|
||||||
int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {
|
int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {
|
||||||
/* TODO: check newline */
|
int len = 0;
|
||||||
#ifdef TTF
|
int st;
|
||||||
int st;
|
int cp;
|
||||||
|
char* input = (char*)text;
|
||||||
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
|
char* last = input;
|
||||||
|
#ifndef TTF
|
||||||
if(MwFLTextWidth)
|
|
||||||
if(!MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextWidth(ttf, text)) != -1) return st;
|
|
||||||
#else
|
|
||||||
(void)handle;
|
(void)handle;
|
||||||
(void)ttf;
|
(void)ttf;
|
||||||
#endif
|
#endif
|
||||||
return MwUTF8Length(text) * FontWidth;
|
|
||||||
|
#ifdef TTF
|
||||||
|
if(ttf <= MwFLBuildFont(0xff)) ttf = assume_ttf(handle, ttf);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while(*input != 0) {
|
||||||
|
input += MwUTF8ToUTF32(input, &cp);
|
||||||
|
|
||||||
|
if(*input == 0 || cp == '\n') {
|
||||||
|
char* line = malloc(input - last + 1);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memcpy(line, last, input - last);
|
||||||
|
|
||||||
|
line[input - last] = 0;
|
||||||
|
|
||||||
|
for(i = 0; line[i] != 0; i++) {
|
||||||
|
if(line[i] == '\r' || line[i] == '\n') {
|
||||||
|
line[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TTF
|
||||||
|
if(MwFLTextWidth && !MwGetInteger(handle, MwNbitmapFont) && ttf != NULL && (st = MwFLTextWidth(ttf, line)) != -1) {
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
st = MwUTF8Length(line) * FontWidth;
|
||||||
|
|
||||||
|
if(st > len) len = st;
|
||||||
|
|
||||||
|
free(line);
|
||||||
|
|
||||||
|
last = input + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MwTextHeight(MwWidget handle, MwFLFont ttf, const char* text) {
|
int MwTextHeight(MwWidget handle, MwFLFont ttf, const char* text) {
|
||||||
|
|
|
||||||
|
|
@ -193,14 +193,13 @@ static void frame_draw(MwWidget handle) {
|
||||||
char* str;
|
char* str;
|
||||||
int l = (j == 0 ? MwGetInteger(handle->parent, MwNleftPadding) : 0);
|
int l = (j == 0 ? MwGetInteger(handle->parent, MwNleftPadding) : 0);
|
||||||
MwPoint p2 = p;
|
MwPoint p2 = p;
|
||||||
|
|
||||||
p2.y += (MwTextHeight(handle, Font, "M") + Padding) / 2;
|
p2.y += (MwTextHeight(handle, Font, "M") + Padding) / 2;
|
||||||
|
|
||||||
if(t == NULL) t = "";
|
if(t == NULL) t = "";
|
||||||
|
|
||||||
str = MwStringDuplicate(t);
|
str = MwStringDuplicate(t);
|
||||||
if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M")) {
|
if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M")) {
|
||||||
int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M");
|
int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M") - 3;
|
||||||
int seek = 0;
|
int seek = 0;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
|
|
||||||
|
|
@ -219,18 +218,21 @@ static void frame_draw(MwWidget handle) {
|
||||||
if(j == (arrlen(lb->list[i].name) - 1)) p.x -= MwDefaultBorderWidth(handle);
|
if(j == (arrlen(lb->list[i].name) - 1)) p.x -= MwDefaultBorderWidth(handle);
|
||||||
if(arrlen(lb->alignment) <= j || lb->alignment[j] == MwALIGNMENT_BEGINNING) {
|
if(arrlen(lb->alignment) <= j || lb->alignment[j] == MwALIGNMENT_BEGINNING) {
|
||||||
p.x += 4;
|
p.x += 4;
|
||||||
|
p2.x = p.x;
|
||||||
MwDrawText(handle, Font, &p2, str, MwALIGNMENT_BEGINNING, selected ? base2 : text2);
|
MwDrawText(handle, Font, &p2, str, MwALIGNMENT_BEGINNING, selected ? base2 : text2);
|
||||||
p.x -= 4;
|
p.x -= 4;
|
||||||
p.x += get_col_width(lb, j);
|
p.x += get_col_width(lb, j);
|
||||||
|
|
||||||
} else if(lb->alignment[j] == MwALIGNMENT_CENTER) {
|
} else if(lb->alignment[j] == MwALIGNMENT_CENTER) {
|
||||||
p.x += (get_col_width(lb, j) - l) / 2;
|
p.x += (get_col_width(lb, j) - l) / 2;
|
||||||
|
p2.x = p.x;
|
||||||
MwDrawText(handle, Font, &p2, str, MwALIGNMENT_CENTER, selected ? base2 : text2);
|
MwDrawText(handle, Font, &p2, str, MwALIGNMENT_CENTER, selected ? base2 : text2);
|
||||||
p.x += (get_col_width(lb, j) - l) / 2;
|
p.x += (get_col_width(lb, j) - l) / 2;
|
||||||
p.x += l;
|
p.x += l;
|
||||||
} else if(lb->alignment[j] == MwALIGNMENT_END) {
|
} else if(lb->alignment[j] == MwALIGNMENT_END) {
|
||||||
p.x += get_col_width(lb, j);
|
p.x += get_col_width(lb, j);
|
||||||
p.x -= 4;
|
p.x -= 4;
|
||||||
|
p2.x = p.x;
|
||||||
MwDrawText(handle, Font, &p2, str, MwALIGNMENT_END, selected ? base2 : text2);
|
MwDrawText(handle, Font, &p2, str, MwALIGNMENT_END, selected ? base2 : text2);
|
||||||
p.x += 4;
|
p.x += 4;
|
||||||
}
|
}
|
||||||
|
|
@ -410,8 +412,8 @@ static void redrawIfNeeded(MwWidget handle, int row) {
|
||||||
static int mwListBoxSetImpl(MwWidget handle, int row, int col, const char* text) {
|
static int mwListBoxSetImpl(MwWidget handle, int row, int col, const char* text) {
|
||||||
MwListBox lb = handle->internal;
|
MwListBox lb = handle->internal;
|
||||||
MwListBoxEntry entry;
|
MwListBoxEntry entry;
|
||||||
char* t = text == NULL ? NULL : MwStringDuplicate(text);
|
char* t = text == NULL ? NULL : MwStringDuplicate(text);
|
||||||
int new = 0;
|
int new = 0;
|
||||||
if(row == -1) row = arrlen(lb->list);
|
if(row == -1) row = arrlen(lb->list);
|
||||||
|
|
||||||
entry.name = NULL;
|
entry.name = NULL;
|
||||||
|
|
@ -439,7 +441,7 @@ static int mwListBoxSetImpl(MwWidget handle, int row, int col, const char* text)
|
||||||
static void mwListBoxSetIconImpl(MwWidget handle, int index, MwLLPixmap icon) {
|
static void mwListBoxSetIconImpl(MwWidget handle, int index, MwLLPixmap icon) {
|
||||||
MwListBox lb = handle->internal;
|
MwListBox lb = handle->internal;
|
||||||
MwListBoxEntry entry;
|
MwListBoxEntry entry;
|
||||||
int new = 0;
|
int new = 0;
|
||||||
if(index == -1) index = arrlen(lb->list);
|
if(index == -1) index = arrlen(lb->list);
|
||||||
|
|
||||||
entry.name = NULL;
|
entry.name = NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue